diff --git a/basegraph.cpp b/basegraph.cpp index dddf1038..26390ae0 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -263,8 +263,8 @@ void setGLProjection(int col) { GLERR("setGLProjection #1"); -#ifndef GLES_ONLY glEnable(GL_BLEND); +#ifndef GLES_ONLY if(vid.antialias & AA_LINES) { glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); @@ -443,8 +443,6 @@ void init_glfont(int size) { GLERR("initfont"); } -GLfloat tver[24]; - int gl_width(int size, const char *s) { int gsiz = size; if(size > vid.fsize || size > 72) gsiz = 72; @@ -467,8 +465,27 @@ int gl_width(int size, const char *s) { return x; } -bool gl_print(int x, int y, int shift, int size, const char *s, int color, int align) { +namespace glhr { void texture_vertices(GLfloat *f, int qty, int stride = 2) { + #if CAP_SHADER + glVertexAttribPointer(aTexture, stride, GL_FLOAT, GL_FALSE, stride * sizeof(GLfloat), f); + #else + glTexCoordPointer(stride, GL_FLOAT, 0, f); + #endif + } + void oldvertices(GLfloat *f, int qty) { + #if CAP_SHADER + glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), f); + #else + glVertexPointer(3, GL_FLOAT, 0, f); + #endif + // #endif + } + } +GLfloat otver[24]; +vector tver(4); + +bool gl_print(int x, int y, int shift, int size, const char *s, int color, int align) { int gsiz = size; if(size > vid.fsize || size > 72) gsiz = 72; @@ -512,12 +529,16 @@ bool gl_print(int x, int y, int shift, int size, const char *s, int color, int a stereo::set_mask(ed); glBindTexture(GL_TEXTURE_2D, f.textures[tabid]); - tver[1] = tver[10] = -hi; - tver[6] = tver[9] = wi; - tver[12+3] = tver[12+5] = fy; - tver[12+4] = tver[12+6] = fx; - glhr::vertices(tver, 4); - glhr::texture_vertices(tver+12, 4); + tver[0].coords[1] = -hi; + tver[3].coords[1] = -hi; + tver[2].coords[0] = wi; + tver[3].coords[0] = wi; + tver[1].texture[1] = fy; + tver[2].texture[1] = fy; + tver[2].texture[0] = fx; + tver[3].texture[0] = fx; + + glhr::prepare(tver); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } @@ -530,6 +551,7 @@ bool gl_print(int x, int y, int shift, int size, const char *s, int color, int a return clicked; } + #endif purehookset hooks_resetGL; @@ -872,7 +894,7 @@ void drawCircle(int x, int y, int size, int color) { if(vid.usingGL) { glhr::be_nontextured(); glhr::set_modelview(glhr::id()); - qglcoords = 0; + glcoords.clear(); glhr::color2(color); x -= vid.xcenter; y -= vid.ycenter; int pts = size * 4; @@ -880,13 +902,9 @@ void drawCircle(int x, int y, int size, int color) { if(ISMOBILE && pts > 72) pts = 72; for(int r=0; r(x + size * sin(rr), y + size * cos(rr), stereo::scrdist)); } - - qglcoords = pts; - activateGlcoords(); + glhr::vertices(glcoords); glDrawArrays(GL_LINE_LOOP, 0, pts); return; } @@ -1057,12 +1075,12 @@ void setvideomode() { if(vid.usingGL) { flags = SDL_OPENGL | SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER; SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); - +#if !ISWEB if(vid.antialias & AA_MULTI) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (vid.antialias & AA_MULTI16) ? 16 : 4); } - +#endif } #endif @@ -1088,10 +1106,12 @@ void setvideomode() { #if CAP_GL if(vid.usingGL) { +#if !ISWEB if(vid.antialias & AA_MULTI) glEnable(GL_MULTISAMPLE); else glDisable(GL_MULTISAMPLE); +#endif glViewport(0, 0, vid.xres, vid.yres); glhr::init(); diff --git a/graph.cpp b/graph.cpp index e6da68e9..fe7f9aa6 100644 --- a/graph.cpp +++ b/graph.cpp @@ -2206,8 +2206,8 @@ void sumaura(int v) { } aurac[AURA][v] = aurac[0][v]; } - -float coltab[4][4]; + +vector auravertices; void drawaura() { if(!haveaura()) return; @@ -2270,13 +2270,8 @@ void drawaura() { #endif #if CAP_GL - glhr::switch_mode(glhr::gmVarColored); - glhr::set_modelview(glhr::id()); setcameraangle(true); - glhr::color_vertices(coltab[0], 4); - activateGlcoords(); - float cx[AURA+1][11][5]; double facs[11] = {1, 1.01, 1.02, 1.04, 1.08, 1.70, 1.95, 1.5, 2, 6, 10}; @@ -2301,22 +2296,21 @@ void drawaura() { cx[r][z][u+2] = bak[u] + (aurac[rm][u] / (aurac[rm][3]+.1) - bak[u]) * cmul[z]; } - for(int u=0; u<4; u++) glcoords[u][2] = stereo::scrdist; - for(int u=0; u<4; u++) coltab[u][3] = 1; - + auravertices.clear(); for(int r=0; r(cx[br][bz][2], 1); - coltab[c][1] = min(cx[br][bz][3], 1); - coltab[c][2] = min(cx[br][bz][4], 1); + for(int c=0; c<6; c++) { + int br = (c == 1 || c == 3 || c == 5) ? r+1 : r; + int bz = (c == 2 || c == 4 || c == 5) ? z+1 : z; + auravertices.emplace_back( + cx[br][bz][0], cx[br][bz][1], cx[br][bz][2], cx[br][bz][3], cx[br][bz][4] + ); } - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } + glhr::switch_mode(glhr::gmVarColored); + glhr::set_modelview(glhr::id()); + glhr::prepare(auravertices); + glDrawArrays(GL_TRIANGLES, 0, size(auravertices)); + setcameraangle(false); #endif @@ -3118,7 +3112,7 @@ void warpfloor(cell *c, const transmatrix& V, int col, int prio, bool warp) { if(shmup::on || nonbitrunc) warp = false; #if CAP_TEXTURE if(qfi.tinf) { - queuetable(V*qfi.spin, &qfi.tinf->vertices[0], size(qfi.tinf->vertices) / 3, 0, texture::recolor(col), prio); + queuetable(V*qfi.spin, qfi.tinf->vertices, size(qfi.tinf->vertices), 0, texture::recolor(col), prio); lastptd().u.poly.tinf = qfi.tinf; } else diff --git a/hyper.h b/hyper.h index e502d366..b9b1fa30 100644 --- a/hyper.h +++ b/hyper.h @@ -2020,12 +2020,16 @@ void drawqueue(); typedef float GLfloat; #endif +typedef array glvec3; +typedef array glvec4; +typedef glvec3 glvertex; + struct textureinfo { transmatrix M; int texture_id; vector> triangles; - vector vertices; - vector tvertices; + vector vertices; + vector tvertices; cell *c; vector matrices; @@ -2035,9 +2039,8 @@ struct textureinfo { struct qpoly { transmatrix V; - GLfloat *tab; - int curveindex; - int cnt; + const vector *tab; + int offset, cnt; int outline; double minwidth; int flags; @@ -2668,3 +2671,6 @@ string helptitle(string s, int col); pair cell_to_pair(cell *c); extern bool nohud, nofps; +template array make_array(T a, T b, T c) { array x; x[0] = a; x[1] = b; x[2] = c; return x; } +template array make_array(T a, T b) { array x; x[0] = a; x[1] = b; return x; } + diff --git a/hyperweb.cpp b/hyperweb.cpp index c67bb39b..b95ebec4 100644 --- a/hyperweb.cpp +++ b/hyperweb.cpp @@ -11,6 +11,7 @@ #define CAP_SDLTTF 0 #define CAP_SHMUP 0 #define CAP_RUG 1 +#define GLES_ONLY #ifdef FAKEWEB void mainloopiter(); @@ -62,7 +63,7 @@ void showDemo() { dialog::addItem(XLAT("play"), 'f'); dialog::addItem(XLAT("tutorial"), 'T'); dialog::addItem(XLAT("help"), 'h'); dialog::lastItem().keycaption += " / F1"; - dialog::addItem(XLAT("toggle high detail"), 'a'); + // dialog::addItem(XLAT("toggle high detail"), 'a'); dialog::addBreak(100); dialog::addTitle("highlights", 0xC00000, 120); @@ -110,7 +111,8 @@ void showDemo() { } void initweb() { - toggleanim(false); - // pushScreen(showDemo); + rug::renderonce = true; + // toggleanim(false); + pushScreen(showDemo); } diff --git a/init.cpp b/init.cpp index 0f8e5941..f3e1f89f 100644 --- a/init.cpp +++ b/init.cpp @@ -315,12 +315,12 @@ typedef unsigned int Uint32; #endif #if ISWEB -inline Uint8 *SDL_GetKeyState(void *v) { static Uint8 tab[1024]; return tab; } +extern "C" { + Uint8 *SDL_GetKeyState(void*); +} +// inline Uint8 *SDL_GetKeyState(void *v) { static Uint8 tab[1024]; return tab; } #endif -/* extern "C" { - Uint8 *SDL_GetKeyState(void*); -} */ #ifndef CAP_GLEW #define CAP_GLEW (CAP_GL && !ISMOBILE && !ISMAC && !ISLINUX && !ISWEB) @@ -645,8 +645,6 @@ int getticks(); void shareScore(MOBPAR_FORMAL); #endif -int mobile_xres, mobile_yres; - void mobile_draw(MOBPAR_FORMAL) { optimizeview(); diff --git a/mapeditor.cpp b/mapeditor.cpp index 53174c29..2f6d3780 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -1128,7 +1128,7 @@ namespace mapeditor { dsCur->rots = 1; for(auto& v: symmetriesAt) - if(p.tab == &ourshape[v[0]*3]) { + if(v[0] == p.offset) { dsCur->rots = v[1]; dsCur->sym = v[2] == 2; } @@ -1136,7 +1136,7 @@ namespace mapeditor { int d = dsCur->rots * (dsCur->sym ? 2 : 1); for(int i=0; i < cnt/d; i++) - dsCur->list.push_back(p.V * hpxyz(p.tab[3*i], p.tab[3*i+1], p.tab[3*i+2])); + dsCur->list.push_back(p.V * glhr::gltopoint((*p.tab)[i+p.offset])); layer++; if(layer == USERLAYERS) break; diff --git a/polygons.cpp b/polygons.cpp index 3b2f3183..691cdb6f 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -108,45 +108,16 @@ SDL_Surface *aux; vector ptds2; #define POLYMAX 60000 -GLfloat glcoords[POLYMAX][3]; -int qglcoords; - -GLfloat *ourshape = NULL; +vector> glcoords, ourshape; void initPolyForGL() { + + ourshape.clear(); - if(ourshape) delete[] ourshape; - ourshape = new GLfloat[3 * qhpc]; + for(int i=0; i(hpc[i][0], hpc[i][1], hpc[i][2])); - // GLfloat ourshape[3*qhpc]; - - int id = 0; - for(int i=0; i(H[0], H[1], H[2])); } int spherespecial, spherephase; void addpoint(const hyperpoint& H) { - if(qglcoords >= POLYMAX) return; - if(true) { hyperpoint Hscr; applymodel(H, Hscr); @@ -201,11 +164,10 @@ void addpoint(const hyperpoint& H) { glcoords[qglcoords][2] += vid.alpha; // glcoords[qglcoords][2] = 1; // EUCSCALE; } */ - qglcoords++; } void coords_to_poly() { - polyi = qglcoords; + polyi = size(glcoords); for(int i=0; i &tab, int ofs, int cnt) { + for(int i=ofs; i& v, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) { if(tinf) { + #if CAP_TEXTURE glhr::be_textured(); glBindTexture(GL_TEXTURE_2D, tinf->texture_id); - glhr::texture_vertices(&tinf->tvertices[tinfshift], 0, 3); + glhr::vertices_texture(v, tinf->tvertices); + #endif + } + else { + glhr::vertices(v); + glhr::be_nontextured(); } - else glhr::be_nontextured(); for(int ed = stereo::active() ? -1 : 0; ed<2; ed+=2) { if(ed) stereo::set_projection(ed), stereo::set_viewport(ed); bool draw = col; - again: - - if(useV == 1) { - glapplymatrix(V); - } - else if(useV == 3) { - GLfloat mat[16] = { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 0, 0, - 0, 0, stereo::scrdist, 1 - }; - glhr::set_modelview(glhr::as_glmatrix(mat)); - } - else - glhr::set_modelview(glhr::id()); + setmatrix(useV, V); if(draw) { glEnable(GL_STENCIL_TEST); @@ -346,16 +311,17 @@ void gldraw(int useV, const transmatrix& V, int ps, int pq, int col, int outline glStencilFunc( GL_NOTEQUAL, 1, 1); GLfloat xx = vid.xres; GLfloat yy = vid.yres; - GLfloat scr[12] = { - -xx, -yy, stereo::scrdist, +xx, -yy, stereo::scrdist, - +xx, +yy, stereo::scrdist, -xx, +yy, stereo::scrdist + vector scr = { + make_array(-xx, -yy, stereo::scrdist), + make_array(+xx, -yy, stereo::scrdist), + make_array(+xx, +yy, stereo::scrdist), + make_array(-xx, +yy, stereo::scrdist) }; - GLfloat *cur = glhr::currentvertices; - glhr::vertices(scr, 4); + glhr::vertices(scr); glhr::set_modelview(glhr::id()); glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, 0, 4); - glhr::vertices(cur, 0); - draw = false; goto again; + glhr::vertices(v); + setmatrix(useV, V); } else { stereo::set_mask(ed); @@ -408,7 +374,7 @@ void fixMercator(bool tinf) { if(mercator_coord) swap(cmin, dmin), swap(cmax, dmax); - for(int i = 0; i hperiod) glcoords[0][mercator_coord] -= period; } @@ -418,7 +384,7 @@ void fixMercator(bool tinf) { ld mincoord = first, maxcoord = first; - for(int i = 0; i next + hperiod) @@ -449,33 +415,27 @@ void fixMercator(bool tinf) { mercator_loop_max--; return; } if(last < first) { - reverse(glcoords, glcoords+qglcoords); + reverse(glcoords.begin(), glcoords.end()); swap(first, last); } while(maxcoord > cmin) { - for(int i=0; i %d\n", base, qglcoords); @@ -495,13 +455,11 @@ void drawpolyline(polytodraw& p) { int i = pp.cnt; pp.cnt = 3; for(int j=0; j poly_limit || abs(glcoords[i][1]) > poly_limit) + if(0) for(auto& p: glcoords) { + if(abs(p[0]) > poly_limit || abs(p[1]) > poly_limit) return; // too large! } if((spherespecial > 0 || (sphere && mdEqui())) && !(poly_flags & POLY_ISSIDE)) { double rarea = 0; - for(int i=0; i(vid.radius * sin(a), vid.radius * cos(a), stereo::scrdist)); } poly_flags ^= POLY_INVERSE; } @@ -600,8 +551,7 @@ void drawpolyline(polytodraw& p) { if(pp.tinf && (poly_flags & POLY_INVERSE)) { return; } - activateGlcoords(); - gldraw(3, Id, 0, qglcoords, p.col, pp.outline, poly_flags, pp.tinf); + gldraw(3, Id, glcoords, 0, size(glcoords), p.col, pp.outline, poly_flags, pp.tinf); continue; } #endif @@ -627,7 +577,7 @@ void drawpolyline(polytodraw& p) { #if CAP_TEXTURE if(!(poly_flags & POLY_INVERSE)) for(int i=0; itvertices[tinfshift + i*3], p.col); + drawTexturedTriangle(s, polyx+i, polyy+i, &pp.tinf->tvertices[pp.offset + i], p.col); #endif } else if(poly_flags & POLY_INVERSE) { @@ -665,10 +615,10 @@ void drawpolyline(polytodraw& p) { } } -vector prettylinepoints; +vector prettylinepoints; void prettypoint(const hyperpoint& h) { - for(int i=0; i<3; i++) prettylinepoints.push_back(h[i]); + prettylinepoints.push_back(glhr::pointtogl(h)); } void prettylinesub(const hyperpoint& h1, const hyperpoint& h2, int lev) { @@ -687,7 +637,8 @@ void prettyline(hyperpoint h1, hyperpoint h2, int col, int lev) { polytodraw p; auto& pp = p.u.poly; pp.V = Id; - pp.tab = &prettylinepoints[0]; + pp.tab = &prettylinepoints; + pp.offset = 0; pp.cnt = size(prettylinepoints)/3; pp.minwidth = minwidth_global; p.col = 0; @@ -705,7 +656,8 @@ void prettypoly(const vector& t, int fillcol, int linecol, int lev) polytodraw p; auto& pp = p.u.poly; pp.V = Id; - pp.tab = &prettylinepoints[0]; + pp.tab = &prettylinepoints; + pp.offset = 0; pp.cnt = size(prettylinepoints)/3; pp.minwidth = minwidth_global; p.col = fillcol; @@ -715,7 +667,7 @@ void prettypoly(const vector& t, int fillcol, int linecol, int lev) drawpolyline(p); } -vector curvedata; +vector curvedata; int curvestart = 0; bool keep_curvedata = false; @@ -738,8 +690,6 @@ void drawqueueitem(polytodraw& ptd) { break; case pkPoly: - if(ptd.u.poly.curveindex >= 0) - ptd.u.poly.tab = &curvedata[ptd.u.poly.curveindex]; drawpolyline(ptd); break; @@ -2300,9 +2250,9 @@ void queuepolyat(const transmatrix& V, const hpcshape& h, int col, int prio) { polytodraw& ptd = nextptd(); ptd.kind = pkPoly; ptd.u.poly.V = V; + ptd.u.poly.offset = h.s; ptd.u.poly.cnt = h.e-h.s; - ptd.u.poly.tab = &ourshape[3*h.s]; - ptd.u.poly.curveindex = -1; + ptd.u.poly.tab = &ourshape; if(cblind) { // protanopia /* int r = (56 * part(col,3) + 43 * part(col,2)) / 100; @@ -2336,13 +2286,13 @@ void queuereset(eModel md, int prio) { ptd.prio = prio << PSHIFT; } -void queuetable(const transmatrix& V, GLfloat *f, int cnt, int linecol, int fillcol, int prio) { +void queuetable(const transmatrix& V, const vector& f, int cnt, int linecol, int fillcol, int prio) { polytodraw& ptd = nextptd(); ptd.kind = pkPoly; ptd.u.poly.V = V; + ptd.u.poly.tab = &f; + ptd.u.poly.offset = 0; ptd.u.poly.cnt = cnt; - ptd.u.poly.tab = f; - ptd.u.poly.curveindex = -1; ptd.col = fillcol; ptd.prio = prio << PSHIFT; ptd.u.poly.outline = linecol; @@ -2419,14 +2369,12 @@ void qfloor(cell *c, const transmatrix& V, const transmatrix& Vspin, const hpcsh } void curvepoint(const hyperpoint& H1) { - curvedata.push_back(H1[0]); - curvedata.push_back(H1[1]); - curvedata.push_back(H1[2]); + curvedata.push_back(glhr::pointtogl(H1)); } void queuecurve(int linecol, int fillcol, int prio) { - queuetable(Id, &curvedata[curvestart], (size(curvedata)-curvestart)/3, linecol, fillcol, prio); - lastptd().u.poly.curveindex = curvestart; + queuetable(Id, curvedata, size(curvedata)-curvestart, linecol, fillcol, prio); + lastptd().u.poly.offset = curvestart; curvestart = size(curvedata); } diff --git a/renderbuffer.cpp b/renderbuffer.cpp index 0ed67add..965d173e 100644 --- a/renderbuffer.cpp +++ b/renderbuffer.cpp @@ -75,8 +75,15 @@ renderbuffer::renderbuffer(int x, int y, bool gl) : x(x), y(y) { glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_rb); GLERR("BindRenderbuffer"); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, tx, ty); + bool has_depth = true; + if(glGetError() != GL_NO_ERROR) { + printf("Could not create: GL_DEPTH24_STENCIL8"); + glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, tx, ty); + has_depth = false; + } GLERR("RbS"); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb); + if(has_depth) + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb); GLERR("FrRb"); diff --git a/rug.cpp b/rug.cpp index fdb0fa06..4e950913 100644 --- a/rug.cpp +++ b/rug.cpp @@ -995,7 +995,7 @@ bool project_ods(hyperpoint azeq, hyperpoint& h1, hyperpoint& h2, bool eye) { } #endif -vector vertex_array, tvertex_array, color_array; +vector ct_array; void drawTriangle(triangle& t) { using namespace hyperpoint_vec; @@ -1070,21 +1070,8 @@ void drawTriangle(triangle& t) { ld col = (2 + hc[0]/hch) / 3; - #if !CAP_SHADER - glNormal3f(hc[0]/hch,hc[1]/hch,hc[2]/hch); - #endif - - for(int i: {0,1,2}) { - tvertex_array.push_back(t.m[i]->x1); - tvertex_array.push_back(t.m[i]->y1); - for(int j: {0,1,2}) - vertex_array.push_back(h[i][j]); - - #if CAP_SHADER - for(int a=0; a<3; a++) color_array.push_back(col); - color_array.push_back(1); - #endif - } + for(int i: {0,1,2}) + ct_array.emplace_back(h[i], t.m[i]->x1, t.m[i]->y1, col); } renderbuffer *glbuf; @@ -1143,9 +1130,7 @@ void drawRugScene() { for(int ed=stereo::active() && stereo::mode != stereo::sODS ? -1 : 0; ed < 2; ed += 2) { use_precompute = false; - vertex_array.clear(); - tvertex_array.clear(); - color_array.clear(); + ct_array.clear(); stereo::set_mask(ed), stereo::set_viewport(ed); if(ed == 1 && stereo::mode == stereo::sAnaglyph) glClear(GL_DEPTH_BUFFER_BIT); @@ -1190,18 +1175,13 @@ void drawRugScene() { gwhere == gElliptic && rug_perspective ? 4 : 100 ); - - glhr::set_modelview(glhr::id()); - + for(int t=0; t void bindbuffer(T& v) { + if(current_vertices == buffered_vertices) { + glBindBuffer(GL_ARRAY_BUFFER, buf_current); + } + current_vertices = &v[0]; + glBufferData(GL_ARRAY_BUFFER, size(v) * sizeof(v[0]), &v[0], GL_DYNAMIC_DRAW); + } + +#define PTR(attrib, q, field) \ + glVertexAttribPointer(attrib, q, GL_FLOAT, GL_FALSE, sizeof(v[0]), (void*) ((char*) &v[0].field - (char*) &v[0])); + +#endif + +void vertices(const vector& v) { + #if CAP_VERTEXBUFFER + if(&v[0] == buffered_vertices) { + if(&v[0] == current_vertices) return; + current_vertices = buffered_vertices; + glBindBuffer(GL_ARRAY_BUFFER, buf_buffered); + glBufferData(GL_ARRAY_BUFFER, size(v) * sizeof(v[0]), &v[0], GL_STATIC_DRAW); + glVertexAttribPointer(glhr::aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), 0); + return; + } + bindbuffer(v); + glVertexAttribPointer(glhr::aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), 0); + #else + if(current_vertices == &v[0]) return; + current_vertices = &v[0]; + #if CAP_SHADER + glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), &v[0]); + #else + glVertexPointer(3, GL_FLOAT, sizeof(glvertex), &v[0]); + #endif + #endif + } + +void vertices_texture(const vector& v, const vector& t) { + #if CAP_TEXTURE + vertices(v); + #if CAP_SHADER + glVertexAttribPointer(aTexture, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), &t[0]); + #else + glTexCoordPointer(stride, GL_FLOAT, 0, &v[0]); + #endif + #endif + } + +void prepare(vector& v) { + #if CAP_VERTEXBUFFER + bindbuffer(v); + PTR(glhr::aPosition, 3, coords); + PTR(glhr::aColor, 4, color); + #else + if(current_vertices == &v[0]) return; + current_vertices = &v[0]; + #if CAP_SHADER + glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(colored_vertex), &v[0].coords); + glVertexAttribPointer(aColor, 4, GL_FLOAT, GL_FALSE, sizeof(colored_vertex), &v[0].color); + #else + glVertexPointer(3, GL_FLOAT, sizeof(colored_vertex), &v[0].coords); + glVertexPointer(3, GL_FLOAT, sizeof(colored_vertex), &v[0].color); + #endif + #endif + } + +void prepare(vector& v) { + #if CAP_VERTEXBUFFER + bindbuffer(v); + PTR(glhr::aPosition, 3, coords); + PTR(glhr::aTexture, 2, texture); + #else + if(current_vertices == &v[0]) return; + current_vertices = &v[0]; + #if CAP_SHADER + glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(textured_vertex), &v[0].coords); + glVertexAttribPointer(aTexture, 3, GL_FLOAT, GL_FALSE, sizeof(textured_vertex), &v[0].texture); + #else + glVertexPointer(3, GL_FLOAT, sizeof(textured_vertex), &v[0].coords); + glVertexPointer(3, GL_FLOAT, sizeof(textured_vertex), &v[0].texture); + #endif + #endif + // color2(col); + } + +void prepare(vector& v) { + #if CAP_VERTEXBUFFER + bindbuffer(v); + PTR(glhr::aPosition, 3, coords); + PTR(glhr::aColor, 4, color); + PTR(glhr::aTexture, 2, texture); + #else + if(current_vertices == &v[0]) return; + current_vertices = &v[0]; + #if CAP_SHADER + glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(ct_vertex), &v[0].coords); + glVertexAttribPointer(aColor, 4, GL_FLOAT, GL_FALSE, sizeof(ct_vertex), &v[0].color); + glVertexAttribPointer(aTexture, 3, GL_FLOAT, GL_FALSE, sizeof(ct_vertex), &v[0].texture); + #else + glVertexPointer(3, GL_FLOAT, sizeof(ct_vertex), &v[0].coords); + glVertexPointer(3, GL_FLOAT, sizeof(ct_vertex), &v[0].texture); + glVertexPointer(3, GL_FLOAT, sizeof(ct_vertex), &v[0].color); + #endif + #endif + } + +void store_in_buffer(vector& v) { +#if CAP_VERTEXBUFFER + if(!buf_buffered) { + printf("no buffer yet\n"); + return; + } + printf("storing %d in buffer: %p\n", size(v), &v[0]); + current_vertices = buffered_vertices = &v[0]; + glBindBuffer(GL_ARRAY_BUFFER, buf_buffered); + glVertexAttribPointer(glhr::aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), 0); + glBufferData(GL_ARRAY_BUFFER, size(v) * sizeof(glvertex), &v[0], GL_STATIC_DRAW); + printf("Stored.\n"); +#endif } } diff --git a/textures.cpp b/textures.cpp index dab3fc3f..e60b7fee 100644 --- a/textures.cpp +++ b/textures.cpp @@ -243,9 +243,6 @@ int color_alpha = 128; int gsplits = 1; -template array make_array(T a, T b, T c) { array x; x[0] = a; x[1] = b; x[2] = c; return x; } -template array make_array(T a, T b) { array x; x[0] = a; x[1] = b; return x; } - void mapTextureTriangle(textureinfo &mi, array v, int splits = gsplits) { if(splits) { @@ -258,16 +255,13 @@ void mapTextureTriangle(textureinfo &mi, array v, int splits = gs } for(int i=0; i<3; i++) { - for(int j=0; j<3; j++) - mi.vertices.push_back(v[i][j]); + mi.vertices.push_back(glhr::pointtogl(v[i])); hyperpoint inmodel; applymodel(mi.M * v[i], inmodel); inmodel = itt * inmodel; inmodel[0] *= vid.radius * 1. / vid.scrsize; inmodel[1] *= vid.radius * 1. / vid.scrsize; - mi.tvertices.push_back((inmodel[0]+1)/2); - mi.tvertices.push_back((inmodel[1]+1)/2); - mi.tvertices.push_back(0); + mi.tvertices.push_back(make_array((inmodel[0]+1)/2, (inmodel[1]+1)/2, 0)); } } @@ -325,7 +319,7 @@ bool apply(cell *c, const transmatrix &V, int col) { qfi.spin = applyPatterndir(c, si); - int n = mi.vertices.size() / 3; + int n = mi.vertices.size(); qfi.special = false; qfi.shape = &shFullFloor[ctof(c)]; @@ -334,10 +328,10 @@ bool apply(cell *c, const transmatrix &V, int col) { if(chasmg == 2) return false; else if(chasmg && wmspatial) { if(detaillevel == 0) return false; - queuetable(V * qfi.spin, &mi.vertices[0], n, mesh_color, recolor(c->land == laCocytus ? 0x080808FF : 0x101010FF), PPR_LAKEBOTTOM); + queuetable(V * qfi.spin, mi.vertices, n, mesh_color, recolor(c->land == laCocytus ? 0x080808FF : 0x101010FF), PPR_LAKEBOTTOM); } else { - queuetable(V * qfi.spin, &mi.vertices[0], n, mesh_color, recolor(col), PPR_FLOOR); + queuetable(V * qfi.spin, mi.vertices, n, mesh_color, recolor(col), PPR_FLOOR); } lastptd().u.poly.tinf = &mi; @@ -348,7 +342,7 @@ bool apply(cell *c, const transmatrix &V, int col) { if(texture::saving) { // create a nicer aura for saved texture - for(int i=0; i rtver(4); + void drawRawTexture() { glhr::be_textured(); glhr::color2(0xFFFFFF20); - glhr::set_modelview(glhr::translate(0, 0, stereo::scrdist)); glBindTexture(GL_TEXTURE_2D, textureid); - vector tver, sver; for(int i=0; i<4; i++) { int cx[4] = {2, -2, -2, 2}; int cy[4] = {2, 2, -2, -2}; @@ -477,15 +471,13 @@ void drawRawTexture() { int y = cy[i]; hyperpoint inmodel = hpxyz(x, y, 1); inmodel = itt * inmodel; - tver.push_back((inmodel[0]+1)/2); - tver.push_back((inmodel[1]+1)/2); - tver.push_back(0); - sver.push_back(x * vid.scrsize); - sver.push_back(y * vid.scrsize); - sver.push_back(0); + rtver[i].texture[0] = (inmodel[0]+1)/2; + rtver[i].texture[1] = (inmodel[1]+1)/2; + rtver[i].coords[0] = x * vid.scrsize; + rtver[i].coords[1] = y * vid.scrsize; } - glhr::vertices(&sver[0], 4); - glhr::texture_vertices(&tver[0], 4, 3); + glhr::set_modelview(glhr::translate(0, 0, stereo::scrdist)); + glhr::prepare(rtver); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } @@ -1263,7 +1255,7 @@ void remap(eTextureState old_tstate, eTextureState old_tstate_max) { auto& mi = texture_map_orig.at(oldid); int ncurr = size(mi.tvertices); int ntarget = ncurr * c->type / mi.current_type; - vector new_tvertices = mi.tvertices; + vector new_tvertices = mi.tvertices; new_tvertices.resize(ntarget); for(int i=ncurr; i