diff --git a/source/build/include/build.h b/source/build/include/build.h index a9d1a4fcd..b22dfbafa 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1316,8 +1316,6 @@ void tileInvalidate(int16_t tilenume, int32_t pal, int32_t how); void polymostSet2dView(void); // sets up GL for 2D drawing -int32_t polymost_drawtilescreen(int32_t tilex, int32_t tiley, int32_t wallnum, int32_t dimen, int32_t tilezoom, - int32_t usehitile, uint8_t *loadedhitile); void polymost_glreset(void); void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype); @@ -1352,9 +1350,7 @@ extern int32_t r_detailmapping; extern int32_t r_glowmapping; # endif -extern int32_t r_vertexarrays; # ifdef USE_GLEXT -extern int32_t r_vbos; extern int32_t r_vbocount; # endif extern int32_t r_animsmoothing; diff --git a/source/build/include/mdsprite.h b/source/build/include/mdsprite.h index f132cccd7..d2e501339 100644 --- a/source/build/include/mdsprite.h +++ b/source/build/include/mdsprite.h @@ -167,11 +167,12 @@ typedef struct uint16_t *vindexes; float *maxdepths; - GLuint *vbos; // polymer VBO names after that, allocated per surface + /* GLuint *indices; GLuint *texcoords; GLuint *geometry; + */ } md3model_t; #define VOXBORDWIDTH 1 //use 0 to save memory, but has texture artifacts; 1 looks better... diff --git a/source/build/src/2d.cpp b/source/build/src/2d.cpp index 7fd1aaca4..ba874519e 100644 --- a/source/build/src/2d.cpp +++ b/source/build/src/2d.cpp @@ -8,6 +8,7 @@ #include "build.h" #include "editor.h" +#include "../../glbackend/glbackend.h" int32_t editorgridextent = 131072; @@ -106,14 +107,14 @@ static void drawlinegl(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t glEnable(GL_BLEND); // When using line antialiasing, this is needed polymost_useColorOnly(true); - glBegin(GL_LINES); glColor4ub(p.r, p.g, p.b, 255); - glVertex2f((float) x1 * (1.f/4096.f), (float) y1 * (1.f/4096.f)); - glVertex2f((float) x2 * (1.f/4096.f), (float) y2 * (1.f/4096.f)); + auto data = GLInterface.AllocVertices(2); + data.second[0].Set((float) x1 * (1.f/4096.f), (float) y1 * (1.f/4096.f)); + data.second[1].Set((float) x2 * (1.f/4096.f), (float) y2 * (1.f/4096.f)); + GLInterface.Draw(DT_LINES, data.first, 2); - glEnd(); - polymost_useColorOnly(false); + polymost_useColorOnly(false); } #endif diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index b8661a905..98dbb9bb6 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -9,6 +9,7 @@ #include "build.h" #include "glad/glad.h" #include "cache1d.h" +#include "../../glbackend/glbackend.h" #undef UNUSED #define VPX_CODEC_DISABLE_COMPAT 1 @@ -550,21 +551,22 @@ int32_t animvpx_render_frame(animvpx_codec_ctx *codec, double animvpx_aspect) if (!glinfo.glsl) glColor3f(1.0, 1.0, 1.0); - glBegin(GL_QUADS); + auto data = GLInterface.AllocVertices(4); + auto vt = data.second; - glTexCoord2f(0.0,1.0); - glVertex3f(-x, -y, 0.0); + vt[0].SetTexCoord(0.0,1.0); + vt[0].SetVertex(-x, -y, 0.0); - glTexCoord2f(0.0,0.0); - glVertex3f(-x, y, 0.0); + vt[1].SetTexCoord(0.0,0.0); + vt[1].SetVertex(-x, y, 0.0); - glTexCoord2f(1.0,0.0); - glVertex3f(x, y, 0.0); + vt[2].SetTexCoord(1.0,0.0); + vt[2].SetVertex(x, y, 0.0); - glTexCoord2f(1.0,1.0); - glVertex3f(x, -y, 0.0); + vt[3].SetTexCoord(1.0,1.0); + vt[3].SetVertex(x, -y, 0.0); - glEnd(); + GLInterface.Draw(DT_TRIANGLE_FAN, data.first, 4); t = timerGetTicks()-t; codec->sumtimes[2] += t; diff --git a/source/build/src/glsurface.cpp b/source/build/src/glsurface.cpp index 8d5c9668f..a4897fdce 100644 --- a/source/build/src/glsurface.cpp +++ b/source/build/src/glsurface.cpp @@ -10,6 +10,7 @@ #include "baselayer.h" #include "build.h" +#include "../../glbackend/glbackend.h" static void* buffer; static GLuint bufferTexID; @@ -17,8 +18,6 @@ static vec2_t bufferRes; static GLuint paletteTexID; -static GLuint quadVertsID = 0; - static GLuint shaderProgramID = 0; static GLint texSamplerLoc = -1; static GLint paletteSamplerLoc = -1; @@ -65,25 +64,6 @@ bool glsurface_initialize(vec2_t bufferResolution) bufferRes = bufferResolution; buffer = Xaligned_alloc(16, bufferRes.x * bufferRes.y); - glGenBuffers(1, &quadVertsID); - glBindBuffer(GL_ARRAY_BUFFER, quadVertsID); - const float quadVerts[] = - { - -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, //top-left - -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, //bottom-left - 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, //top-right - 1.0f, -1.0f, 0.0f, 1.0f, 1.0f //bottom-right - }; - glBufferData(GL_ARRAY_BUFFER, sizeof(quadVerts), quadVerts, GL_STATIC_DRAW); - - //specify format/arrangement for vertex positions: - glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(float) * 5, 0); - //specify format/arrangement for vertex texture coords: - glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 5, (const void*) (sizeof(float) * 3)); - - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glActiveTexture(GL_TEXTURE0); glGenTextures(1, &bufferTexID); glBindTexture(GL_TEXTURE_2D, bufferTexID); @@ -167,12 +147,6 @@ void glsurface_destroy() ALIGNED_FREE_AND_NULL(buffer); - glDeleteBuffers(1, &quadVertsID); - quadVertsID = 0; - - glDisableVertexAttribArray(0); - glDisableVertexAttribArray(1); - glDeleteTextures(1, &bufferTexID); bufferTexID = 0; glDeleteTextures(1, &paletteTexID); @@ -229,7 +203,12 @@ void glsurface_blitBuffer() glActiveTexture(GL_TEXTURE0); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bufferRes.x, bufferRes.y, GL_RED, GL_UNSIGNED_BYTE, (void*) buffer); - glDrawArrays(GL_TRIANGLE_STRIP, - 0, - 4); + auto data = GLInterface.AllocVertices(4); + auto vt = data.second; + + vt[0].Set(-1.0f, 1.0f, 0.0f, 0.0f, 0.0f); //top-left + vt[1].Set(-1.0f, -1.0f, 0.0f, 0.0f, 1.0f); //bottom-left + vt[2].Set(1.0f, 1.0f, 0.0f, 1.0f, 0.0f); //top-right + vt[3].Set(1.0f, -1.0f, 0.0f, 1.0f, 1.0f); //bottom-right + GLInterface.Draw(DT_TRIANGLE_STRIP, data.first, 4); } diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index f0fcda732..2e89456be 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -16,6 +16,7 @@ #include "kplib.h" #include "common.h" #include "palette.h" +#include "../../glbackend/glbackend.h" #include "vfs.h" @@ -93,32 +94,6 @@ int32_t globalnoeffect=0; extern int32_t timerticspersec; -#ifdef USE_GLEXT -void md_freevbos() -{ - int32_t i; - - for (i=0; imdnum == 3) - { - md3model_t *m = (md3model_t *)models[i]; - if (m->vbos) - { - // OSD_Printf("freeing model %d vbo\n",i); - glDeleteBuffers(m->head.numsurfs, m->vbos); - DO_FREE_AND_NULL(m->vbos); - } - } - - if (allocvbos) - { - glDeleteBuffers(allocvbos, indexvbos); - glDeleteBuffers(allocvbos, vertvbos); - allocvbos = 0; - } -} -#endif - void freeallmodels() { int32_t i; @@ -144,9 +119,6 @@ void freeallmodels() allocmodeltris = maxmodeltris = 0; } -#ifdef USE_GLEXT - md_freevbos(); -#endif #ifdef POLYMER DO_FREE_AND_NULL(tribuf); #endif @@ -1173,26 +1145,6 @@ prep_return: m->nframe = 0; } -#ifdef USE_GLEXT -// VBO generation and allocation -static void mdloadvbos(md3model_t *m) -{ - int32_t i; - - m->vbos = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint)); - glGenBuffers(m->head.numsurfs, m->vbos); - - i = 0; - while (i < m->head.numsurfs) - { - glBindBuffer(GL_ARRAY_BUFFER, m->vbos[i]); - glBufferData(GL_ARRAY_BUFFER, m->head.surfs[i].numverts * sizeof(md3uv_t), m->head.surfs[i].uv, GL_STATIC_DRAW); - i++; - } - glBindBuffer(GL_ARRAY_BUFFER, 0); -} -#endif - //--------------------------------------- MD2 LIBRARY BEGINS --------------------------------------- static md2model_t *md2load(buildvfs_kfd fil, const char *filnam) { @@ -1431,8 +1383,6 @@ static md2model_t *md2load(buildvfs_kfd fil, const char *filnam) m3->vindexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * s->numtris * 3); m3->maxdepths = (float *)Xmalloc(sizeof(float) * s->numtris); - m3->vbos = NULL; - // die MD2 ! DIE ! Bfree(m->texid); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); @@ -1622,54 +1572,9 @@ static md3model_t *md3load(buildvfs_kfd fil) m->vindexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * maxtrispersurf * 3); m->maxdepths = (float *)Xmalloc(sizeof(float) * maxtrispersurf); - m->vbos = NULL; - return m; } -#ifdef POLYMER -static inline void invertmatrix(const float *m, float *out) -{ - float det; - - det = (m[0] * (m[4]*m[8] - m[5] * m[7])) - - (m[1] * (m[3]*m[8] - m[5] * m[6])) - + (m[2] * (m[3]*m[7] - m[4] * m[6])); - - if (det == 0.0f) - { - Bmemset(out, 0, sizeof(float) * 9); - out[8] = out[4] = out[0] = 1.f; - return; - } - - det = 1.0f / det; - - out[0] = det * (m[4] * m[8] - m[5] * m[7]); - out[1] = det * (m[2] * m[7] - m[1] * m[8]); - out[2] = det * (m[1] * m[5] - m[2] * m[4]); - out[3] = det * (m[5] * m[6] - m[3] * m[8]); - out[4] = det * (m[0] * m[8] - m[2] * m[6]); - out[5] = det * (m[2] * m[3] - m[0] * m[5]); - out[6] = det * (m[3] * m[7] - m[1] * m[6]); - out[7] = det * (m[1] * m[6] - m[0] * m[7]); - out[8] = det * (m[0] * m[4] - m[1] * m[3]); -} - -static inline void normalize(float *vec) -{ - float norm; - - if ((norm = vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]) == 0.f) - return; - - norm = polymost_invsqrt_approximation(norm); - vec[0] *= norm; - vec[1] *= norm; - vec[2] *= norm; -} -#endif - static void md3postload_common(md3model_t *m) { int framei, surfi, verti; @@ -2037,58 +1942,24 @@ static void md3draw_handle_triangles(const md3surf_t *s, uint16_t *indexhandle, { int32_t i; - if (r_vertexarrays) - { - int32_t k = 0; - if (M == NULL) - { - for (i=s->numtris-1; i>=0; i--, k+=3) - { - indexhandle[k] = s->tris[i].i[0]; - indexhandle[k+1] = s->tris[i].i[1]; - indexhandle[k+2] = s->tris[i].i[2]; - } - return; - } - - - for (i=s->numtris-1; i>=0; i--, k+=3) - { - uint16_t tri = M->indexes[i]; - - indexhandle[k] = s->tris[tri].i[0]; - indexhandle[k+1] = s->tris[tri].i[1]; - indexhandle[k+2] = s->tris[tri].i[2]; - } - return; - } - - glBegin(GL_TRIANGLES); + auto data = GLInterface.AllocVertices(s->numtris * 3); + auto vt = data.second; for (i=s->numtris-1; i>=0; i--) { uint16_t tri = M ? M->indexes[i] : i; int32_t j; - for (j=0; j<3; j++) + for (j=0; j<3; j++, vt++) { int32_t k = s->tris[tri].i[j]; -#ifdef USE_GLEXT - if (texunits > GL_TEXTURE0) - { - int32_t l = GL_TEXTURE0; - while (l <= texunits) - glMultiTexCoord2f(l++, s->uv[k].u, s->uv[k].v); - } - else -#endif - glTexCoord2f(s->uv[k].u, s->uv[k].v); + vt->SetTexCoord(s->uv[k].u, s->uv[k].v); - glVertex3fv((float *) &vertlist[k]); + vt->SetVertex(vertlist[k].x, vertlist[k].y); } } - glEnd(); + GLInterface.Draw(DT_TRIANGLES, data.first, s->numtris *3); #ifndef USE_GLEXT UNREFERENCED_PARAMETER(texunits); @@ -2109,11 +1980,6 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) const uint8_t lpal = ((unsigned)owner < MAXSPRITES) ? sprite[tspr->owner].pal : tspr->pal; const int32_t sizyrep = tilesiz[tspr->picnum].y*tspr->yrepeat; -#ifdef USE_GLEXT - if (r_vbos && (m->vbos == NULL)) - mdloadvbos(m); -#endif - // if ((tspr->cstat&48) == 32) return 0; updateanimation((md2model_t *)m, tspr, lpal); @@ -2294,10 +2160,6 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) for (surfi=0; surfihead.numsurfs; surfi++) { //PLAG : sorting stuff -#ifdef USE_GLEXT - void *vbotemp; - vec3f_t *vertexhandle = NULL; -#endif uint16_t *indexhandle; vec3f_t fp; @@ -2306,18 +2168,6 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) v0 = &s->xyzn[m->cframe*s->numverts]; v1 = &s->xyzn[m->nframe*s->numverts]; -#ifdef USE_GLEXT - if (r_vertexarrays && r_vbos) - { - if (++curvbo >= r_vbocount) - curvbo = 0; - - glBindBuffer(GL_ARRAY_BUFFER, vertvbos[curvbo]); - vbotemp = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); - vertexhandle = (vec3f_t *)vbotemp; - } -#endif - if (sext->pitch || sext->roll) { vec3f_t fp1, fp2; @@ -2343,11 +2193,6 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) fp.x = (fp1.x - a0.y)*m0.y + (fp2.x - a0.y)*m1.y; fp.y = (fp1.y - a0.z)*m0.z + (fp2.y - a0.z)*m1.z; -#ifdef USE_GLEXT - if (r_vertexarrays && r_vbos) - vertexhandle[i] = fp; -#endif - vertlist[i] = fp; } } @@ -2359,23 +2204,10 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) fp.y = v0[i].z*m0.z + v1[i].z*m1.z; fp.x = v0[i].y*m0.y + v1[i].y*m1.y; -#ifdef USE_GLEXT - if (r_vertexarrays && r_vbos) - vertexhandle[i] = fp; -#endif - vertlist[i] = fp; } } -#ifdef USE_GLEXT - if (r_vertexarrays && r_vbos) - { - glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } -#endif - glMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; glLoadMatrixf(mat); // PLAG: End @@ -2430,13 +2262,6 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) glMatrixMode(GL_MODELVIEW); } - if (r_vertexarrays && r_vbos) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[curvbo]); - vbotemp = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); - indexhandle = (uint16_t *) vbotemp; - } - else #endif indexhandle = m->vindexes; @@ -2484,85 +2309,12 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) } else { -#ifdef USE_GLEXT - if (r_vertexarrays && r_vbos) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[curvbo]); - vbotemp = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); - indexhandle = (uint16_t *) vbotemp; - } - else -#endif - indexhandle = m->vindexes; + indexhandle = m->vindexes; md3draw_handle_triangles(s, indexhandle, texunits, NULL); } - if (r_vertexarrays) - { #ifdef USE_GLEXT - int32_t l; - - if (r_vbos) - { - glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glBindBuffer(GL_ARRAY_BUFFER, m->vbos[surfi]); - - l = GL_TEXTURE0; - do - { - glClientActiveTexture(l++); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, 0); - } while (l <= texunits); - - glBindBuffer(GL_ARRAY_BUFFER, vertvbos[curvbo]); - glVertexPointer(3, GL_FLOAT, 0, 0); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[curvbo]); - glDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, 0); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - } - else // r_vbos - { - l = GL_TEXTURE0; - do - { - glClientActiveTexture(l++); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, &(s->uv[0].u)); - } while (l <= texunits); - - glVertexPointer(3, GL_FLOAT, 0, &(vertlist[0].x)); - - glDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, m->vindexes); - } // r_vbos - - while (texunits > GL_TEXTURE0) - { - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f); - glDisable(GL_TEXTURE_2D); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glClientActiveTexture(texunits - 1); - glActiveTexture(--texunits); - } -#else - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, &(s->uv[0].u)); - - glVertexPointer(3, GL_FLOAT, 0, &(vertlist[0].x)); - - glDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, m->vindexes); -#endif - } -#ifdef USE_GLEXT - else // r_vertexarrays { while (texunits > GL_TEXTURE0) { @@ -2571,7 +2323,6 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr) glMatrixMode(GL_MODELVIEW); glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f); glDisable(GL_TEXTURE_2D); - glActiveTexture(--texunits); } } // r_vertexarrays @@ -2638,14 +2389,6 @@ static void md3free(md3model_t *m) Bfree(m->vindexes); Bfree(m->maxdepths); -#ifdef USE_GLEXT - if (m->vbos) - { - glDeleteBuffers(m->head.numsurfs, m->vbos); - DO_FREE_AND_NULL(m->vbos); - } -#endif - Bfree(m); } @@ -2694,57 +2437,14 @@ mdmodel_t *mdload(const char *filnam) md3postload_common(vm3); -#ifdef POLYMER - if (glrendmode != REND_POLYMER) - if (md3postload_polymer_check(vm3)) - { - mdfree(vm); - vm = NULL; - } -#endif } return vm; } -#ifdef USE_GLEXT -void md_allocvbos(void) -{ - int32_t i; - - indexvbos = (GLuint *) Xrealloc(indexvbos, sizeof(GLuint) * r_vbocount); - vertvbos = (GLuint *) Xrealloc(vertvbos, sizeof(GLuint) * r_vbocount); - - if (r_vbocount != allocvbos) - { - glGenBuffers(r_vbocount - allocvbos, &(indexvbos[allocvbos])); - glGenBuffers(r_vbocount - allocvbos, &(vertvbos[allocvbos])); - - i = allocvbos; - while (i < r_vbocount) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[i]); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, maxmodeltris * 3 * sizeof(uint16_t), NULL, GL_STREAM_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, vertvbos[i]); - glBufferData(GL_ARRAY_BUFFER, maxmodelverts * sizeof(vec3f_t), NULL, GL_STREAM_DRAW); - i++; - } - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - allocvbos = r_vbocount; - } -} -#endif int32_t polymost_mddraw(const uspritetype *tspr) { -#ifdef USE_GLEXT - if (r_vbos && (r_vbocount > allocvbos)) - md_allocvbos(); -#endif - if (maxmodelverts > allocmodelverts) { vertlist = (vec3f_t *) Xrealloc(vertlist, sizeof(vec3f_t)*maxmodelverts); diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index ed643380b..d9eafa3de 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -15,6 +15,7 @@ #include "palette.h" #include "a.h" #include "xxhash.h" +#include "../../glbackend/glbackend.h" #include "vfs.h" @@ -66,11 +67,13 @@ void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f) glColor4ub(r, g, b, f); polymost_useColorOnly(true); - glBegin(GL_TRIANGLES); - glVertex2f(-2.5f, 1.f); - glVertex2f(2.5f, 1.f); - glVertex2f(.0f, -2.5f); - glEnd(); + + auto data = GLInterface.AllocVertices(3); + auto vt = data.second; + vt[0].Set(-2.5f, 1.f); + vt[1].Set(2.5f, 1.f); + vt[2].Set(.0f, -2.5f); + GLInterface.Draw(DT_TRIANGLES, data.first, 3); polymost_useColorOnly(false); glPopMatrix(); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 0ec446820..bbaf9d0ce 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -81,19 +81,6 @@ static int32_t preview_mouseaim=1; // when 1, displays a CROSSHAIR tsprite at t static int32_t drawpoly_srepeat = 0, drawpoly_trepeat = 0; #define MAX_DRAWPOLY_VERTS 8 -#define BUFFER_OFFSET(bytes) (GLintptr) ((GLubyte*) NULL + (bytes)) -// these cvars are never used directly in rendering -- only when glinit() is called/renderer reset -// We do this because we don't want to accidentally overshoot our existing buffer's bounds -uint32_t r_persistentStreamBuffer = 1; -uint32_t persistentStreamBuffer = r_persistentStreamBuffer; -int32_t r_drawpolyVertsBufferLength = 30000; -int32_t drawpolyVertsBufferLength = r_drawpolyVertsBufferLength; -static GLuint drawpolyVertsID = 0; -static GLint drawpolyVertsOffset = 0; -static int32_t drawpolyVertsSubBufferIndex = 0; -static GLsync drawpolyVertsSync[3] = { 0 }; -static float defaultDrawpolyVertsArray[MAX_DRAWPOLY_VERTS*5]; -static float* drawpolyVerts = defaultDrawpolyVertsArray; struct glfiltermodes glfiltermodes[NUMGLFILTERMODES] = { @@ -133,10 +120,8 @@ int32_t glrendmode = REND_POLYMOST; // fullbright tiles. Also see 'fullbrightloadingpass'. int32_t r_fullbrights = 1; -int32_t r_vertexarrays = 1; #ifdef USE_GLEXT //POGOTODO: we no longer support rendering without VBOs -- update any outdated pre-GL2 code that renders without VBOs -int32_t r_vbos = 1; int32_t r_vbocount = 64; #endif int32_t r_animsmoothing = 1; @@ -550,10 +535,6 @@ void polymost_glreset() glDeleteTextures(1,&polymosttext); polymosttext=0; -#ifdef USE_GLEXT - md_freevbos(); -#endif - Bmemset(texcache.list,0,sizeof(texcache.list)); glox1 = -1; @@ -572,25 +553,6 @@ static void Polymost_DetermineTextureFormatSupport(void); // reset vertex pointers to polymost default void polymost_resetVertexPointers() { - glBindBuffer(GL_ARRAY_BUFFER, drawpolyVertsID); - - glVertexPointer(3, GL_FLOAT, 5*sizeof(float), 0); - glTexCoordPointer(2, GL_FLOAT, 5*sizeof(float), (GLvoid*) (3*sizeof(float))); - -#ifdef USE_GLEXT - if (r_detailmapping) - { - glClientActiveTexture(GL_TEXTURE3); - glTexCoordPointer(2, GL_FLOAT, 5*sizeof(float), (GLvoid*) (3*sizeof(float))); - } - if (r_glowmapping) - { - glClientActiveTexture(GL_TEXTURE4); - glTexCoordPointer(2, GL_FLOAT, 5*sizeof(float), (GLvoid*) (3*sizeof(float))); - } - glClientActiveTexture(GL_TEXTURE0); -#endif - polymost_resetProgram(); } @@ -899,43 +861,8 @@ void polymost_glinit() glEnable(GL_MULTISAMPLE); } - if (r_persistentStreamBuffer && ((!glinfo.bufferstorage) || (!glinfo.sync))) - { - OSD_Printf("Your OpenGL implementation doesn't support the required extensions for persistent stream buffers. Disabling...\n"); - r_persistentStreamBuffer = 0; - } #endif - //POGOTODO: require a max texture size >= 2048 - - persistentStreamBuffer = r_persistentStreamBuffer; - drawpolyVertsBufferLength = r_drawpolyVertsBufferLength; - - drawpolyVertsOffset = 0; - drawpolyVertsSubBufferIndex = 0; - - GLuint ids[2]; - glGenBuffers(2, ids); - drawpolyVertsID = ids[0]; - glBindBuffer(GL_ARRAY_BUFFER, drawpolyVertsID); - if (persistentStreamBuffer) - { - // reset the sync objects, as old ones we had from any last GL context are gone now - Bmemset(drawpolyVertsSync, 0, sizeof(drawpolyVertsSync)); - - GLbitfield flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT; - // we want to triple-buffer to avoid having to wait for the buffer to become available again, - // so triple the buffer size we expect to use - glBufferStorage(GL_ARRAY_BUFFER, 3*drawpolyVertsBufferLength*sizeof(float)*5, NULL, flags); - drawpolyVerts = (float*) glMapBufferRange(GL_ARRAY_BUFFER, 0, 3*drawpolyVertsBufferLength*sizeof(float)*5, flags); - } - else - { - drawpolyVerts = defaultDrawpolyVertsArray; - glBufferData(GL_ARRAY_BUFFER, drawpolyVertsBufferLength*sizeof(float)*5, NULL, GL_STREAM_DRAW); - } - glBindBuffer(GL_ARRAY_BUFFER, 0); - currentTextureID = 0; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &tilesheetSize); @@ -974,24 +901,6 @@ void polymost_glinit() glBindTexture(GL_TEXTURE_2D, tilesheetTexIDs[blankTile.tilesheetID]); uploadtextureindexed(false, {(int32_t) blankTile.rect.u, (int32_t) blankTile.rect.v}, {2, 2}, (intptr_t) blankTex); - quadVertsID = ids[1]; - glBindBuffer(GL_ARRAY_BUFFER, quadVertsID); - const float quadVerts[] = - { - -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, //top-left - -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, //bottom-left - 0.5f, 1.0f, 0.0f, 1.0f, 1.0f, //top-right - 0.5f, 0.0f, 0.0f, 1.0f, 0.0f //bottom-right - }; - glBufferData(GL_ARRAY_BUFFER, sizeof(quadVerts), quadVerts, GL_STATIC_DRAW); - - //specify format/arrangement for vertex positions: - glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(float) * 5, 0); - //specify format/arrangement for vertex texture coords: - glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 5, (const void*) (sizeof(float) * 3)); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - const char* const POLYMOST2_BASIC_VERTEX_SHADER_CODE = "#version 110\n\ \n\ @@ -2552,53 +2461,6 @@ static void polymost_updatePalette() } } -static void polymost_lockSubBuffer(uint32_t subBufferIndex) -{ - if (drawpolyVertsSync[subBufferIndex]) - { - glDeleteSync(drawpolyVertsSync[subBufferIndex]); - } - - drawpolyVertsSync[subBufferIndex] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); -} - -static void polymost_waitForSubBuffer(uint32_t subBufferIndex) -{ - if (drawpolyVertsSync[subBufferIndex]) - { - while (true) - { - // we only need to flush if there's a possibility that drawpolyVertsBufferLength is - // so small that we can eat through 3 times the buffer size in a single frame - GLenum waitResult = glClientWaitSync(drawpolyVertsSync[subBufferIndex], GL_SYNC_FLUSH_COMMANDS_BIT, 500000); - if (waitResult == GL_ALREADY_SIGNALED || - waitResult == GL_CONDITION_SATISFIED) - { - return; - } - if (waitResult == GL_WAIT_FAILED) - { - OSD_Printf("polymost_waitForSubBuffer: Wait failed! Error 0x%X. Disabling r_persistentStreamBuffer.\n", glGetError()); - r_persistentStreamBuffer = 0; - videoResetMode(); - if (videoSetGameMode(fullscreen,xres,yres,bpp,upscalefactor)) - { - OSD_Printf("polymost_waitForSubBuffer: Video reset failed. Please ensure r_persistentStreamBuffer = 0 and try restarting the game.\n"); - Bexit(1); - } - return; - } - - static char loggedLongWait = false; - if (waitResult == GL_TIMEOUT_EXPIRED && - !loggedLongWait) - { - OSD_Printf("polymost_waitForSubBuffer(): Had to wait for the drawpoly buffer to become available. For performance, try increasing buffer size with r_drawpolyVertsBufferLength.\n"); - loggedLongWait = true; - } - } - } -} static void polymost_updaterotmat(void) { @@ -7228,15 +7090,16 @@ static void drawtrap(float x0, float x1, float y0, float x2, float x3, float y1) else if (x2 == x3) { px[1] = x1; py[1] = y0; px[2] = x3; } else { px[1] = x1; py[1] = y0; px[2] = x3; px[3] = x2; py[3] = y1; n = 4; } - glBegin(GL_TRIANGLE_FAN); - for (bssize_t i=0; iSetTexCoord(px[i]*xtex.u + py[i]*ytex.u + otex.u, px[i]*xtex.v + py[i]*ytex.v + otex.v); - glVertex2f(px[i],py[i]); + vt->SetVertex(px[i],py[i]); } - glEnd(); + GLInterface.Draw(DT_TRIANGLE_FAN, data.first, n); } static void tessectrap(const float *px, const float *py, const int32_t *point2, int32_t numpoints) @@ -7280,15 +7143,17 @@ static void tessectrap(const float *px, const float *py, const int32_t *point2, } if (z != 3) //Simple polygon... early out { - glBegin(GL_TRIANGLE_FAN); - for (i=0; iSetTexCoord(px[j]*xtex.u + py[j]*ytex.u + otex.u, px[j]*xtex.v + py[j]*ytex.v + otex.v); - glVertex2f(px[j],py[j]); + vt->SetVertex(px[j],py[j]); } - glEnd(); + GLInterface.Draw(DT_TRIANGLE_FAN, data.first, npoints); return; } @@ -7436,88 +7301,6 @@ void polymost_fillpolygon(int32_t npoints) } } -int32_t polymost_drawtilescreen(int32_t tilex, int32_t tiley, int32_t wallnum, int32_t dimen, int32_t tilezoom, - int32_t usehitile, uint8_t *loadedhitile) -{ - float xdime, ydime, xdimepad, ydimepad, scx, scy, ratio = 1.f; - int32_t i; - pthtyp *pth; - - if (videoGetRenderMode() < REND_POLYMOST || !in3dmode()) - return -1; - - if (!glinfo.texnpot) - { - i = (1<<(picsiz[wallnum]&15)); if (i < tilesiz[wallnum].x) i += i; xdimepad = (float)i; - i = (1<<(picsiz[wallnum]>>4)); if (i < tilesiz[wallnum].y) i += i; ydimepad = (float)i; - } - else - { - xdimepad = (float)tilesiz[wallnum].x; - ydimepad = (float)tilesiz[wallnum].y; - } - xdime = (float)tilesiz[wallnum].x; xdimepad = xdime/xdimepad; - ydime = (float)tilesiz[wallnum].y; ydimepad = ydime/ydimepad; - - if ((xdime <= dimen) && (ydime <= dimen)) - { - scx = xdime; - scy = ydime; - } - else - { - scx = (float)dimen; - scy = (float)dimen; - if (xdime < ydime) - scx *= xdime/ydime; - else - scy *= ydime/xdime; - } - - int32_t const ousehightile = usehightile; - usehightile = usehitile && usehightile; - pth = texcache_fetch(wallnum, 0, 0, DAMETH_CLAMPED | (videoGetRenderMode() == REND_POLYMOST && r_useindexedcolortextures ? PTH_INDEXED : 0)); - if (usehightile) - loadedhitile[wallnum>>3] |= (1<<(wallnum&7)); - usehightile = ousehightile; - - if (pth) - { - polymost_bindPth(pth); - - if (!(pth->flags & PTH_INDEXED)) - polymost_usePaletteIndexing(false); - } - - polymost_updatePalette(); - - glDisable(GL_ALPHA_TEST); - - if (tilezoom) - { - if (scx > scy) ratio = dimen/scx; - else ratio = dimen/scy; - } - - glColor3f(1,1,1); - glEnable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - glBegin(GL_TRIANGLE_FAN); - glTexCoord2f(0, 0); glVertex2f((float)tilex ,(float)tiley); - glTexCoord2f(xdimepad, 0); glVertex2f((float)tilex+(scx*ratio),(float)tiley); - glTexCoord2f(xdimepad,ydimepad); glVertex2f((float)tilex+(scx*ratio),(float)tiley+(scy*ratio)); - glTexCoord2f(0, ydimepad); glVertex2f((float)tilex ,(float)tiley+(scy*ratio)); - glEnd(); - - if (pth && !(pth->flags & PTH_INDEXED)) - { - // restore palette usage if we were just rendering a non-indexed color texture - polymost_usePaletteIndexing(true); - } - - return 0; -} - static int32_t gen_font_glyph_tex(void) { // construct a 256x128 texture for the font glyph matrix @@ -7613,14 +7396,15 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba glColor4ub(b.r,b.g,b.b,255); - glBegin(GL_QUADS); + auto data = GLInterface.AllocVertices(4); + auto vt = data.second; - glVertex2i(xpos,ypos); - glVertex2i(xpos,ypos+(fontsize?6:8)); - glVertex2i(xpos+(c<<(3-fontsize)), ypos+(fontsize ? 6 : 8)); - glVertex2i(xpos+(c<<(3-fontsize)), ypos); + vt->SetTexCoord(); vt->SetVertex(xpos, ypos); vt++; + vt->SetTexCoord(); vt->SetVertex(xpos, ypos + (fontsize ? 6 : 8)); vt++; + vt->SetTexCoord(); vt->SetVertex(xpos + (c << (3 - fontsize)), ypos + (fontsize ? 6 : 8)); vt++; + vt->SetTexCoord(); vt->SetVertex(xpos+(c<<(3-fontsize)), ypos); - glEnd(); + GLInterface.Draw(DT_TRIANGLE_FAN, data.first, 4); } glEnable(GL_TEXTURE_2D); @@ -7630,7 +7414,6 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba vec2f_t const tc = { fontsize ? (4.f / 256.f) : (8.f / 256.f), fontsize ? (6.f / 128.f) : (8.f / 128.f) }; - glBegin(GL_QUADS); for (bssize_t c=0; name[c]; ++c) { @@ -7665,22 +7448,30 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba vec2f_t const t = { (float)(name[c] % 32) * (1.0f / 32.f), (float)((name[c] / 32) + (fontsize * 8)) * (1.0f / 16.f) }; - glTexCoord2f(t.x, t.y); - glVertex2i(xpos, ypos); + auto data = GLInterface.AllocVertices(4); + auto vt = data.second; - glTexCoord2f(t.x + tc.x, t.y); - glVertex2i(xpos + (8 >> fontsize), ypos); + vt->SetTexCoord(t.x, t.y); + vt->SetVertex(xpos, ypos); + vt++; - glTexCoord2f(t.x + tc.x, t.y + tc.y); - glVertex2i(xpos + (8 >> fontsize), ypos + (fontsize ? 6 : 8)); + vt->SetTexCoord(t.x + tc.x, t.y); + vt->SetVertex(xpos + (8 >> fontsize), ypos); + vt++; - glTexCoord2f(t.x, t.y + tc.y); - glVertex2i(xpos, ypos + (fontsize ? 6 : 8)); + vt->SetTexCoord(t.x + tc.x, t.y + tc.y); + vt->SetVertex(xpos + (8 >> fontsize), ypos + (fontsize ? 6 : 8)); + vt++; + + vt->SetTexCoord(t.x, t.y + tc.y); + vt->SetVertex(xpos, ypos + (fontsize ? 6 : 8)); + vt++; + + GLInterface.Draw(DT_TRIANGLE_FAN, data.first, 4); xpos += (8>>fontsize); } - glEnd(); glDepthMask(GL_TRUE); // re-enable writing to the z-buffer @@ -7836,53 +7627,8 @@ void polymost_initosdfuncs(void) }, { "r_usetileshades", "enable/disable Polymost tile shade textures", (void *) &r_usetileshades, CVAR_INT | CVAR_INVALIDATEART, 0, 2 }, -#ifdef USE_GLEXT - { "r_vbocount","sets the number of Vertex Buffer Objects to use when drawing models",(void *) &r_vbocount, CVAR_INT, 1, 256 }, - { "r_persistentStreamBuffer","enable/disable persistent stream buffering (requires renderer restart)",(void *) &r_persistentStreamBuffer, CVAR_BOOL, 0, 1 }, - { "r_drawpolyVertsBufferLength","sets the size of the vertex buffer for polymost's streaming VBO rendering (requires renderer restart)",(void *) &r_drawpolyVertsBufferLength, CVAR_INT, MAX_DRAWPOLY_VERTS, 1000000 }, -#endif - { "r_vertexarrays","enable/disable using vertex arrays when drawing models",(void *) &r_vertexarrays, CVAR_BOOL, 0, 1 }, { "r_projectionhack", "enable/disable projection hack", (void *) &glprojectionhacks, CVAR_INT, 0, 1 }, -#ifdef POLYMER - // polymer cvars - { "r_pr_lighting", "enable/disable dynamic lights - restarts renderer", (void *) &pr_lighting, CVAR_INT | CVAR_RESTARTVID, 0, 2 }, - { "r_pr_normalmapping", "enable/disable virtual displacement mapping", (void *) &pr_normalmapping, CVAR_BOOL, 0, 1 }, - { "r_pr_specularmapping", "enable/disable specular mapping", (void *) &pr_specularmapping, CVAR_BOOL, 0, 1 }, - { "r_pr_shadows", "enable/disable dynamic shadows", (void *) &pr_shadows, CVAR_BOOL, 0, 1 }, - { "r_pr_shadowcount", "maximal amount of shadow emitting lights on screen - you need to restart the renderer for it to take effect", (void *) &pr_shadowcount, CVAR_INT, 0, 64 }, - { "r_pr_shadowdetail", "sets the shadow map resolution - you need to restart the renderer for it to take effect", (void *) &pr_shadowdetail, CVAR_INT, 0, 5 }, - { "r_pr_shadowfiltering", "enable/disable shadow edges filtering - you need to restart the renderer for it to take effect", (void *) &pr_shadowfiltering, CVAR_BOOL, 0, 1 }, - { "r_pr_maxlightpasses", "the maximal amount of lights a single object can by affected by", (void *) &r_pr_maxlightpasses, CVAR_INT|CVAR_FUNCPTR, 0, PR_MAXLIGHTS }, - { "r_pr_maxlightpriority", "lowering that value removes less meaningful lights from the scene", (void *) &pr_maxlightpriority, CVAR_INT, 0, PR_MAXLIGHTPRIORITY }, - { "r_pr_customaspect", "if non-zero, forces the 3D view aspect ratio", (void *) &pr_customaspect, CVAR_DOUBLE, 0, 3 }, - { "r_pr_billboardingmode", "face sprite display method. 0: classic mode; 1: polymost mode", (void *) &pr_billboardingmode, CVAR_INT, 0, 1 }, - { "r_pr_verbosity", "verbosity level of the polymer renderer", (void *) &pr_verbosity, CVAR_INT, 0, 3 }, - { "r_pr_wireframe", "toggles wireframe mode", (void *) &pr_wireframe, CVAR_INT | CVAR_NOSAVE, 0, 1 }, - { "r_pr_vbos", "contols Vertex Buffer Object usage. 0: no VBOs. 1: VBOs for map data. 2: VBOs for model data.", (void *) &pr_vbos, CVAR_INT | CVAR_RESTARTVID, 0, 2 }, - { "r_pr_buckets", "controls batching of primitives. 0: no batching. 1: buckets of materials.", (void *)&pr_buckets, CVAR_BOOL | CVAR_NOSAVE | CVAR_RESTARTVID, 0, 1 }, - { "r_pr_gpusmoothing", "toggles model animation interpolation", (void *)&pr_gpusmoothing, CVAR_INT, 0, 1 }, - { "r_pr_overrideparallax", "overrides parallax mapping scale and bias values with values from the pr_parallaxscale and pr_parallaxbias cvars; use it to fine-tune DEF tokens", - (void *) &pr_overrideparallax, CVAR_BOOL | CVAR_NOSAVE, 0, 1 }, - { "r_pr_parallaxscale", "overriden parallax mapping offset scale", (void *) &pr_parallaxscale, CVAR_FLOAT | CVAR_NOSAVE, -10, 10 }, - { "r_pr_parallaxbias", "overriden parallax mapping offset bias", (void *) &pr_parallaxbias, CVAR_FLOAT | CVAR_NOSAVE, -10, 10 }, - { "r_pr_overridespecular", "overrides specular material power and factor values with values from the pr_specularpower and pr_specularfactor cvars; use it to fine-tune DEF tokens", - (void *) &pr_overridespecular, CVAR_BOOL | CVAR_NOSAVE, 0, 1 }, - { "r_pr_specularpower", "overriden specular material power", (void *) &pr_specularpower, CVAR_FLOAT | CVAR_NOSAVE, -10, 1000 }, - { "r_pr_specularfactor", "overriden specular material factor", (void *) &pr_specularfactor, CVAR_FLOAT | CVAR_NOSAVE, -10, 1000 }, - { "r_pr_highpalookups", "enable/disable highpalookups", (void *) &pr_highpalookups, CVAR_BOOL, 0, 1 }, - { "r_pr_artmapping", "enable/disable art mapping", (void *) &pr_artmapping, CVAR_BOOL | CVAR_INVALIDATEART, 0, 1 }, - { "r_pr_overridehud", "overrides hud model parameters with values from the pr_hud* cvars; use it to fine-tune DEF tokens", (void *) &pr_overridehud, CVAR_BOOL | CVAR_NOSAVE, 0, 1 }, - { "r_pr_hudxadd", "overriden HUD xadd; see r_pr_overridehud", (void *) &pr_hudxadd, CVAR_FLOAT | CVAR_NOSAVE, -100, 100 }, - { "r_pr_hudyadd", "overriden HUD yadd; see r_pr_overridehud", (void *) &pr_hudyadd, CVAR_FLOAT | CVAR_NOSAVE, -100, 100 }, - { "r_pr_hudzadd", "overriden HUD zadd; see r_pr_overridehud", (void *) &pr_hudzadd, CVAR_FLOAT | CVAR_NOSAVE, -100, 100 }, - { "r_pr_hudangadd", "overriden HUD angadd; see r_pr_overridehud", (void *) &pr_hudangadd, CVAR_INT | CVAR_NOSAVE, -1024, 1024 }, - { "r_pr_hudfov", "overriden HUD fov; see r_pr_overridehud", (void *) &pr_hudfov, CVAR_INT | CVAR_NOSAVE, 0, 1023 }, - { "r_pr_overridemodelscale", "overrides model scale if non-zero; use it to fine-tune DEF tokens", (void *) &pr_overridemodelscale, CVAR_FLOAT | CVAR_NOSAVE, 0, 500 }, - { "r_pr_ati_fboworkaround", "enable this to workaround an ATI driver bug that causes sprite shadows to be square - you need to restart the renderer for it to take effect", (void *) &pr_ati_fboworkaround, CVAR_BOOL | CVAR_NOSAVE, 0, 1 }, - { "r_pr_ati_nodepthoffset", "enable this to workaround an ATI driver bug that causes sprite drawing to freeze the game on Radeon X1x00 hardware - you need to restart the renderer for it to take effect", (void *) &pr_ati_nodepthoffset, CVAR_BOOL | CVAR_NOSAVE, 0, 1 }, - { "r_pr_nullrender", "disable all draws when enabled, 2: disables updates too", (void *)&pr_nullrender, CVAR_INT | CVAR_NOSAVE, 0, 3 }, -#endif #ifdef __ANDROID__ { "r_models","enable/disable model rendering",(void *) &usemodels, CVAR_BOOL | CVAR_NOSAVE, 0, 1 }, @@ -7930,17 +7676,6 @@ void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) #include "compat.h" -int32_t polymost_drawtilescreen(int32_t tilex, int32_t tiley, int32_t wallnum, int32_t dimen, - int32_t usehitile, uint8_t *loadedhitile) -{ - UNREFERENCED_PARAMETER(tilex); - UNREFERENCED_PARAMETER(tiley); - UNREFERENCED_PARAMETER(wallnum); - UNREFERENCED_PARAMETER(dimen); - UNREFERENCED_PARAMETER(usehitile); - UNREFERENCED_PARAMETER(loadedhitile); - return -1; -} #endif diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index bb886d381..ab441cded 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -15,6 +15,7 @@ #include "cache1d.h" #include "kplib.h" #include "palette.h" +#include "../../glbackend/glbackend.h" #include "vfs.h" @@ -897,7 +898,9 @@ voxmodel_t *voxload(const char *filnam) return vm; } + //Draw voxel model as perfect cubes +// Note: This is a hopeless mess that totally forfeits any chance of using a vertex buffer with its messy coordinate adjustments. :( int32_t polymost_voxdraw(voxmodel_t *m, const uspritetype *tspr) { // float clut[6] = {1.02,1.02,0.94,1.06,0.98,0.98}; @@ -1022,13 +1025,22 @@ int32_t polymost_voxdraw(voxmodel_t *m, const uspritetype *tspr) polymost_usePaletteIndexing(false); polymost_setTexturePosSize({ 0.f, 0.f, 1.f, 1.f }); - glBegin(GL_QUADS); // {{{ + auto data = GLInterface.AllocVertices(m->qcnt * 4); + auto vt = data.second; + int qstart = 0; + int qdone = 0; for (bssize_t i=0, fi=0; iqcnt; i++) { if (i == m->qfacind[fi]) { f = 1 /*clut[fi++]*/; + if (qdone > 0) + { + GLInterface.Draw(DT_QUADS, qstart, qdone * 4); + qstart += qdone * 4; + qdone = 0; + } glColor4f(pc[0]*f, pc[1]*f, pc[2]*f, pc[3]*f); } @@ -1038,26 +1050,22 @@ int32_t polymost_voxdraw(voxmodel_t *m, const uspritetype *tspr) const int32_t yy = vptr[0].y + vptr[2].y; const int32_t zz = vptr[0].z + vptr[2].z; - for (bssize_t j=0; j<4; j++) + for (bssize_t j=0; j<4; j++, vt++) { - vec3f_t fp; #if (VOXBORDWIDTH == 0) - glTexCoord2f(((float)vptr[j].u)*ru + uhack[vptr[j].u!=vptr[0].u], + vt->SetTexCoord(((float)vptr[j].u)*ru + uhack[vptr[j].u!=vptr[0].u], ((float)vptr[j].v)*rv + vhack[vptr[j].v!=vptr[0].v]); #else - glTexCoord2f(((float)vptr[j].u)*ru, ((float)vptr[j].v)*rv); + vt->SetTexCoord(((float)vptr[j].u)*ru, ((float)vptr[j].v)*rv); #endif - fp.x = ((float)vptr[j].x) - phack[xx>vptr[j].x*2] + phack[xxvptr[j].y*2] + phack[yyvptr[j].z*2] + phack[zzx = ((float)vptr[j].x) - phack[xx>vptr[j].x*2] + phack[xxy = ((float)vptr[j].y) - phack[yy>vptr[j].y*2] + phack[yyz = ((float)vptr[j].z) - phack[zz>vptr[j].z*2] + phack[zz