mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-04-01 00:07:02 +00:00
uniformizing vertex attribute arrays
This commit is contained in:
parent
64adb6f0ea
commit
120797d7ce
@ -501,12 +501,9 @@ bool gl_print(int x, int y, int shift, int size, const char *s, int color, int a
|
||||
|
||||
glfont_t& f(*glfont[gsiz]);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glhr::be_textured();
|
||||
|
||||
glcolor2((color << 8) | 0xFF);
|
||||
glhr::color2((color << 8) | 0xFF);
|
||||
|
||||
int tsize = 0;
|
||||
|
||||
@ -537,13 +534,11 @@ bool gl_print(int x, int y, int shift, int size, const char *s, int color, int a
|
||||
|
||||
tver[1] = tver[10] = -hi;
|
||||
tver[6] = tver[9] = wi;
|
||||
tver[12+4] = tver[12+7] = fy;
|
||||
tver[12+6] = tver[12+9] = fx;
|
||||
activateVertexArray(tver, 8);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(3, GL_FLOAT, 0, &tver[12]);
|
||||
tver[12+3] = tver[12+5] = fy;
|
||||
tver[12+4] = tver[12+6] = fx;
|
||||
glhr::vertices(tver, 4);
|
||||
glhr::texture_vertices(tver+12, 4);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
if(stereo::active() && shift) stereo::set_mask(0);
|
||||
@ -553,8 +548,6 @@ bool gl_print(int x, int y, int shift, int size, const char *s, int color, int a
|
||||
x += wi;
|
||||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
return clicked;
|
||||
}
|
||||
#endif
|
||||
@ -900,7 +893,7 @@ void drawCircle(int x, int y, int size, int color) {
|
||||
glhr::be_nontextured();
|
||||
glhr::set_modelview(glhr::id());
|
||||
qglcoords = 0;
|
||||
glcolor2(color);
|
||||
glhr::color2(color);
|
||||
x -= vid.xcenter; y -= vid.ycenter;
|
||||
int pts = size * 4;
|
||||
if(pts > 1500) pts = 1500;
|
||||
|
@ -2268,7 +2268,7 @@ void drawaura() {
|
||||
#endif
|
||||
|
||||
#if CAP_GL
|
||||
glhr::be_nontextured();
|
||||
glhr::switch_mode(glhr::gmVarColored);
|
||||
glhr::set_modelview(glhr::id());
|
||||
setcameraangle(true);
|
||||
|
||||
|
1
hyper.h
1
hyper.h
@ -2389,7 +2389,6 @@ extern purehookset hooks_drawmap;
|
||||
extern hookset<bool(eLand&)> *hooks_music;
|
||||
extern hookset<bool()> *hooks_prestats;
|
||||
extern purehookset hooks_fixticks;
|
||||
void activateVertexArray(GLfloat *f, int qty);
|
||||
|
||||
ld realradius();
|
||||
|
||||
|
51
polygons.cpp
51
polygons.cpp
@ -111,10 +111,6 @@ vector<polytodraw*> ptds2;
|
||||
GLfloat glcoords[POLYMAX][3];
|
||||
int qglcoords;
|
||||
|
||||
#if CAP_GL
|
||||
GLfloat *currentvertices;
|
||||
#endif
|
||||
|
||||
GLfloat *ourshape = NULL;
|
||||
|
||||
void initPolyForGL() {
|
||||
@ -132,7 +128,7 @@ void initPolyForGL() {
|
||||
}
|
||||
|
||||
#if CAP_GL
|
||||
currentvertices = NULL;
|
||||
glhr::currentvertices = NULL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -141,25 +137,16 @@ void initPolyForGL() {
|
||||
|
||||
GLuint shapebuffer;
|
||||
|
||||
extern void glcolor(int color);
|
||||
|
||||
|
||||
void activateVertexArray(GLfloat *f, int qty) {
|
||||
currentvertices = f;
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(3, GL_FLOAT, 0, f);
|
||||
}
|
||||
|
||||
extern GLfloat *ourshape;
|
||||
|
||||
void activateShapes() {
|
||||
if(currentvertices != ourshape) {
|
||||
activateVertexArray(ourshape, qhpc);
|
||||
if(glhr::currentvertices != ourshape) {
|
||||
glhr::vertices(ourshape, qhpc);
|
||||
}
|
||||
}
|
||||
|
||||
void activateGlcoords() {
|
||||
activateVertexArray(glcoords[0], qglcoords);
|
||||
glhr::vertices(glcoords[0], qglcoords);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -283,11 +270,6 @@ void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, GLfloat *tv, int col
|
||||
#endif
|
||||
|
||||
#if CAP_GL
|
||||
void glcolor2(int color) {
|
||||
unsigned char *c = (unsigned char*) (&color);
|
||||
glColor4f(c[3] / 255.0, c[2] / 255.0, c[1]/255.0, c[0] / 255.0);
|
||||
}
|
||||
|
||||
void glapplymatrix(const transmatrix& V) {
|
||||
GLfloat mat[16];
|
||||
int id = 0;
|
||||
@ -322,11 +304,9 @@ int tinfshift;
|
||||
void gldraw(int useV, const transmatrix& V, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) {
|
||||
|
||||
if(tinf) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glhr::be_textured();
|
||||
glBindTexture(GL_TEXTURE_2D, tinf->texture_id);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(3, GL_FLOAT, 0, &tinf->tvertices[tinfshift]);
|
||||
glhr::texture_vertices(&tinf->tvertices[tinfshift], 0, 3);
|
||||
}
|
||||
else glhr::be_nontextured();
|
||||
|
||||
@ -352,7 +332,7 @@ void gldraw(int useV, const transmatrix& V, int ps, int pq, int col, int outline
|
||||
|
||||
if(flags & POLY_INVERSE) {
|
||||
stereo::set_mask(ed);
|
||||
glcolor2(col);
|
||||
glhr::color2(col);
|
||||
glStencilOp( GL_ZERO, GL_ZERO, GL_ZERO);
|
||||
glStencilFunc( GL_NOTEQUAL, 1, 1);
|
||||
GLfloat xx = vid.xres;
|
||||
@ -361,16 +341,16 @@ void gldraw(int useV, const transmatrix& V, int ps, int pq, int col, int outline
|
||||
-xx, -yy, stereo::scrdist, +xx, -yy, stereo::scrdist,
|
||||
+xx, +yy, stereo::scrdist, -xx, +yy, stereo::scrdist
|
||||
};
|
||||
GLfloat *cur = currentvertices;
|
||||
activateVertexArray(scr, 4);
|
||||
GLfloat *cur = glhr::currentvertices;
|
||||
glhr::vertices(scr, 4);
|
||||
glhr::set_modelview(glhr::id());
|
||||
glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, 0, 4);
|
||||
activateVertexArray(cur, 0);
|
||||
glhr::vertices(cur, 0);
|
||||
draw = false; goto again;
|
||||
}
|
||||
else {
|
||||
stereo::set_mask(ed);
|
||||
glcolor2(col);
|
||||
glhr::color2(col);
|
||||
glStencilOp( GL_ZERO, GL_ZERO, GL_ZERO);
|
||||
glStencilFunc( GL_EQUAL, 1, 1);
|
||||
glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, ps, pq);
|
||||
@ -380,17 +360,12 @@ void gldraw(int useV, const transmatrix& V, int ps, int pq, int col, int outline
|
||||
}
|
||||
|
||||
if(outline) {
|
||||
glcolor2(outline);
|
||||
glhr::color2(outline);
|
||||
glDrawArrays(GL_LINE_STRIP, ps, pq);
|
||||
}
|
||||
}
|
||||
|
||||
if(stereo::active()) stereo::set_projection(0), stereo::set_viewport(0), stereo::set_mask(0);
|
||||
|
||||
if(tinf) {
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -531,8 +506,8 @@ void drawpolyline(polytodraw& p) {
|
||||
#if CAP_GL
|
||||
if(vid.usingGL && pmodel == mdDisk && !spherespecial) {
|
||||
const int pq = pp.cnt;
|
||||
if(currentvertices != pp.tab)
|
||||
activateVertexArray(pp.tab, pq);
|
||||
if(glhr::currentvertices != pp.tab)
|
||||
glhr::vertices(pp.tab, pq);
|
||||
const int ps=0;
|
||||
glLineWidth(linewidthat(tC0(pp.V), pp.minwidth));
|
||||
gldraw(1, pp.V, ps, pq, p.col, pp.outline, 0, pp.tinf);
|
||||
|
60
rug.cpp
60
rug.cpp
@ -1108,36 +1108,13 @@ void prepareTexture() {
|
||||
|
||||
double xview, yview;
|
||||
|
||||
void glcolorClear(int color) {
|
||||
unsigned char *c = (unsigned char*) (&color);
|
||||
glClearColor(c[3] / 255.0, c[2] / 255.0, c[1]/255.0, c[0] / 255.0);
|
||||
}
|
||||
|
||||
void drawRugScene() {
|
||||
GLfloat light_ambient[] = { 3.5, 3.5, 3.5, 1.0 };
|
||||
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
|
||||
#ifndef GLES_ONLY
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||
#else
|
||||
glLightModelx(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||
#endif
|
||||
GLERR("lighting");
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
void drawRugScene() {
|
||||
glbuf->use_as_texture();
|
||||
|
||||
if(backcolor == 0)
|
||||
glClearColor(0.05,0.05,0.05,1);
|
||||
else
|
||||
glcolorClear(backcolor << 8 | 0xFF);
|
||||
glhr::colorClear(backcolor << 8 | 0xFF);
|
||||
#ifdef GLES_ONLY
|
||||
glClearDepthf(1.0f);
|
||||
#else
|
||||
@ -1146,8 +1123,7 @@ void drawRugScene() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glhr::be_textured();
|
||||
glhr::switch_mode(glhr::gmVarColored);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
@ -1209,39 +1185,27 @@ void drawRugScene() {
|
||||
glhr::projection_multiply(glhr::as_glmatrix(ortho));
|
||||
}
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
|
||||
fog_max(
|
||||
gwhere == gSphere ? 10 :
|
||||
gwhere == gElliptic ? 4 :
|
||||
100
|
||||
);
|
||||
|
||||
if(rug_perspective && gwhere >= gSphere) {
|
||||
glEnable(GL_FOG);
|
||||
#ifndef GLES_ONLY
|
||||
glFogi(GL_FOG_MODE, GL_LINEAR);
|
||||
#else
|
||||
glFogx(GL_FOG_MODE, GL_LINEAR);
|
||||
#endif
|
||||
glFogf(GL_FOG_START, 0);
|
||||
glFogf(GL_FOG_END, gwhere == gSphere ? 10 : 4);
|
||||
}
|
||||
|
||||
glhr::set_modelview(glhr::id());
|
||||
|
||||
for(int t=0; t<size(triangles); t++)
|
||||
drawTriangle(triangles[t]);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(3, GL_FLOAT, 0, &vertex_array[0]);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, &tvertex_array[0]);
|
||||
|
||||
|
||||
glhr::vertices(&vertex_array[0], 0);
|
||||
glhr::texture_vertices(&tvertex_array[0], 0);
|
||||
glDrawArrays(GL_TRIANGLES, 0, size(vertex_array)/3);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
stereo::set_mask(0);
|
||||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_FOG);
|
||||
|
||||
stereo::set_mask(0), stereo::set_viewport(0);
|
||||
stereo::set_projection(0);
|
||||
|
110
shaders.cpp
110
shaders.cpp
@ -9,7 +9,17 @@
|
||||
|
||||
namespace glhr {
|
||||
|
||||
enum mode { gmColored, gmTextured, gmMAX};
|
||||
enum eMode { gmColored, gmTextured, gmVarColored, gmLightFog, gmMAX};
|
||||
|
||||
static const flagtype GF_TEXTURE = 1;
|
||||
static const flagtype GF_VARCOLOR = 2;
|
||||
static const flagtype GF_LIGHTFOG = 4;
|
||||
|
||||
flagtype flags[gmMAX] = { 0, GF_TEXTURE, GF_VARCOLOR, GF_TEXTURE | GF_LIGHTFOG };
|
||||
|
||||
eMode mode;
|
||||
|
||||
void switch_mode(eMode m);
|
||||
|
||||
struct glmatrix {
|
||||
GLfloat a[4][4];
|
||||
@ -84,9 +94,9 @@ void set_modelview(const glmatrix& m) {
|
||||
glLoadMatrixf(m.as_array());
|
||||
}
|
||||
|
||||
void be_nontextured() { }
|
||||
void be_textured() { }
|
||||
void init() { }
|
||||
void init() {
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -210,7 +220,7 @@ struct GLprogram {
|
||||
|
||||
};
|
||||
|
||||
GLprogram *textured, *nontextured;
|
||||
GLprogram *programs[gmMAX];
|
||||
|
||||
void init() {
|
||||
projection = id();
|
||||
@ -219,7 +229,7 @@ void init() {
|
||||
auto texture_only = [=] (string s) -> string { if(i) return s; else return ""; };
|
||||
auto not_texture_only = [=] (string s) -> string { if(!i) return s; else return ""; };
|
||||
|
||||
(i==1?textured:nontextured) = new GLprogram(
|
||||
programs[i] = new GLprogram(
|
||||
// "attribute vec4 position;"
|
||||
// "attribute vec3 normal;"
|
||||
|
||||
@ -252,8 +262,13 @@ void init() {
|
||||
" }"
|
||||
);
|
||||
}
|
||||
|
||||
programs[2] = programs[0];
|
||||
programs[3] = programs[1];
|
||||
|
||||
nontextured->enable();
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
switch_mode(gmColored);
|
||||
programs[gmColored]->enable();
|
||||
}
|
||||
|
||||
void set_modelview(const glmatrix& modelview) {
|
||||
@ -263,8 +278,83 @@ void set_modelview(const glmatrix& modelview) {
|
||||
// glUniformMatrix3fv(current->uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, nm[0]);
|
||||
}
|
||||
|
||||
void be_nontextured() { nontextured->enable(); }
|
||||
void be_textured() { textured->enable(); }
|
||||
|
||||
#endif
|
||||
|
||||
GLfloat *currentvertices;
|
||||
|
||||
void vertices(GLfloat *f, int qty) {
|
||||
currentvertices = f;
|
||||
glVertexPointer(3, GL_FLOAT, 0, f);
|
||||
}
|
||||
|
||||
void texture_vertices(GLfloat *f, int qty, int stride = 2) {
|
||||
glTexCoordPointer(stride, GL_FLOAT, 0, f);
|
||||
}
|
||||
|
||||
void color_vertices(GLfloat *f, int qty) {
|
||||
glColorPointer(4, GL_FLOAT, 0, f);
|
||||
}
|
||||
|
||||
void color2(int color) {
|
||||
unsigned char *c = (unsigned char*) (&color);
|
||||
glColor4f(c[3] / 255.0, c[2] / 255.0, c[1]/255.0, c[0] / 255.0);
|
||||
}
|
||||
|
||||
void colorClear(int color) {
|
||||
unsigned char *c = (unsigned char*) (&color);
|
||||
glClearColor(c[3] / 255.0, c[2] / 255.0, c[1]/255.0, c[0] / 255.0);
|
||||
}
|
||||
|
||||
void be_nontextured() { switch_mode(gmColored); }
|
||||
void be_textured() { switch_mode(gmTextured); }
|
||||
|
||||
void switch_mode(eMode m) {
|
||||
if(m == mode) return;
|
||||
#if CAP_SHADER
|
||||
programs[m]->enable();
|
||||
#endif
|
||||
flagtype newflags = flags[m] &~ flags[mode];
|
||||
flagtype oldflags = flags[mode] &~ flags[m];
|
||||
if(newflags & GF_TEXTURE) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
if(oldflags & GF_TEXTURE) {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
if(newflags & GF_VARCOLOR)
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
if(oldflags & GF_VARCOLOR)
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
if(newflags & GF_LIGHTFOG) {
|
||||
GLfloat light_ambient[] = { 3.5, 3.5, 3.5, 1.0 };
|
||||
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||
GLERR("lighting");
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glEnable(GL_FOG);
|
||||
glFogi(GL_FOG_MODE, GL_LINEAR);
|
||||
glFogf(GL_FOG_START, 0);
|
||||
}
|
||||
if(oldflags & GF_LIGHTFOG) {
|
||||
glDisable(GL_FOG);
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
mode = m;
|
||||
}
|
||||
|
||||
void fog_max(ld fogmax) {
|
||||
glFogf(GL_FOG_END, fogmax);
|
||||
}
|
||||
|
||||
}
|
||||
|
10
textures.cpp
10
textures.cpp
@ -465,9 +465,8 @@ void saveFullTexture() {
|
||||
bool newmove = false;
|
||||
|
||||
void drawRawTexture() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glhr::be_textured();
|
||||
glcolor2(0xFFFFFF20);
|
||||
glhr::color2(0xFFFFFF20);
|
||||
glhr::set_modelview(glhr::translate(0, 0, stereo::scrdist));
|
||||
glBindTexture(GL_TEXTURE_2D, textureid);
|
||||
vector<GLfloat> tver, sver;
|
||||
@ -485,12 +484,9 @@ void drawRawTexture() {
|
||||
sver.push_back(y * vid.scrsize);
|
||||
sver.push_back(0);
|
||||
}
|
||||
activateVertexArray(&sver[0], 4);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(3, GL_FLOAT, 0, &tver[0]);
|
||||
glhr::vertices(&sver[0], 4);
|
||||
glhr::texture_vertices(&tver[0], 4, 3);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
struct magicmapper_point {
|
||||
|
Loading…
x
Reference in New Issue
Block a user