mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-27 14:37:16 +00:00
more changes to make it work on iOS
This commit is contained in:
parent
90d477d3dc
commit
d01d772669
@ -255,20 +255,28 @@ void stereo::set_viewport(int ed) {
|
||||
|
||||
void setGLProjection(int col) {
|
||||
DEBB(DF_GRAPH, (debugfile,"setGLProjection\n"));
|
||||
GLERR("pre_setGLProjection");
|
||||
|
||||
unsigned char *c = (unsigned char*) (&col);
|
||||
glClearColor(c[2] / 255.0, c[1] / 255.0, c[0]/255.0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
GLERR("setGLProjection #1");
|
||||
|
||||
#ifndef GLES_ONLY
|
||||
glEnable(GL_BLEND);
|
||||
if(vid.antialias & AA_LINES) {
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||
}
|
||||
else glDisable(GL_LINE_SMOOTH);
|
||||
#endif
|
||||
|
||||
glLineWidth(vid.linewidth);
|
||||
|
||||
#if !ISMOBILE
|
||||
GLERR("setGLProjection #2");
|
||||
|
||||
#ifndef GLES_ONLY
|
||||
if(vid.antialias & AA_POLY) {
|
||||
glEnable(GL_POLYGON_SMOOTH);
|
||||
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
|
||||
@ -276,6 +284,8 @@ void setGLProjection(int col) {
|
||||
else glDisable(GL_POLYGON_SMOOTH);
|
||||
#endif
|
||||
|
||||
GLERR("setGLProjection #3");
|
||||
|
||||
//glLineWidth(1.0f);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
@ -291,7 +301,10 @@ void setGLProjection(int col) {
|
||||
else
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
GLERR("setGLProjection");
|
||||
|
||||
stereo::set_projection(0);
|
||||
GLERR("after set_projection");
|
||||
}
|
||||
|
||||
inline int next_p2 (int a )
|
||||
@ -945,6 +958,8 @@ hookset<void(renderbuffer*)> *hooks_hqshot;
|
||||
#if CAP_SDL
|
||||
void saveHighQualityShot(const char *fname, const char *caption, int fade) {
|
||||
|
||||
resetbuffer rb;
|
||||
|
||||
int maxrange = getDistLimit() * 3/2;
|
||||
|
||||
dynamicval<int> v3(sightrange, (cheater && sightrange < maxrange) ? maxrange : sightrange);
|
||||
@ -1014,7 +1029,7 @@ void saveHighQualityShot(const char *fname, const char *caption, int fade) {
|
||||
if(i == 0) addMessage(XLAT("Saved the high quality shot to %1", fname));
|
||||
}
|
||||
|
||||
glbuf.disable();
|
||||
rb.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
9
hyper.h
9
hyper.h
@ -2552,10 +2552,16 @@ struct renderbuffer {
|
||||
renderbuffer(int x, int y, bool gl);
|
||||
~renderbuffer();
|
||||
void enable();
|
||||
void disable();
|
||||
void clear(int col);
|
||||
};
|
||||
|
||||
struct resetbuffer {
|
||||
GLint drawFboId, readFboId;
|
||||
SDL_Surface *sreset;
|
||||
resetbuffer();
|
||||
void reset();
|
||||
};
|
||||
|
||||
namespace stereo {
|
||||
enum eStereo { sOFF, sAnaglyph, sLR, sODS };
|
||||
|
||||
@ -2661,3 +2667,4 @@ extern void popGame();
|
||||
string helptitle(string s, int col);
|
||||
pair<int, int> cell_to_pair(cell *c);
|
||||
extern bool nohud, nofps;
|
||||
|
||||
|
10
init.cpp
10
init.cpp
@ -645,6 +645,8 @@ int getticks();
|
||||
void shareScore(MOBPAR_FORMAL);
|
||||
#endif
|
||||
|
||||
int mobile_xres, mobile_yres;
|
||||
|
||||
void mobile_draw(MOBPAR_FORMAL) {
|
||||
|
||||
optimizeview();
|
||||
@ -697,7 +699,13 @@ void mobile_draw(MOBPAR_FORMAL) {
|
||||
lmouseover = mousedest.d >= 0 ? cwt.c->mov[(cwt.spin + mousedest.d) % cwt.c->type] : cwt.c;
|
||||
}
|
||||
}
|
||||
mouseh = gethyper(mousex, mousey);
|
||||
|
||||
#if CAP_RUG
|
||||
if(rug::rugged)
|
||||
mouseh = rug::gethyper(mousex, mousey);
|
||||
else
|
||||
#endif
|
||||
mouseh = gethyper(mousex, mousey);
|
||||
|
||||
// if(debfile) fprintf(debfile, "d1\n"), fflush(debfile);
|
||||
frames++;
|
||||
|
@ -43,38 +43,52 @@ renderbuffer::renderbuffer(int x, int y, bool gl) : x(x), y(y) {
|
||||
|
||||
# if CAP_GL
|
||||
if(gl) {
|
||||
resetbuffer rb;
|
||||
tx = next_p2(x);
|
||||
ty = next_p2(y);
|
||||
|
||||
FramebufferName = renderedTexture = depth_stencil_rb = 0;
|
||||
GLERR("even before");
|
||||
glGenFramebuffers(1, &FramebufferName); //
|
||||
GLERR("GenFramebuffer");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
||||
GLERR("BindFramebuffer");
|
||||
|
||||
glGenTextures(1, &renderedTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, renderedTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, tx, ty, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
GLERR("GenTextures");
|
||||
|
||||
#ifdef TEX
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);
|
||||
#else
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderedTexture, 0);
|
||||
#endif
|
||||
GLERR("FramebufferTexture");
|
||||
// GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
|
||||
// glDrawBuffers(1, DrawBuffers);
|
||||
|
||||
glGenRenderbuffers(1, &depth_stencil_rb);
|
||||
GLERR("GenRenderbuffer");
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_rb);
|
||||
GLERR("BindRenderbuffer");
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, tx, ty);
|
||||
GLERR("RbS");
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb);
|
||||
GLERR("FrRb");
|
||||
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
FramebufferName = renderedTexture = 0;
|
||||
else
|
||||
valid = true;
|
||||
|
||||
printf("Framebuffer remains = %d (%d)\n", FramebufferName, valid);
|
||||
GLERR("initialization");
|
||||
|
||||
rb.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -94,6 +108,7 @@ SDL_Surface *renderbuffer::render() {
|
||||
make_surface() ;
|
||||
if(FramebufferName) {
|
||||
glReadPixels(0, 0, vid.xres, vid.yres, GL_BGRA, GL_UNSIGNED_BYTE, srf->pixels);
|
||||
GLERR("readPixels");
|
||||
for(int y=0; y<vid.yres/2; y++)
|
||||
for(int x=0; x<vid.xres; x++)
|
||||
swap(qpixel(srf,x,y), qpixel(srf,x,vid.yres-1-y));
|
||||
@ -105,8 +120,9 @@ SDL_Surface *renderbuffer::render() {
|
||||
void renderbuffer::enable() {
|
||||
#if CAP_GL
|
||||
if(FramebufferName) {
|
||||
GLERR("prebind");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
||||
glViewport(0,0,x,y);
|
||||
GLERR("bind");
|
||||
vid.usingGL = true;
|
||||
return;
|
||||
}
|
||||
@ -118,21 +134,6 @@ void renderbuffer::enable() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void renderbuffer::disable() {
|
||||
#if CAP_GL
|
||||
if(FramebufferName) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#if CAP_SDL
|
||||
glViewport(0,0,s_screen->w,s_screen->h);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if CAP_SDL
|
||||
s = s_screen;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CAP_GL
|
||||
void renderbuffer::use_as_texture() {
|
||||
if(!renderedTexture) {
|
||||
@ -185,3 +186,24 @@ void renderbuffer::clear(int col) {
|
||||
SDL_FillRect(srf, NULL, col);
|
||||
#endif
|
||||
}
|
||||
|
||||
resetbuffer::resetbuffer() {
|
||||
#if CAP_GL
|
||||
drawFboId = 0, readFboId = 0;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFboId);
|
||||
#endif
|
||||
#if CAP_SDL
|
||||
sreset = s;
|
||||
#endif
|
||||
}
|
||||
|
||||
void resetbuffer::reset() {
|
||||
#if CAP_GL
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, drawFboId);
|
||||
#endif
|
||||
#if CAP_SDL
|
||||
s = sreset;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
13
rug.cpp
13
rug.cpp
@ -1090,13 +1090,17 @@ void drawTriangle(triangle& t) {
|
||||
renderbuffer *glbuf;
|
||||
|
||||
void prepareTexture() {
|
||||
resetbuffer rb;
|
||||
|
||||
videopar svid = vid;
|
||||
|
||||
setVidParam();
|
||||
dynamicval<stereo::eStereo> d(stereo::mode, stereo::sOFF);
|
||||
|
||||
glbuf->enable();
|
||||
|
||||
stereo::set_viewport(0);
|
||||
stereo::set_projection(0);
|
||||
stereo::set_mask(0);
|
||||
glbuf->clear(0);
|
||||
|
||||
ptds.clear();
|
||||
@ -1113,7 +1117,7 @@ void prepareTexture() {
|
||||
}
|
||||
drawqueue();
|
||||
vid = svid;
|
||||
glbuf->disable();
|
||||
rb.reset();
|
||||
}
|
||||
|
||||
double xview, yview;
|
||||
@ -1219,6 +1223,7 @@ transmatrix currentrot;
|
||||
void init() {
|
||||
if(rugged) return;
|
||||
when_enabled = ticks;
|
||||
GLERR("before init");
|
||||
glbuf = new renderbuffer(TEXTURESIZE, TEXTURESIZE, vid.usingGL && !rendernogl);
|
||||
if(!glbuf->valid) {
|
||||
addMessage(XLAT("Failed to enable"));
|
||||
@ -1341,7 +1346,9 @@ transmatrix last_orientation;
|
||||
|
||||
void actDraw() {
|
||||
try {
|
||||
|
||||
if(!renderonce) prepareTexture();
|
||||
stereo::set_viewport(0);
|
||||
physics();
|
||||
drawRugScene();
|
||||
|
||||
@ -1512,7 +1519,7 @@ hyperpoint gethyper(ld x, ld y) {
|
||||
}
|
||||
|
||||
void show() {
|
||||
cmode = sm::SIDE | sm::MAYDARK;
|
||||
cmode = sm::SIDE;
|
||||
gamescreen(0);
|
||||
dialog::init(XLAT("hypersian rug mode"), iinf[itPalace].color, 150, 100);
|
||||
|
||||
|
51
shaders.cpp
51
shaders.cpp
@ -2,7 +2,7 @@
|
||||
// If CAP_SHADER is 0, OpenGL 1.0 is used.
|
||||
// If CAP_SHADER is 1, GLSL is used.
|
||||
|
||||
#define DEBUG_GL 0
|
||||
#define DEBUG_GL 1
|
||||
|
||||
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
|
||||
|
||||
@ -202,6 +202,14 @@ struct GLprogram {
|
||||
|
||||
GLprogram(string vsh, string fsh) {
|
||||
_program = glCreateProgram();
|
||||
|
||||
#ifndef GLES_ONLY
|
||||
while(vsh.find("mediump ") != string::npos)
|
||||
vsh.replace(vsh.find("mediump "), 7, "");
|
||||
while(fsh.find("mediump ") != string::npos)
|
||||
fsh.replace(fsh.find("mediump "), 7, "");
|
||||
#endif
|
||||
|
||||
// printf("creating program %d\n", _program);
|
||||
vertShader = compileShader(GL_VERTEX_SHADER, vsh.c_str());
|
||||
fragShader = compileShader(GL_FRAGMENT_SHADER, fsh.c_str());
|
||||
@ -336,39 +344,52 @@ void be_textured() { switch_mode(gmTextured); }
|
||||
|
||||
void switch_mode(eMode m) {
|
||||
if(m == mode) return;
|
||||
GLERR("pre_switch_mode");
|
||||
#if CAP_SHADER
|
||||
programs[m]->enable();
|
||||
GLERR("after_enable");
|
||||
#endif
|
||||
flagtype newflags = flags[m] &~ flags[mode];
|
||||
flagtype oldflags = flags[mode] &~ flags[m];
|
||||
if(newflags & GF_TEXTURE) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
GLERR("xsm");
|
||||
#if CAP_SHADER
|
||||
glEnableVertexAttribArray(aTexture);
|
||||
GLERR("xsm");
|
||||
#else
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
GLERR("xsm");
|
||||
#endif
|
||||
}
|
||||
if(oldflags & GF_TEXTURE) {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
GLERR("xsm");
|
||||
#if CAP_SHADER
|
||||
glDisableVertexAttribArray(aTexture);
|
||||
GLERR("xsm");
|
||||
#else
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
GLERR("xsm");
|
||||
#endif
|
||||
}
|
||||
if(newflags & GF_VARCOLOR) {
|
||||
#if CAP_SHADER
|
||||
GLERR("xsm");
|
||||
glEnableVertexAttribArray(aColor);
|
||||
#else
|
||||
GLERR("xsm");
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
GLERR("xsm");
|
||||
#endif
|
||||
}
|
||||
if(oldflags & GF_VARCOLOR) {
|
||||
#if CAP_SHADER
|
||||
glDisableVertexAttribArray(aColor);
|
||||
GLERR("xsm");
|
||||
#else
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
GLERR("xsm");
|
||||
#endif
|
||||
}
|
||||
if(newflags & GF_LIGHTFOG) {
|
||||
@ -399,6 +420,7 @@ void switch_mode(eMode m) {
|
||||
#endif
|
||||
}
|
||||
mode = m;
|
||||
GLERR("after_switch_mode");
|
||||
}
|
||||
|
||||
void fog_max(ld fogmax) {
|
||||
@ -434,17 +456,18 @@ void init() {
|
||||
bool varcol = f & GF_VARCOLOR;
|
||||
|
||||
programs[i] = new GLprogram(stringbuilder(
|
||||
1, "attribute vec4 aPosition;",
|
||||
texture, "attribute vec2 aTexture;",
|
||||
varcol, "attribute vec4 aColor;",
|
||||
|
||||
1, "attribute mediump vec4 aPosition;",
|
||||
texture, "attribute mediump vec2 aTexture;",
|
||||
varcol, "attribute mediump vec4 aColor;",
|
||||
// "attribute vec3 normal;"
|
||||
|
||||
1, "varying vec4 vColor;",
|
||||
texture, "varying vec2 vTexCoord;",
|
||||
1, "varying mediump vec4 vColor;",
|
||||
texture, "varying mediump vec2 vTexCoord;",
|
||||
|
||||
1, "uniform mat4 uMVP;",
|
||||
1, "uniform float uFog;",
|
||||
!varcol, "uniform vec4 uColor;",
|
||||
1, "uniform mediump mat4 uMVP;",
|
||||
1, "uniform mediump float uFog;",
|
||||
!varcol, "uniform mediump vec4 uColor;",
|
||||
|
||||
1, "void main() {",
|
||||
texture, "vTexCoord = aTexture;",
|
||||
@ -456,9 +479,9 @@ void init() {
|
||||
|
||||
stringbuilder(
|
||||
|
||||
1, "uniform sampler2D tTexture;",
|
||||
1, "varying vec4 vColor;",
|
||||
texture, "varying vec2 vTexCoord;",
|
||||
1, "uniform mediump sampler2D tTexture;",
|
||||
1, "varying mediump vec4 vColor;",
|
||||
texture, "varying mediump vec2 vTexCoord;",
|
||||
1, "void main() {",
|
||||
texture, "gl_FragColor = vColor * texture2D(tTexture, vTexCoord);",
|
||||
!texture, "gl_FragColor = vColor;",
|
||||
|
Loading…
Reference in New Issue
Block a user