From 96c0c3197ce810b8f5708d3e72eb5afef425eb7a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 4 Oct 2019 18:12:03 +0200 Subject: [PATCH] - abstracted away more OpenGL calls, in particular all matrix access. --- source/CMakeLists.txt | 1 - source/build/include/baselayer.h | 20 -- source/build/include/build.h | 2 +- source/build/include/glbuild.h | 129 --------- source/build/include/polymost.h | 10 +- source/build/src/2d.cpp | 25 +- source/build/src/animvpx.cpp | 44 +-- source/build/src/baselayer.cpp | 50 ---- source/build/src/common.cpp | 3 +- source/build/src/engine.cpp | 137 +-------- source/build/src/glbuild.cpp | 277 ------------------- source/build/src/mdsprite.cpp | 74 ++--- source/build/src/palette.cpp | 50 ++-- source/build/src/polymost.cpp | 457 +++++-------------------------- source/build/src/sdlayer.cpp | 40 +-- source/build/src/voxmodel.cpp | 17 +- source/glbackend/glbackend.cpp | 103 +++++++ source/glbackend/glbackend.h | 48 +++- 18 files changed, 316 insertions(+), 1171 deletions(-) delete mode 100644 source/build/src/glbuild.cpp diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index a1c3e0125..c335e24f4 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -802,7 +802,6 @@ set (PCH_SOURCES build/src/compat.cpp build/src/defs.cpp build/src/engine.cpp - build/src/glbuild.cpp build/src/glsurface.cpp build/src/hash.cpp build/src/hightile.cpp diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index a61012e1b..b7cb42dc6 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -85,29 +85,9 @@ struct glinfo_t { const char *extensions; float maxanisotropy; - char bgra; - char clamptoedge; - char texcompr; - char texnpot; - char multisample; - char nvmultisamplehint; - char arbfp; - char depthtex; - char shadow; - char fbos; - char rect; - char multitex; - char envcombine; - char vbos; - char vsync; - char sm4; - char occlusionqueries; - char glsl; char debugoutput; char bufferstorage; char sync; - char depthclamp; - char clipcontrol; char dumped; }; diff --git a/source/build/include/build.h b/source/build/include/build.h index 00d8f6c59..84f2a5364 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1124,7 +1124,7 @@ void renderDrawMapView(int32_t dax, int32_t day, int32_t zoome, int16_t ang); void rotatesprite_(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, int8_t dashade, uint8_t dapalnum, int32_t dastat, uint8_t daalpha, uint8_t dablend, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2); -void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col); +void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t col); void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t p); int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) ATTRIBUTE((nonnull(5))); diff --git a/source/build/include/glbuild.h b/source/build/include/glbuild.h index 1826a603b..6a1118cc7 100644 --- a/source/build/include/glbuild.h +++ b/source/build/include/glbuild.h @@ -5,9 +5,6 @@ #ifdef USE_OPENGL #if !defined GEKKO -# define DYNAMIC_GL -# define DYNAMIC_GLU -# define DYNAMIC_GLEXT # define USE_GLEXT #endif @@ -17,133 +14,7 @@ # include #endif -# ifdef _WIN32 -# define PR_CALLBACK __stdcall -# else -# define PR_CALLBACK -# endif -// custom error checking - -extern GLenum BuildGLError; -extern void BuildGLErrorCheck(void); - - -//////// dynamic/static API wrapping //////// - -#if !defined RENDERTYPESDL && defined _WIN32 && defined DYNAMIC_GL -typedef HGLRC (WINAPI * bwglCreateContextProcPtr)(HDC); -extern bwglCreateContextProcPtr bwglCreateContext; -#define wglCreateContext bwglCreateContext -typedef BOOL (WINAPI * bwglDeleteContextProcPtr)(HGLRC); -extern bwglDeleteContextProcPtr bwglDeleteContext; -#define wglDeleteContext bwglDeleteContext -typedef PROC (WINAPI * bwglGetProcAddressProcPtr)(LPCSTR); -extern bwglGetProcAddressProcPtr bwglGetProcAddress; -#define wglGetProcAddress bwglGetProcAddress -typedef BOOL (WINAPI * bwglMakeCurrentProcPtr)(HDC,HGLRC); -extern bwglMakeCurrentProcPtr bwglMakeCurrent; -#define wglMakeCurrent bwglMakeCurrent - -typedef int32_t (WINAPI * bwglChoosePixelFormatProcPtr)(HDC,CONST PIXELFORMATDESCRIPTOR*); -extern bwglChoosePixelFormatProcPtr bwglChoosePixelFormat; -#define wglChoosePixelFormat bwglChoosePixelFormat -typedef int32_t (WINAPI * bwglDescribePixelFormatProcPtr)(HDC,int32_t,UINT,LPPIXELFORMATDESCRIPTOR); -extern bwglDescribePixelFormatProcPtr bwglDescribePixelFormat; -#define wglDescribePixelFormat bwglDescribePixelFormat -typedef int32_t (WINAPI * bwglGetPixelFormatProcPtr)(HDC); -extern bwglGetPixelFormatProcPtr bwglGetPixelFormat; -#define wglGetPixelFormat bwglGetPixelFormat -typedef BOOL (WINAPI * bwglSetPixelFormatProcPtr)(HDC,int32_t,const PIXELFORMATDESCRIPTOR*); -extern bwglSetPixelFormatProcPtr bwglSetPixelFormat; -#define wglSetPixelFormat bwglSetPixelFormat -#endif - -#if defined DYNAMIC_GLU - -// GLU -#if defined __clang__ && defined __APPLE__ -// XXX: OS X 10.9 deprecated GLUtesselator. -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#endif - -typedef void (APIENTRY * bgluTessBeginContourProcPtr)(GLUtesselator* tess); -extern bgluTessBeginContourProcPtr bgluTessBeginContour; -typedef void (APIENTRY * bgluTessBeginPolygonProcPtr)(GLUtesselator* tess, GLvoid* data); -extern bgluTessBeginPolygonProcPtr bgluTessBeginPolygon; -typedef void (APIENTRY * bgluTessCallbackProcPtr)(GLUtesselator* tess, GLenum which, void (PR_CALLBACK CallBackFuncProcPtr)()); -extern bgluTessCallbackProcPtr bgluTessCallback; -typedef void (APIENTRY * bgluTessEndContourProcPtr)(GLUtesselator* tess); -extern bgluTessEndContourProcPtr bgluTessEndContour; -typedef void (APIENTRY * bgluTessEndPolygonProcPtr)(GLUtesselator* tess); -extern bgluTessEndPolygonProcPtr bgluTessEndPolygon; -typedef void (APIENTRY * bgluTessNormalProcPtr)(GLUtesselator* tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ); -extern bgluTessNormalProcPtr bgluTessNormal; -typedef void (APIENTRY * bgluTessPropertyProcPtr)(GLUtesselator* tess, GLenum which, GLdouble data); -extern bgluTessPropertyProcPtr bgluTessProperty; -typedef void (APIENTRY * bgluTessVertexProcPtr)(GLUtesselator* tess, GLdouble *location, GLvoid* data); -extern bgluTessVertexProcPtr bgluTessVertex; -typedef GLUtesselator* (APIENTRY * bgluNewTessProcPtr)(void); -extern bgluNewTessProcPtr bgluNewTess; -typedef void (APIENTRY * bgluDeleteTessProcPtr)(GLUtesselator* tess); -extern bgluDeleteTessProcPtr bgluDeleteTess; - -#if defined __clang__ && defined __APPLE__ -#pragma clang diagnostic pop -#endif - -typedef void (APIENTRY * bgluPerspectiveProcPtr)(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); -extern bgluPerspectiveProcPtr bgluPerspective; - -typedef const GLubyte * (APIENTRY * bgluErrorStringProcPtr)(GLenum error); -extern bgluErrorStringProcPtr bgluErrorString; - -typedef GLint (APIENTRY * bgluProjectProcPtr)(GLdouble objX, GLdouble objY, GLdouble objZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* winX, GLdouble* winY, GLdouble* winZ); -extern bgluProjectProcPtr bgluProject; -typedef GLint (APIENTRY * bgluUnProjectProcPtr)(GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble* objX, GLdouble* objY, GLdouble* objZ); -extern bgluUnProjectProcPtr bgluUnProject; - -#else - -#define bgluTessBeginContour gluTessBeginContour -#define bgluTessBeginPolygon gluTessBeginPolygon -#define bgluTessCallback gluTessCallback -#define bgluTessEndContour gluTessEndContour -#define bgluTessEndPolygon gluTessEndPolygon -#define bgluTessNormal gluTessNormal -#define bgluTessProperty gluTessProperty -#define bgluTessVertex gluTessVertex -#define bgluNewTess gluNewTess -#define bgluDeleteTess gluDeleteTess - -#define bgluPerspective gluPerspective - -#define bgluErrorString gluErrorString - -#define bgluProject gluProject -#define bgluUnProject gluUnProject - -#endif - - -//////// glGenTextures/glDeleteTextures debugging //////// -void texdbg_bglGenTextures(GLsizei n, GLuint *textures, const char *srcfn); -void texdbg_bglDeleteTextures(GLsizei n, const GLuint *textures, const char *srcfn); - -//#define DEBUG_TEXTURE_NAMES - -#if defined DEBUGGINGAIDS && defined DEBUG_TEXTURE_NAMES -# define glGenTextures(numtexs, texnamear) texdbg_bglGenTextures(numtexs, texnamear, __FILE__) -# define glDeleteTextures(numtexs, texnamear) texdbg_bglDeleteTextures(numtexs, texnamear, __FILE__) -#endif - #endif //USE_OPENGL -#if !defined RENDERTYPESDL && defined _WIN32 && defined DYNAMIC_GL -extern char *gldriver; - -int32_t loadwgl(const char *driver); -int32_t unloadwgl(void); -#endif #endif diff --git a/source/build/include/polymost.h b/source/build/include/polymost.h index fb2c98a54..49f43da7b 100644 --- a/source/build/include/polymost.h +++ b/source/build/include/polymost.h @@ -1,7 +1,6 @@ #ifndef polymost_h_ # define polymost_h_ -#ifdef USE_OPENGL #include "baselayer.h" // glinfo #include "glad/glad.h" @@ -148,15 +147,12 @@ static FORCE_INLINE int polymost_is_npotmode(void) { // The glinfo.texnpot check is so we don't have to deal with that case in // gloadtile_art(). - return glinfo.texnpot && + return // r_npotwallmode is NYI for hightiles. We require r_hightile off // because in calc_ypanning(), the repeat would be multiplied by a // factor even if no modified texture were loaded. !usehightile && -#ifdef NEW_MAP_FORMAT - g_loadedMapVersion < 10 && -#endif - r_npotwallmode; + r_npotwallmode; } static inline float polymost_invsqrt_approximation(float x) @@ -293,5 +289,3 @@ extern void polymost_setupglowtexture(int32_t texunits, FHardwareTexture *tex); extern void polymost_setupdetailtexture(int32_t texunits, FHardwareTexture* tex); #endif - -#endif diff --git a/source/build/src/2d.cpp b/source/build/src/2d.cpp index c3c6d6413..c1c5601d7 100644 --- a/source/build/src/2d.cpp +++ b/source/build/src/2d.cpp @@ -9,6 +9,7 @@ #include "build.h" #include "compat.h" #include "baselayer.h" +#include "matrix.h" #include "../../glbackend/glbackend.h" @@ -50,14 +51,14 @@ static void drawlinegl(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t } glViewport(0, 0, xdim, ydim); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, xdim, ydim, 0, -1, 1); + VSMatrix proj(0); + proj.ortho(0, xdim, ydim, 0, -1, 1); + GLInterface.SetMatrix(Matrix_Projection, &proj); gloy1 = -1; - glDisable(GL_ALPHA_TEST); - glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); // When using line antialiasing, this is needed + GLInterface.EnableAlphaTest(false); + GLInterface.EnableDepthTest(false); + GLInterface.EnableBlend(true); // When using line antialiasing, this is needed polymost_useColorOnly(true); glColor4ub(p.r, p.g, p.b, 255); @@ -86,7 +87,7 @@ void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t p) //drawlinepixels(x1, y1, x2, y2, col); } -void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col) +void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t col) { col = palookup[0][col]; @@ -116,13 +117,13 @@ void polymostSet2dView(void) glViewport(0, 0, xdim, ydim); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, xdim, ydim, 0, -1, 1); + VSMatrix proj(0); + proj.ortho(0, xdim, ydim, 0, -1, 1); + GLInterface.SetMatrix(Matrix_Projection, &proj); gloy1 = -1; - glDisable(GL_DEPTH_TEST); - glDisable(GL_BLEND); + GLInterface.EnableDepthTest(false); + GLInterface.EnableBlend(false); #endif } diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index b7d4e86e5..14b4efe7d 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 "matrix.h" #include "../../glbackend/glbackend.h" #undef UNUSED @@ -376,9 +377,6 @@ static const char *fragprog_src = void animvpx_setup_glstate(int32_t animvpx_flags) { -#ifdef USE_GLEXT - if (glinfo.glsl) - { GLint gli; GLuint FSHandle, PHandle; static char logbuf[512]; @@ -409,28 +407,23 @@ void animvpx_setup_glstate(int32_t animvpx_flags) /* Finally, use the program. */ useShaderProgram(PHandle); - } -#endif + ////////// GL STATE ////////// //Force fullscreen (glox1=-1 forces it to restore afterwards) glViewport(0,0,xdim,ydim); glox1 = -1; - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_ModelView, &identity); + GLInterface.SetMatrix(Matrix_Projection, &identity); + GLInterface.SetMatrix(Matrix_Texture0, &identity); // glPushAttrib(GL_ENABLE_BIT); - glDisable(GL_ALPHA_TEST); - glDisable(GL_DEPTH_TEST); - glDisable(GL_BLEND); - glDisable(GL_CULL_FACE); + GLInterface.EnableAlphaTest(false); + GLInterface.EnableDepthTest(false); + GLInterface.EnableBlend(false); + GLInterface.SetCull(Cull_None); texture = GLInterface.NewTexture(); @@ -453,15 +446,8 @@ void animvpx_setup_glstate(int32_t animvpx_flags) void animvpx_restore_glstate(void) { -#ifdef USE_GLEXT - if (glinfo.glsl) - { - useShaderProgram(0); - polymost_resetProgram(); - } -#endif - -// glPopAttrib(); + useShaderProgram(0); + polymost_resetProgram(); delete texture; texture = nullptr; @@ -504,9 +490,6 @@ int32_t animvpx_render_frame(animvpx_codec_ctx *codec, double animvpx_aspect) } #endif - if (!glinfo.glsl) - glColor3f(1.0, 1.0, 1.0); - auto data = GLInterface.AllocVertices(4); auto vt = data.second; @@ -540,9 +523,6 @@ void animvpx_print_stats(const animvpx_codec_ctx *codec) const int32_t *m = codec->maxtimes; int32_t n = codec->numframes; - if (glinfo.glsl) - initprintf("animvpx: GLSL mode\n"); - initprintf("VP8 timing stats (mean, max) [ms] for %d frames:\n" " read and decode frame: %.02f, %d\n" " 3 planes -> packed conversion: %.02f, %d\n" diff --git a/source/build/src/baselayer.cpp b/source/build/src/baselayer.cpp index 9c45e795e..ecea6dcfb 100644 --- a/source/build/src/baselayer.cpp +++ b/source/build/src/baselayer.cpp @@ -212,30 +212,6 @@ struct glinfo_t glinfo = "", // extensions 1.0, // max anisotropy - 0, // brga texture format - 0, // clamp-to-edge support - 0, // texture compression - 0, // non-power-of-two textures - 0, // multisampling - 0, // nvidia multisampling hint - 0, // ARBfp - 0, // depth textures - 0, // shadow comparison - 0, // Frame Buffer Objects - 0, // rectangle textures - 0, // multitexturing - 0, // env_combine - 0, // Vertex Buffer Objects - 0, // VSync support - 0, // Shader Model 4 support - 0, // Occlusion Queries - 0, // GLSL - 0, // Debug Output - 0, // Buffer storage - 0, // Sync - 0, // Depth Clamp - 0, // Clip Control - 0, // GL info dumped }; // Used to register the game's / editor's osdcmd_vidmode() functions here. @@ -342,32 +318,6 @@ int osdcmd_glinfo(osdcmdptr_t UNUSED(parm)) char const *s[] = { "supported", "not supported" }; -#define SUPPORTED(x) (x ? s[0] : s[1]) - - initprintf(" BGRA textures: %s\n", SUPPORTED(glinfo.bgra)); - initprintf(" Non-power-of-2 textures: %s\n", SUPPORTED(glinfo.texnpot)); - initprintf(" Clamp-to-edge: %s\n", SUPPORTED(glinfo.clamptoedge)); - initprintf(" Multi-texturing: %s\n", SUPPORTED(glinfo.multitex)); - initprintf(" Framebuffer objects: %s\n", SUPPORTED(glinfo.fbos)); - initprintf(" Texture compression: %s\n", SUPPORTED(glinfo.texcompr)); - initprintf(" Multi-sampling: %s\n", SUPPORTED(glinfo.multisample)); - initprintf(" NVIDIA multisample hint: %s\n", SUPPORTED(glinfo.nvmultisamplehint)); - initprintf(" ARBfp fragment programs: %s\n", SUPPORTED(glinfo.arbfp)); - initprintf(" Depth textures: %s\n", SUPPORTED(glinfo.depthtex)); - initprintf(" Shadow textures: %s\n", SUPPORTED(glinfo.shadow)); - initprintf(" Rectangle textures: %s\n", SUPPORTED(glinfo.rect)); - initprintf(" env_combine: %s\n", SUPPORTED(glinfo.envcombine)); - initprintf(" Vertex buffer objects: %s\n", SUPPORTED(glinfo.vbos)); - initprintf(" Shader model 4: %s\n", SUPPORTED(glinfo.sm4)); - initprintf(" Occlusion queries: %s\n", SUPPORTED(glinfo.occlusionqueries)); - initprintf(" GLSL: %s\n", SUPPORTED(glinfo.glsl)); - initprintf(" Debug output: %s\n", SUPPORTED(glinfo.debugoutput)); - initprintf(" Buffer storage: %s\n", SUPPORTED(glinfo.bufferstorage)); - initprintf(" Sync: %s\n", SUPPORTED(glinfo.sync)); - initprintf(" Maximum anisotropy: %.1f%s\n", glinfo.maxanisotropy, glinfo.maxanisotropy > 1.0 ? "" : " (no anisotropic filtering)"); - -#undef SUPPORTED - initprintf(" Extensions:\n%s", glinfo.extensions); return OSDCMD_OK; diff --git a/source/build/src/common.cpp b/source/build/src/common.cpp index a9aa1d0fc..49b849035 100644 --- a/source/build/src/common.cpp +++ b/source/build/src/common.cpp @@ -9,6 +9,7 @@ #include "common.h" #include "vfs.h" +#include "../../glbackend/glbackend.h" GrowArray g_defModules; @@ -259,7 +260,7 @@ void COMMON_doclearbackground(int numcols, int height) polymostSet2dView(); glColor4f(0.f, 0.f, 0.f, 0.67f); - glEnable(GL_BLEND); + GLInterface.EnableBlend(true); glRecti(0, 0, xdim, height); glColor4f(0.f, 0.f, 0.f, 1.f); glRecti(0, height-4, xdim, height); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 0df02c01f..48c910b8f 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -30,6 +30,7 @@ # include "hightile.h" # include "mdsprite.h" # include "polymost.h" +#include "../../glbackend/glbackend.h" #endif @@ -874,9 +875,6 @@ void yax_drawrooms(void (*SpriteAnimFunc)(int32_t,int32_t,int32_t,int32_t,int32_ if (videoGetRenderMode() == REND_POLYMER || numyaxbunches==0) { -#ifdef ENGINE_SCREENSHOT_DEBUG - engine_screenshot = 0; -#endif return; } @@ -1001,22 +999,6 @@ void yax_drawrooms(void (*SpriteAnimFunc)(int32_t,int32_t,int32_t,int32_t,int32_ g_nodraw = 0; scansector_collectsprites = 0; - if (editstatus==1 && in3dmode()) - { - if (videoGetRenderMode() == REND_CLASSIC) - { - videoBeginDrawing(); - draw_rainbow_background(); - videoEndDrawing(); - } -#ifdef USE_OPENGL - else - { - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - } -#endif - } - #ifdef USE_OPENGL if (videoGetRenderMode() == REND_POLYMOST) { @@ -6217,15 +6199,6 @@ static void renderDrawSprite(int32_t snum) case REND_POLYMOST: polymost_drawsprite(snum); return; -# ifdef POLYMER - case REND_POLYMER: - glEnable(GL_ALPHA_TEST); - glEnable(GL_BLEND); - polymer_drawsprite(snum); - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - return; -# endif #endif } } @@ -6239,20 +6212,6 @@ static void renderDrawMaskedWall(int16_t damaskwallcnt) //============================================================================= //POLYMOST BEGINS #ifdef USE_OPENGL if (videoGetRenderMode() == REND_POLYMOST) { polymost_drawmaskwall(damaskwallcnt); return; } -# ifdef POLYMER - else if (videoGetRenderMode() == REND_POLYMER) - { - glEnable(GL_ALPHA_TEST); - glEnable(GL_BLEND); - - polymer_drawmaskwall(damaskwallcnt); - - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - - return; - } -#endif #endif //============================================================================= //POLYMOST ENDS @@ -8538,30 +8497,6 @@ int32_t renderDrawRoomsQ16(int32_t daposx, int32_t daposy, int32_t daposz, } } -#ifdef USE_OPENGL -# ifdef POLYMER - if (videoGetRenderMode() == REND_POLYMER) - { -# ifdef YAX_ENABLE - // BEGIN_TWEAK ceiling/floor fake 'TROR' pics, see END_TWEAK in build.c - if (editstatus && showinvisibility) - { - for (i=0; i= MAXSECTORS) @@ -9038,8 +8973,8 @@ killsprite: #ifdef USE_OPENGL if (videoGetRenderMode() == REND_POLYMOST) { - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); + GLInterface.EnableBlend(false); + GLInterface.EnableAlphaTest(true); polymost_setClamp(1+2); if (spritesortcnt < numSprites) @@ -9105,8 +9040,8 @@ killsprite: renderDrawMaskedWall(i); } - glEnable(GL_BLEND); - glEnable(GL_ALPHA_TEST); + GLInterface.EnableBlend(true); + GLInterface.EnableAlphaTest(true); glDepthMask(GL_FALSE); } #endif @@ -11454,7 +11389,6 @@ void neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange, // 1: don't reset walbitmap[] (the bitmap of already dragged vertices) // 2: In the editor, do wall[].cstat |= (1<<14) also for the lastwall(). void dragpoint(int16_t pointhighlight, int32_t dax, int32_t day, uint8_t flags) -#ifdef YAX_ENABLE { int32_t i, numyaxwalls=0; static int16_t yaxwalls[MAXWALLS]; @@ -11546,63 +11480,6 @@ void dragpoint(int16_t pointhighlight, int32_t dax, int32_t day, uint8_t flags) } } } -#else -{ - int16_t cnt, tempshort; - int32_t thelastwall; - - tempshort = pointhighlight; //search points CCW - cnt = MAXWALLS; - - wall[tempshort].x = dax; - wall[tempshort].y = day; - - if (editstatus) - { - editwall[pointhighlight>>3] |= 1<<(pointhighlight&7); - if (linehighlight >= 0 && linehighlight < MAXWALLS) - editwall[linehighlight>>3] |= 1<<(linehighlight&7); - int wn = lastwall(pointhighlight); - editwall[wn>>3] |= 1<<(wn&7); - } - - do - { - if (wall[tempshort].nextwall >= 0) - { - tempshort = wall[wall[tempshort].nextwall].point2; - - wall[tempshort].x = dax; - wall[tempshort].y = day; - editwall[tempshort>>3] |= 1<<(tempshort&7); - } - else - { - tempshort = pointhighlight; //search points CW if not searched all the way around - do - { - thelastwall = lastwall(tempshort); - if (wall[thelastwall].nextwall >= 0) - { - tempshort = wall[thelastwall].nextwall; - wall[tempshort].x = dax; - wall[tempshort].y = day; - editwall[tempshort>>3] |= 1<<(tempshort&7); - } - else - { - break; - } - cnt--; - } - while ((tempshort != pointhighlight) && (cnt > 0)); - break; - } - cnt--; - } - while ((tempshort != pointhighlight) && (cnt > 0)); -} -#endif // // lastwall @@ -13132,8 +13009,8 @@ int32_t videoSetRenderMode(int32_t renderer) #ifdef USE_OPENGL if (bpp == 8) { - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); + GLInterface.EnableBlend(false); + GLInterface.EnableAlphaTest(false); renderer = REND_CLASSIC; } # ifdef POLYMER diff --git a/source/build/src/glbuild.cpp b/source/build/src/glbuild.cpp deleted file mode 100644 index c404c78bd..000000000 --- a/source/build/src/glbuild.cpp +++ /dev/null @@ -1,277 +0,0 @@ -#include "baselayer.h" -#include "compat.h" -#include "glad/glad.h" -#include "glbuild.h" - -#if defined USE_OPENGL - -#ifdef RENDERTYPESDL -# include "sdlayer.h" -#endif - -GLenum BuildGLError; -void BuildGLErrorCheck(void) -{ - volatile GLenum err; - while ((err = glGetError()) != GL_NO_ERROR) - { - BuildGLError = err; // set a watchpoint/breakpoint here - } -} - -#if defined DYNAMIC_GL - -#if !defined RENDERTYPESDL && defined _WIN32 -bwglCreateContextProcPtr bwglCreateContext; -bwglDeleteContextProcPtr bwglDeleteContext; -bwglGetProcAddressProcPtr bwglGetProcAddress; -bwglMakeCurrentProcPtr bwglMakeCurrent; - -bwglChoosePixelFormatProcPtr bwglChoosePixelFormat; -bwglDescribePixelFormatProcPtr bwglDescribePixelFormat; -bwglGetPixelFormatProcPtr bwglGetPixelFormat; -bwglSetPixelFormatProcPtr bwglSetPixelFormat; -#endif - -#endif - -#if defined DYNAMIC_GLU - -// GLU -bgluTessBeginContourProcPtr bgluTessBeginContour; -bgluTessBeginPolygonProcPtr bgluTessBeginPolygon; -bgluTessCallbackProcPtr bgluTessCallback; -bgluTessEndContourProcPtr bgluTessEndContour; -bgluTessEndPolygonProcPtr bgluTessEndPolygon; -bgluTessNormalProcPtr bgluTessNormal; -bgluTessPropertyProcPtr bgluTessProperty; -bgluTessVertexProcPtr bgluTessVertex; -bgluNewTessProcPtr bgluNewTess; -bgluDeleteTessProcPtr bgluDeleteTess; - -bgluPerspectiveProcPtr bgluPerspective; - -bgluErrorStringProcPtr bgluErrorString; - -bgluProjectProcPtr bgluProject; -bgluUnProjectProcPtr bgluUnProject; - -#endif - -#if defined DYNAMIC_GL || defined DYNAMIC_GLEXT || defined DYNAMIC_GLU -# if !defined _WIN32 -# include -# endif -#endif - -#if defined DYNAMIC_GL || defined DYNAMIC_GLEXT - -#if !defined RENDERTYPESDL && defined _WIN32 -static HMODULE hGLDLL; - -char *gldriver = NULL; - -static void *getproc_(const char *s, int32_t *err, int32_t fatal, int32_t extension) -{ - void *t; -#if defined RENDERTYPESDL - UNREFERENCED_PARAMETER(extension); - t = (void *)SDL_GL_GetProcAddress(s); -#elif defined _WIN32 - if (extension) t = (void *)bwglGetProcAddress(s); - else t = (void *)GetProcAddress(hGLDLL,s); -#else -#error Need a dynamic loader for this platform... -#endif - if (!t && fatal) - { - initprintf("Failed to find %s in %s\n", s, gldriver); - *err = 1; - } - return t; -} -#define GETPROC(s) getproc_(s,&err,1,0) - -int32_t loadwgl(const char *driver) -{ - int32_t err=0; - - if (hGLDLL) return 0; - - if (!driver) - { - driver = "opengl32.dll"; - } - - hGLDLL = LoadLibrary(driver); - if (!hGLDLL) - { - initprintf("Failed loading \"%s\"\n", driver); - return -1; - } - - gldriver = Xstrdup(driver); - - bwglCreateContext = (bwglCreateContextProcPtr) GETPROC("wglCreateContext"); - bwglDeleteContext = (bwglDeleteContextProcPtr) GETPROC("wglDeleteContext"); - bwglGetProcAddress = (bwglGetProcAddressProcPtr) GETPROC("wglGetProcAddress"); - bwglMakeCurrent = (bwglMakeCurrentProcPtr) GETPROC("wglMakeCurrent"); - - bwglChoosePixelFormat = (bwglChoosePixelFormatProcPtr) GETPROC("wglChoosePixelFormat"); - bwglDescribePixelFormat = (bwglDescribePixelFormatProcPtr) GETPROC("wglDescribePixelFormat"); - bwglGetPixelFormat = (bwglGetPixelFormatProcPtr) GETPROC("wglGetPixelFormat"); - bwglSetPixelFormat = (bwglSetPixelFormatProcPtr) GETPROC("wglSetPixelFormat"); - - if (err) unloadwgl(); - return err; -} -int32_t unloadwgl(void) -{ - if (!hGLDLL) return 0; - - DO_FREE_AND_NULL(gldriver); - - FreeLibrary(hGLDLL); - hGLDLL = NULL; - - bwglCreateContext = (bwglCreateContextProcPtr) NULL; - bwglDeleteContext = (bwglDeleteContextProcPtr) NULL; - bwglGetProcAddress = (bwglGetProcAddressProcPtr) NULL; - bwglMakeCurrent = (bwglMakeCurrentProcPtr) NULL; - - bwglChoosePixelFormat = (bwglChoosePixelFormatProcPtr) NULL; - bwglDescribePixelFormat = (bwglDescribePixelFormatProcPtr) NULL; - bwglGetPixelFormat = (bwglGetPixelFormatProcPtr) NULL; - bwglSetPixelFormat = (bwglSetPixelFormatProcPtr) NULL; - return 0; -} -#endif - -#endif - -#if defined DYNAMIC_GLU -#if defined _WIN32 -static HMODULE hGLUDLL; -#else -static void *gluhandle = NULL; -#endif - -char *glulibrary = NULL; - -static void *glugetproc_(const char *s, int32_t *err, int32_t fatal) -{ - void *t; -#if defined _WIN32 - t = (void *)GetProcAddress(hGLUDLL,s); -#else - t = (void *)dlsym(gluhandle,s); -#endif - if (!t && fatal) - { - initprintf("Failed to find %s in %s\n", s, glulibrary); - *err = 1; - } - return t; -} -#define GLUGETPROC(s) glugetproc_(s,&err,1) -#define GLUGETPROCSOFT(s) glugetproc_(s,&err,0) -#endif - - - - -//////// glGenTextures/glDeleteTextures debugging //////// -# if defined DEBUGGINGAIDS && defined DEBUG_TEXTURE_NAMES -static uint8_t *texnameused; // bitmap -static uint32_t *texnamefromwhere; // hash of __FILE__ -static uint32_t texnameallocsize; - -// djb3 algorithm -static inline uint32_t texdbg_getcode(const char *s) -{ - uint32_t h = 5381; - int32_t ch; - - while ((ch = *s++) != '\0') - h = ((h << 5) + h) ^ ch; - - return h; -} - -static void texdbg_realloc(uint32_t maxtexname) -{ - uint32_t newsize = texnameallocsize ? texnameallocsize : 64; - - if (maxtexname < texnameallocsize) - return; - - while (maxtexname >= newsize) - newsize <<= 1; -// initprintf("texdebug: new size %u\n", newsize); - - texnameused = Xrealloc(texnameused, newsize>>3); - texnamefromwhere = Xrealloc(texnamefromwhere, newsize*sizeof(uint32_t)); - - Bmemset(texnameused + (texnameallocsize>>3), 0, (newsize-texnameallocsize)>>3); - Bmemset(texnamefromwhere + texnameallocsize, 0, (newsize-texnameallocsize)*sizeof(uint32_t)); - - texnameallocsize = newsize; -} - -#undef bglGenTextures -void texdbg_bglGenTextures(GLsizei n, GLuint *textures, const char *srcfn) -{ - int32_t i; - uint32_t hash = srcfn ? texdbg_getcode(srcfn) : 0; - - for (i=0; i>3]&pow2char[textures[i]&7])) - initprintf("texdebug %x Gen: overwriting used tex name %u from %x\n", hash, textures[i], texnamefromwhere[textures[i]]); - - bglGenTextures(n, textures); - - { - GLuint maxtexname = 0; - - for (i=0; i>3] |= pow2char[textures[i]&7]; - texnamefromwhere[textures[i]] = hash; - } - } -} - -#undef bglDeleteTextures -void texdbg_bglDeleteTextures(GLsizei n, const GLuint *textures, const char *srcfn) -{ - int32_t i; - uint32_t hash = srcfn ? texdbg_getcode(srcfn) : 0; - - for (i=0; i>3]&pow2char[textures[i]&7])==0) - initprintf("texdebug %x Del: deleting unused tex name %u\n", hash, textures[i]); - else if ((texnameused[textures[i]>>3]&pow2char[textures[i]&7]) && - texnamefromwhere[textures[i]] != hash) - initprintf("texdebug %x Del: deleting foreign tex name %u from %x\n", hash, - textures[i], texnamefromwhere[textures[i]]); - } - - bglDeleteTextures(n, textures); - - if (texnameallocsize) - for (i=0; i>3] &= ~pow2char[textures[i]&7]; - texnamefromwhere[textures[i]] = 0; - } -} -# endif // defined DEBUGGINGAIDS - -#endif diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 22743fd9e..8d71fcf17 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -693,13 +693,7 @@ FHardwareTexture *mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t isart = 1; } - if (!glinfo.texnpot) - { - for (siz.x=1; siz.x= 0; j--) - swapchar(&pic[j].r, &pic[j].b); - } - if (pal < (MAXPALOOKUPS - RESERVEDPALS)) m->usesalpha = hasalpha; if ((doalloc & 3) == 1) @@ -845,9 +833,7 @@ FHardwareTexture *mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t *texidx = GLInterface.NewTexture(); } - //gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,xsiz,ysiz,GL_BGRA_EXT,GL_UNSIGNED_BYTE,(char *)fptr); - - int32_t const texfmt = glinfo.bgra ? GL_BGRA : GL_RGBA; + int32_t const texfmt = GL_BGRA; uploadtexture(*texidx, (doalloc&1), siz, texfmt, pic, tsiz, DAMETH_HI | DAMETH_MASK | @@ -2015,8 +2001,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) // glPushAttrib(GL_POLYGON_BIT); if ((grhalfxdown10x >= 0) ^((globalorientation&8) != 0) ^((globalorientation&4) != 0)) glFrontFace(GL_CW); else glFrontFace(GL_CCW); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); + GLInterface.SetCull(Cull_Back); // tinting pc[0] = pc[1] = pc[2] = ((float)numshades - min(max((globalshade * shadescale) + m->shadeoff, 0.f), (float)numshades)) / (float)numshades; @@ -2043,14 +2028,14 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) float al = 0.0; if (alphahackarray[globalpicnum] != 0) al=alphahackarray[globalpicnum] * (1.f/255.f); - glEnable(GL_BLEND); - glEnable(GL_ALPHA_TEST); + GLInterface.EnableBlend(true); + GLInterface.EnableAlphaTest(true); glAlphaFunc(GL_GREATER,al); } else { if ((tspr->cstat&2) || sext->alpha > 0.f || pc[3] < 1.0f) - glEnable(GL_BLEND); //else glDisable(GL_BLEND); + GLInterface.EnableBlend(true); //else GLInterface.EnableBlend(false); } glColor4f(pc[0],pc[1],pc[2],pc[3]); //if (MFLAGS_NOCONV(m)) @@ -2137,8 +2122,9 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) } } - 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); + //Let OpenGL (and perhaps hardware :) handle the matrix rotation + mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; + GLInterface.SetMatrix(Matrix_ModelView, mat); // PLAG: End auto tex = mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,globalpal,surfi); @@ -2147,10 +2133,8 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) //i = mdloadskin((md2model *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,surfi); //hack for testing multiple surfaces per MD3 GLInterface.BindTexture(0, tex); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(xpanning, ypanning, 1.0f); - glMatrixMode(GL_MODELVIEW); + VSMatrix texmat(0); + texmat.translate(xpanning, ypanning, 1.0f); if (!(tspr->extra&TSPR_EXTRA_MDHACK)) { @@ -2171,13 +2155,10 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) if ((int32_t) sk->palette == DETAILPAL && sk->skinnum == tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum && sk->surfnum == surfi) f = sk->param; - glActiveTexture(GL_TEXTURE3); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(xpanning, ypanning, 1.0f); - glScalef(f, f, 1.0f); - glMatrixMode(GL_MODELVIEW); - glActiveTexture(GL_TEXTURE0); + texmat.loadIdentity(); + texmat.translate(xpanning, ypanning, 1.0f); + texmat.scale(f, f, 1.0f); + GLInterface.SetMatrix(Matrix_Texture3, &texmat); } tex = r_glowmapping ? mdloadskin((md2model_t *) m, tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum, GLOWPAL, surfi) : 0; @@ -2187,12 +2168,9 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) polymost_useGlowMapping(true); polymost_setupglowtexture(4, tex); - glActiveTexture(GL_TEXTURE4); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(xpanning, ypanning, 1.0f); - glMatrixMode(GL_MODELVIEW); - glActiveTexture(GL_TEXTURE0); + texmat.loadIdentity(); + texmat.translate(xpanning, ypanning, 1.0f); + GLInterface.SetMatrix(Matrix_Texture4, &texmat); } #endif @@ -2254,15 +2232,13 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) } //------------ - if (m->usesalpha) glDisable(GL_ALPHA_TEST); + if (m->usesalpha) GLInterface.EnableAlphaTest(false); - glDisable(GL_CULL_FACE); -// glPopAttrib(); + GLInterface.SetCull(Cull_None); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_ModelView, &identity); + GLInterface.SetMatrix(Matrix_Texture0, &identity); polymost_setClamp(prevClamp); polymost_usePaletteIndexing(true); diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index cb9e05567..eeaa3cedf 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -50,19 +50,18 @@ static void paletteSetFade(uint8_t offset); #ifdef USE_OPENGL void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f) { - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + auto oldproj = GLInterface.GetMatrix(Matrix_Projection); + auto oldmv = GLInterface.GetMatrix(Matrix_ModelView); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_Projection, &identity); + GLInterface.SetMatrix(Matrix_ModelView, &identity); - glDisable(GL_DEPTH_TEST); - glDisable(GL_ALPHA_TEST); + GLInterface.EnableDepthTest(false); + GLInterface.EnableAlphaTest(false); polymost_setFogEnabled(false); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); + GLInterface.EnableBlend(true); glColor4ub(r, g, b, f); polymost_useColorOnly(true); @@ -75,9 +74,8 @@ void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f) GLInterface.Draw(DT_TRIANGLES, data.first, 3); polymost_useColorOnly(false); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); + GLInterface.SetMatrix(Matrix_Projection, &oldproj); + GLInterface.SetMatrix(Matrix_ModelView, &oldmv); } int32_t tint_blood_r = 0, tint_blood_g = 0, tint_blood_b = 0; @@ -86,19 +84,19 @@ void fullscreen_tint_gl_blood(void) { if (!(tint_blood_r|tint_blood_g|tint_blood_b)) return; - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + auto oldproj = GLInterface.GetMatrix(Matrix_Projection); + auto oldmv = GLInterface.GetMatrix(Matrix_ModelView); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_Projection, &identity); + GLInterface.SetMatrix(Matrix_ModelView, &identity); - glDisable(GL_DEPTH_TEST); - glDisable(GL_ALPHA_TEST); + + GLInterface.EnableDepthTest(false); + GLInterface.EnableAlphaTest(false); polymost_setFogEnabled(false); glBlendFunc(GL_ONE, GL_ONE); - glEnable(GL_BLEND); + GLInterface.EnableBlend(true); polymost_useColorOnly(true); glColor4ub(max(tint_blood_r, 0), max(tint_blood_g, 0), max(tint_blood_b, 0), 255); @@ -121,9 +119,9 @@ void fullscreen_tint_gl_blood(void) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); polymost_useColorOnly(false); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); + GLInterface.SetMatrix(Matrix_Projection, &oldproj); + GLInterface.SetMatrix(Matrix_ModelView, &oldmv); + } #endif @@ -846,8 +844,8 @@ palette_t paletteGetColor(int32_t col) { if (!gammabrightness) { - palette_t const p = { britable[curbrightness][curpalette[col].r], britable[curbrightness][curpalette[col].g], - britable[curbrightness][curpalette[col].b], 0 }; + palette_t const p = { (uint8_t)britable[curbrightness][curpalette[col].r], (uint8_t)britable[curbrightness][curpalette[col].g], + (uint8_t)britable[curbrightness][curpalette[col].b], 0 }; return p; } diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index beb2f38b9..58b45fc97 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -6,8 +6,6 @@ Ken Silverman's official web site: http://www.advsys.net/ken **************************************************************************************************/ -#ifdef USE_OPENGL - #include "build.h" #include "common.h" #include "engine_priv.h" @@ -137,22 +135,10 @@ static GLenum currentActiveTexture = 0; static uint32_t currentTextureID = 0; static GLuint quadVertsID = 0; -static GLuint polymost2BasicShaderProgramID = 0; -static GLint texSamplerLoc = -1; -static GLint fullBrightSamplerLoc = -1; -static GLint projMatrixLoc = -1; -static GLint mvMatrixLoc = -1; -static GLint texOffsetLoc = -1; -static GLint texScaleLoc = -1; -static GLint tintLoc = -1; -static GLint alphaLoc = -1; -static GLint fogRangeLoc = -1; -static GLint fogColorLoc = -1; + #define PALSWAP_TEXTURE_SIZE 2048 int32_t r_useindexedcolortextures = -1; -static GLint tilesheetSize = 0; -static vec2f_t tilesheetHalfTexelSize = { 0.f, 0.f }; static int32_t lastbasepal = -1; static FHardwareTexture *paletteTextureIDs[MAXBASEPALS]; static FHardwareTexture *palswapTextureID = nullptr; @@ -508,10 +494,7 @@ void polymost_resetProgram() polymost_outputGLDebugMessage(3, "polymost_resetProgram()"); - if (r_enablepolymost2) - useShaderProgram(polymost2BasicShaderProgramID); - else - useShaderProgram(polymost1CurrentShaderProgramID); + useShaderProgram(polymost1CurrentShaderProgramID); // ensure that palswapTexture and paletteTexture[curbasepal] is bound GLInterface.BindTexture(1, palswapTextureID); @@ -779,119 +762,11 @@ void useShaderProgram(uint32_t shaderID) // one-time initialization of OpenGL for polymost void polymost_glinit() { - glEnable(GL_TEXTURE_2D); - glHint(GL_FOG_HINT, GL_NICEST); - glFogi(GL_FOG_MODE, (r_usenewshading < 2) ? GL_EXP2 : GL_LINEAR); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glPixelStorei(GL_PACK_ALIGNMENT, 1); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - if (glinfo.depthclamp) - glEnable(GL_DEPTH_CLAMP); - - //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - //glEnable(GL_LINE_SMOOTH); - globalflags |= GLOBAL_NO_GL_TILESHADES; // This re-enables the old fading logic without re-adding the r_usetileshades variable. The entire thing will have to be done on a more abstract level anyway. - -#ifdef USE_GLEXT - if (glmultisample > 0 && glinfo.multisample) - { - if (glinfo.nvmultisamplehint) - glHint(GL_MULTISAMPLE_FILTER_HINT_NV, glnvmultisamplehint ? GL_NICEST:GL_FASTEST); - glEnable(GL_MULTISAMPLE); - } - -#endif - currentTextureID = 0; - - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &tilesheetSize); - tilesheetHalfTexelSize = { 0.5f/tilesheetSize, 0.5f/tilesheetSize }; - vec2_t maxTexDimensions = { tilesheetSize, tilesheetSize }; char allPacked = false; - const char* const POLYMOST2_BASIC_VERTEX_SHADER_CODE = - "#version 110\n\ - \n\ - // input\n\ - attribute vec3 i_vertPos;\n\ - attribute vec2 i_texCoord;\n\ - uniform mat4 u_mvMatrix;\n\ - uniform mat4 u_projMatrix;\n\ - uniform vec2 u_texOffset;\n\ - uniform vec2 u_texScale;\n\ - \n\ - // output\n\ - varying vec2 v_texCoord;\n\ - varying float v_distance;\n\ - \n\ - void main()\n\ - {\n\ - vec4 eyeCoordPosition = u_mvMatrix * vec4(i_vertPos, 1.0);\n\ - gl_Position = u_projMatrix * eyeCoordPosition;\n\ - \n\ - eyeCoordPosition.xyz /= eyeCoordPosition.w;\n\ - \n\ - v_texCoord = i_texCoord * u_texScale + u_texOffset;\n\ - v_distance = eyeCoordPosition.z;\n\ - }\n"; - const char* const POLYMOST2_BASIC_FRAGMENT_SHADER_CODE = - "#version 110\n\ - \n\ - varying vec2 v_texCoord;\n\ - uniform sampler2D s_texture;\n\ - uniform sampler2D s_fullBright;\n\ - \n\ - uniform vec4 u_tint;\n\ - uniform float u_alpha;\n\ - \n\ - varying float v_distance;\n\ - uniform vec2 u_fogRange;\n\ - uniform vec4 u_fogColor;\n\ - \n\ - const float c_zero = 0.0;\n\ - const float c_one = 1.0;\n\ - \n\ - void main()\n\ - {\n\ - vec4 color = texture2D(s_texture, v_texCoord);\n\ - vec4 fullBrightColor = texture2D(s_fullBright, v_texCoord);\n\ - \n\ - float fogFactor = clamp((u_fogRange.y-v_distance)/(u_fogRange.y-u_fogRange.x), c_zero, c_one);\n\ - \n\ - color.rgb = mix(u_fogColor.rgb, color.rgb, fogFactor);\n\ - color.rgb *= u_tint.rgb * u_tint.a * color.a;\n\ - color.rgb = mix(color.rgb, fullBrightColor.rgb, fullBrightColor.a);\n\ - \n\ - color.a *= u_alpha;\n\ - \n\ - gl_FragColor = color;\n\ - }\n"; - - polymost2BasicShaderProgramID = glCreateProgram(); - GLuint polymost2BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, POLYMOST2_BASIC_VERTEX_SHADER_CODE); - GLuint polymost2BasicFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, POLYMOST2_BASIC_FRAGMENT_SHADER_CODE); - glBindAttribLocation(polymost2BasicShaderProgramID, 0, "i_vertPos"); - glBindAttribLocation(polymost2BasicShaderProgramID, 1, "i_texCoord"); - glAttachShader(polymost2BasicShaderProgramID, polymost2BasicVertexShaderID); - glAttachShader(polymost2BasicShaderProgramID, polymost2BasicFragmentShaderID); - glLinkProgram(polymost2BasicShaderProgramID); - - // Get the attribute/uniform locations - texSamplerLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "s_texture"); - fullBrightSamplerLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "s_fullBright"); - projMatrixLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_projMatrix"); - mvMatrixLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_mvMatrix"); - texOffsetLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_texOffset"); - texScaleLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_texScale"); - tintLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_tint"); - alphaLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_alpha"); - fogRangeLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_fogRange"); - fogColorLoc = glGetUniformLocation(polymost2BasicShaderProgramID, "u_fogColor"); - polymost1ExtendedShaderProgramID = glCreateProgram(); GLuint polymost1BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, polymost1Vert); GLuint polymost1ExtendedFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, polymost1Frag); @@ -1192,8 +1067,6 @@ static void resizeglcheck(void) glViewport(windowxy1.x-(fovcorrect/2), ydim-(windowxy2.y+1), ourxdimen+fovcorrect, windowxy2.y-windowxy1.y+1); - glMatrixMode(GL_PROJECTION); - float m[4][4]; Bmemset(m,0,sizeof(m)); @@ -1213,10 +1086,9 @@ static void resizeglcheck(void) m[2][2] = (farclip + nearclip) / (farclip - nearclip); m[2][3] = 1.f; m[3][2] = -(2.f * farclip * nearclip) / (farclip - nearclip); - glLoadMatrixf(&m[0][0]); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + GLInterface.SetMatrix(Matrix_Projection, &m[0][0]); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_ModelView, &identity); if (!nofog) polymost_setFogEnabled(true); } @@ -1388,7 +1260,6 @@ static void gloadtile_art_indexed(int32_t dapic, int32_t dameth, pthtyp *pth, in char npoty = 0; //POGOTODO: if !glinfo.texnpot, then we could allocate a texture of the pow2 size, and then populate the subportion using buffersubdata func - //if (!glinfo.texnpot) if (waloff[dapic]) { @@ -1431,18 +1302,10 @@ void gloadtile_art(int32_t dapic, int32_t dapal, int32_t tintpalnum, int32_t das char npoty = 0; { - if (!glinfo.texnpot) - { - for (siz.x = 1; siz.x < tsiz.x; siz.x += siz.x) { } - for (siz.y = 1; siz.y < tsiz.y; siz.y += siz.y) { } - } + if ((tsiz.x|tsiz.y) == 0) + siz.x = siz.y = 1; else - { - if ((tsiz.x|tsiz.y) == 0) - siz.x = siz.y = 1; - else - siz = tsiz; - } + siz = tsiz; coltype *pic = (coltype *)Xmalloc(siz.x*siz.y*sizeof(coltype)); @@ -1589,19 +1452,12 @@ void gloadtile_art(int32_t dapic, int32_t dapal, int32_t tintpalnum, int32_t das if (!doalloc) { vec2_t pthSiz2 = pth->siz; - if (!glinfo.texnpot) - { - for (pthSiz2.x = 1; pthSiz2.x < pth->siz.x; pthSiz2.x += pthSiz2.x) { } - for (pthSiz2.y = 1; pthSiz2.y < pth->siz.y; pthSiz2.y += pthSiz2.y) { } - } + if ((pthSiz2.x|pthSiz2.y) == 0) + pthSiz2.x = pthSiz2.y = 1; else - { - if ((pthSiz2.x|pthSiz2.y) == 0) - pthSiz2.x = pthSiz2.y = 1; - else - pthSiz2 = pth->siz; - } - if (siz.x > pthSiz2.x || + pthSiz2 = pth->siz; + + if (siz.x > pthSiz2.x || siz.y > pthSiz2.y) { //POGO: grow our texture to hold the tile data @@ -1712,13 +1568,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp isart = 1; } - if (!glinfo.texnpot) - { - for (siz.x=1; siz.x>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y) @@ -1880,18 +1724,12 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp fixtransparency(pic,tsiz,siz,dameth); - int32_t const texfmt = glinfo.bgra ? GL_BGRA : GL_RGBA; + int32_t const texfmt = GL_BGRA; if (!doalloc) { vec2_t pthSiz2 = pth->siz; - if (!glinfo.texnpot) - { - for (pthSiz2.x=1; pthSiz2.x < pth->siz.x; pthSiz2.x+=pthSiz2.x) { } - for (pthSiz2.y=1; pthSiz2.y < pth->siz.y; pthSiz2.y+=pthSiz2.y) { } - } - else - pthSiz2 = tsiz; + pthSiz2 = tsiz; if (siz.x > pthSiz2.x || siz.y > pthSiz2.y) { @@ -2185,11 +2023,6 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 if (!pth) { - if (editstatus) - { - Bsprintf(ptempbuf, "pth==NULL! (bad pal?) pic=%d pal=%d", globalpicnum, globalpal); - polymost_printext256(8,8, editorcolors[15],editorcolors[5], ptempbuf, 0); - } return; } @@ -2235,13 +2068,13 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 } + VSMatrix texmat; // texture scale by parkar request if (pth->hicr && !drawingskybox && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) { - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glScalef(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); - glMatrixMode(GL_MODELVIEW); + texmat.loadIdentity(); + texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); + GLInterface.SetMatrix(Matrix_ModelView, &texmat); } #ifdef USE_GLEXT @@ -2265,18 +2098,15 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 polymost_useDetailMapping(true); polymost_setupdetailtexture(3, detailpth->glpic); - glActiveTexture(GL_TEXTURE3); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); + texmat.loadIdentity(); if (pth->hicr && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) - glScalef(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); + texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); if ((detailpth->hicr->scale.x != 1.0f) || (detailpth->hicr->scale.y != 1.0f)) - glScalef(detailpth->hicr->scale.x, detailpth->hicr->scale.y, 1.0f); + texmat.scale(detailpth->hicr->scale.x, detailpth->hicr->scale.y, 1.0f); - glMatrixMode(GL_MODELVIEW); - glActiveTexture(GL_TEXTURE0); + GLInterface.SetMatrix(Matrix_Texture3, &texmat); } } @@ -2294,7 +2124,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 } } - if (glinfo.texnpot && r_npotwallmode == 2 && (method & DAMETH_WALL) != 0) + if (r_npotwallmode == 2 && (method & DAMETH_WALL) != 0) { int32_t size = tilesiz[globalpicnum].y; int32_t size2; @@ -2323,13 +2153,6 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 vec2_t tsiz2 = tsiz; - if (!glinfo.texnpot) - { - for (tsiz2.x = 1; tsiz2.x < tsiz.x; tsiz2.x += tsiz2.x) - ; /* do nothing */ - for (tsiz2.y = 1; tsiz2.y < tsiz.y; tsiz2.y += tsiz2.y) - ; /* do nothing */ - } if (method & DAMETH_MASKPROPS || fullbright_pass == 2) { @@ -2548,9 +2371,8 @@ do #endif if (pth->hicr) { - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_Texture3, &identity); } if (videoGetRenderMode() != REND_POLYMOST) @@ -2975,38 +2797,6 @@ skip: ; if ((vsp[ni].tag == 0) || (n1.y <= vsp[i].cy[1]+DOMOST_OFFSET)) k -= 3; if ((vsp[ni].tag == 1) || (n1.y >= vsp[i].fy[1]-DOMOST_OFFSET)) k += 3; -#if 0 - //POGO: This GL1 debug code draws a green line that represents the new line, and the current VSP floor & ceil as red and blue respectively. - // To enable this, ensure that in polymost_drawrooms() that you are clearing the stencil buffer and color buffer. - // Additionally, disable any calls to glColor4f in polymost_drawpoly and disable culling triangles with area==0/removing duplicate points - // If you don't want any lines showing up from mirrors/skyboxes, be sure to disable them as well. - glEnable(GL_STENCIL_TEST); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, 0xFF); - glDisable(GL_DEPTH_TEST); - polymost_useColorOnly(true); - glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - - glColor4f(0.f, 1.f, 0.f, 1.f); - vec2f_t nline[3] = {{dx0, n0.y}, {dx1, n1.y}, {dx0, n0.y}}; - polymost_drawpoly(nline, 3, domostpolymethod); - - glColor4f(1.f, 0.f, 0.f, 1.f); - vec2f_t floor[3] = {{vsp[i].x, vsp[i].fy[0]}, {vsp[ni].x, vsp[i].fy[1]}, {vsp[i].x, vsp[i].fy[0]}}; - polymost_drawpoly(floor, 3, domostpolymethod); - - glColor4f(0.f, 0.f, 1.f, 1.f); - vec2f_t ceil[3] = {{vsp[i].x, vsp[i].cy[0]}, {vsp[ni].x, vsp[i].cy[1]}, {vsp[i].x, vsp[i].cy[0]}}; - polymost_drawpoly(ceil, 3, domostpolymethod); - - glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - polymost_useColorOnly(false); - glEnable(GL_DEPTH_TEST); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc(GL_EQUAL, 0, 0xFF); - glColor4f(1.f, 1.f, 1.f, 1.f); -#endif - if (!dir) { switch (k) @@ -3220,33 +3010,6 @@ skip: ; if ((vsp[i].ctag == vsp[ni].ctag) && (vsp[i].ftag == vsp[ni].ftag)) { MERGE_NODES(i, ni); -#if 0 - //POGO: This GL1 debug code draws the resulting merged VSP segment with floor and ceiling bounds lines as yellow and cyan respectively - // To enable this, ensure that in polymost_drawrooms() that you are clearing the stencil buffer and color buffer. - // Additionally, disable any calls to glColor4f in polymost_drawpoly and disable culling triangles with area==0 - // If you don't want any lines showing up from mirrors/skyboxes, be sure to disable them as well. - glEnable(GL_STENCIL_TEST); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, 0xFF); - glDisable(GL_DEPTH_TEST); - polymost_useColorOnly(true); - glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - - glColor4f(1.f, 1.f, 0.f, 1.f); - vec2f_t dfloor[3] = {{vsp[i].x, vsp[i].fy[0]}, {vsp[vsp[i].n].x, vsp[i].fy[1]}, {vsp[i].x, vsp[i].fy[0]}}; - polymost_drawpoly(dfloor, 3, domostpolymethod); - - glColor4f(0.f, 1.f, 1.f, 1.f); - vec2f_t dceil[3] = {{vsp[i].x, vsp[i].cy[0]}, {vsp[vsp[i].n].x, vsp[i].cy[1]}, {vsp[i].x, vsp[i].cy[0]}}; - polymost_drawpoly(dceil, 3, domostpolymethod); - - glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - polymost_useColorOnly(false); - glEnable(GL_DEPTH_TEST); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc(GL_EQUAL, 0, 0xFF); - glColor4f(1.f, 1.f, 1.f, 1.f); -#endif continue; } if (vsp[ni].x - vsp[i].x < DOMOST_OFFSET) @@ -3835,7 +3598,7 @@ static void polymost_internal_nonparallaxed(vec2f_t n0, vec2f_t n1, float ryp0, domostpolymethod = DAMETH_BACKFACECULL; //Back-face culling if (domostpolymethod & DAMETH_MASKPROPS) - glEnable(GL_BLEND); + GLInterface.EnableBlend(true); polymost_domost(x0, y0, x1, y1); //flor } @@ -3845,13 +3608,13 @@ static void polymost_internal_nonparallaxed(vec2f_t n0, vec2f_t n1, float ryp0, domostpolymethod = DAMETH_BACKFACECULL; //Back-face culling if (domostpolymethod & DAMETH_MASKPROPS) - glEnable(GL_BLEND); + GLInterface.EnableBlend(true); polymost_domost(x1, y1, x0, y0); //ceil } if (domostpolymethod & DAMETH_MASKPROPS) - glDisable(GL_BLEND); + GLInterface.EnableBlend(false); domostpolymethod = DAMETH_NOMASK; } @@ -3876,7 +3639,7 @@ static void calc_ypanning(int32_t refposz, float ryp0, float ryp1, t *= (float)tilesiz[globalpicnum].y / i; i = tilesiz[globalpicnum].y; } - else if (!(glinfo.texnpot && r_npotwallmode == 2) && dopancor) + else if (!(r_npotwallmode == 2) && dopancor) { // Carry out panning "correction" to make it look like classic in some // cases, but failing in the general case. @@ -5495,20 +5258,14 @@ void polymost_drawrooms() videoBeginDrawing(); frameoffset = frameplace + windowxy1.y*bytesperline + windowxy1.x; -#ifdef YAX_ENABLE - if (numyaxbunches==0) -#endif - if (editstatus) - glClear(GL_COLOR_BUFFER_BIT); - #ifdef YAX_ENABLE if (yax_polymostclearzbuffer) #endif glClear(GL_DEPTH_BUFFER_BIT); - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glEnable(GL_DEPTH_TEST); + GLInterface.EnableBlend(false); + GLInterface.EnableAlphaTest(false); + GLInterface.EnableDepthTest(true); glDepthFunc(GL_ALWAYS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS // glDepthRange(0.0, 1.0); //<- this is more widely supported than glPolygonOffset @@ -6032,25 +5789,21 @@ void polymost_prepareMirror(int32_t dax, int32_t day, int32_t daz, fix16_t daang grhalfxdown10x = grhalfxdown10; //POGO: write the mirror region to the stencil buffer to allow showing mirrors & skyboxes at the same time - glEnable(GL_STENCIL_TEST); - glClear(GL_STENCIL_BUFFER_BIT); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, 0xFF); - glDisable(GL_ALPHA_TEST); - glDisable(GL_DEPTH_TEST); + GLInterface.EnableStencilWrite(1); + GLInterface.EnableAlphaTest(false); + GLInterface.EnableDepthTest(false); polymost_drawmaskwallinternal(mirrorWall); - glEnable(GL_ALPHA_TEST); - glEnable(GL_DEPTH_TEST); + GLInterface.EnableAlphaTest(true); + GLInterface.EnableDepthTest(true); //POGO: render only to the mirror region - glStencilFunc(GL_EQUAL, 1, 0xFF); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + GLInterface.EnableStencilTest(1); } void polymost_completeMirror() { polymost_outputGLDebugMessage(3, "polymost_completeMirror()"); - glDisable(GL_STENCIL_TEST); + GLInterface.DisableStencil(); } typedef struct @@ -6915,7 +6668,6 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, if (videoGetRenderMode() < REND_POLYMER) { - glMatrixMode(GL_PROJECTION); Bmemset(m, 0, sizeof(m)); if ((dastat&(RS_AUTO|RS_NOCLIP)) == RS_AUTO) @@ -6941,20 +6693,19 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, m[2][2] = 1.0001f; m[3][2] = 1-m[2][2]; } - - glLoadMatrixf(&m[0][0]); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + + GLInterface.SetMatrix(Matrix_Projection, &m[0][0]); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_ModelView, &identity); } if (hud->flags & HUDFLAG_NODEPTH) - glDisable(GL_DEPTH_TEST); + GLInterface.EnableDepthTest(false); else { static int32_t onumframes = 0; - glEnable(GL_DEPTH_TEST); + GLInterface.EnableDepthTest(true); if (onumframes != numframes) { @@ -6970,40 +6721,7 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, if (videoGetRenderMode() == REND_POLYMOST) polymost_mddraw(&tspr); -# ifdef POLYMER - else - { - int32_t fov; - tspriteptr[maxspritesonscreen] = &tspr; - - glEnable(GL_ALPHA_TEST); - glEnable(GL_BLEND); - - spriteext[tspr.owner].roll = a; - spriteext[tspr.owner].offset.z = z; - - fov = hud->fov; - - if (fov == -1) - fov = pr_fov; - - if (pr_overridehud) - fov = pr_hudfov; - - polymer_setaspect(fov); - - polymer_drawsprite(maxspritesonscreen); - - polymer_setaspect(pr_fov); - - spriteext[tspr.owner].offset.z = 0; - spriteext[tspr.owner].roll = 0; - - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - } -# endif if (!nofog) polymost_setFogEnabled(true); gvrcorrection = ogvrcorrection; @@ -7033,9 +6751,9 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 sx, sy, z, a, picnum, dashade, dapalnum, dastat, daalpha, dablend, cx1, cy1, cx2, cy2, uniqid); glViewport(0,0,xdim,ydim); glox1 = -1; //Force fullscreen (glox1=-1 forces it to restore) - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - + auto oldproj = GLInterface.GetMatrix(Matrix_Projection); + auto oldmv = GLInterface.GetMatrix(Matrix_ModelView); + globvis = 0; globvis2 = 0; polymost_setClamp(1+2); @@ -7079,27 +6797,18 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 m[1][1] = fxdim / fydim; m[2][2] = 1.0001f; m[3][2] = 1 - m[2][2]; - - glLoadMatrixf(&m[0][0]); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glDisable(GL_DEPTH_TEST); - -#if defined(POLYMER) -# ifdef USE_GLEXT - const int32_t olddetailmapping = r_detailmapping, oldglowmapping = r_glowmapping; -# endif - const int32_t oldnormalmapping = pr_normalmapping; -#endif + + GLInterface.SetMatrix(Matrix_Projection, &m[0][0]); + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_ModelView, &identity); + GLInterface.EnableDepthTest(false); int32_t method = DAMETH_CLAMPED; //Use OpenGL clamping - dorotatesprite never repeats if (!(dastat & RS_NOMASK)) { - glEnable(GL_ALPHA_TEST); - glEnable(GL_BLEND); + GLInterface.EnableAlphaTest(true); + GLInterface.EnableBlend(true); if (dastat & RS_TRANS1) method |= (dastat & RS_TRANS2) ? DAMETH_TRANS2 : DAMETH_TRANS1; @@ -7108,24 +6817,12 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 } else { - glDisable(GL_ALPHA_TEST); - glDisable(GL_BLEND); + GLInterface.EnableAlphaTest(false); + GLInterface.EnableBlend(false); } handle_blend(!!(dastat & RS_TRANS1), dablend, !!(dastat & RS_TRANS2)); -#ifdef POLYMER - if (videoGetRenderMode() == REND_POLYMER) - { - pr_normalmapping = 0; - polymer_inb4rotatesprite(picnum, dapalnum, dashade, method); - polymost_resetVertexPointers(); -# ifdef USE_GLEXT - r_detailmapping = 0; - r_glowmapping = 0; -# endif - } -#endif drawpoly_alpha = daalpha * (1.0f / 255.0f); drawpoly_blend = dablend; @@ -7265,24 +6962,12 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 if (!nofog) polymost_setFogEnabled(true); } - glDisable(GL_ALPHA_TEST); - glDisable(GL_BLEND); + GLInterface.EnableAlphaTest(false); + GLInterface.EnableBlend(false); polymost_setClamp(0); -#ifdef POLYMER - if (videoGetRenderMode() == REND_POLYMER) - { -# ifdef USE_GLEXT - r_detailmapping = olddetailmapping; - r_glowmapping = oldglowmapping; -# endif - polymer_postrotatesprite(); - pr_normalmapping = oldnormalmapping; - } -#endif - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); + GLInterface.SetMatrix(Matrix_Projection, &oldproj); + GLInterface.SetMatrix(Matrix_ModelView, &oldmv); globalpicnum = ogpicnum; globalshade = ogshade; @@ -7490,7 +7175,7 @@ void polymost_fillpolygon(int32_t npoints) } if (gloy1 != -1) polymostSet2dView(); //disables blending, texturing, and depth testing - glEnable(GL_ALPHA_TEST); + GLInterface.EnableAlphaTest(true); pthtyp const * const pth = our_texcache_fetch(DAMETH_NOMASK | (videoGetRenderMode() == REND_POLYMOST && r_useindexedcolortextures ? PTH_INDEXED : 0)); if (pth) @@ -7509,12 +7194,12 @@ void polymost_fillpolygon(int32_t npoints) handle_blend(maskprops > DAMETH_MASK, 0, maskprops == DAMETH_TRANS2); if (maskprops > DAMETH_MASK) { - glEnable(GL_BLEND); + GLInterface.EnableBlend(true); glColor4f(f, f, f, float_trans(maskprops, 0)); } else { - glDisable(GL_BLEND); + GLInterface.EnableBlend(false); glColor3f(f, f, f); } @@ -7608,7 +7293,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba polymostSet2dView(); // disables blending, texturing, and depth testing - glDisable(GL_ALPHA_TEST); + GLInterface.EnableAlphaTest(false); glDepthMask(GL_FALSE); // disable writing to the z-buffer // glPushAttrib(GL_POLYGON_BIT|GL_ENABLE_BIT); @@ -7635,7 +7320,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba GLInterface.Draw(DT_TRIANGLE_FAN, data.first, 4); } - glEnable(GL_BLEND); + GLInterface.EnableBlend(true); glColor4ub(p.r,p.g,p.b,255); vec2f_t const tc = { fontsize ? (4.f / 256.f) : (8.f / 256.f), @@ -7837,7 +7522,7 @@ void polymost_initosdfuncs(void) (void*)& r_usenewshading, CVAR_INT | CVAR_FUNCPTR, 0, 4}, { "r_yshearing", "enable/disable y-shearing", (void*) &r_yshearing, CVAR_BOOL, 0, 1 }, { "r_flatsky", "enable/disable flat skies", (void*)& r_flatsky, CVAR_BOOL, 0, 1 }, -#endif + }; for (i=0; iSetTextureFilterMode(gltexfiltermode, glanisotropy); } -#endif // defined USE_OPENGL // // setvideomode() -- set SDL video mode diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index cd64ae0a9..8c6f10cad 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1092,8 +1092,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) else glFrontFace(GL_CCW); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); + GLInterface.SetCull(Cull_Back); float pc[4]; @@ -1108,7 +1107,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) handle_blend(!!(tspr->cstat & 2), tspr->blend, !!(tspr->cstat & 512)); if (!(tspr->cstat & 2) || spriteext[tspr->owner].alpha > 0.f || pc[3] < 1.0f) - glEnable(GL_BLEND); // else glDisable(GL_BLEND); + GLInterface.EnableBlend(true); // else GLInterface.EnableBlend(false); } else pc[3] = 1.f; //------------ @@ -1126,10 +1125,10 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) mat[13] -= (m->piv.x*mat[1] + m->piv.y*mat[5] + zoff*mat[9]); mat[14] -= (m->piv.x*mat[2] + m->piv.y*mat[6] + zoff*mat[10]); // - glMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation + //Let OpenGL (and perhaps hardware :) handle the matrix rotation mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; - glLoadMatrixf(mat); + GLInterface.SetMatrix(Matrix_ModelView, mat); const float ru = 1.f/((float)m->mytexx); const float rv = 1.f/((float)m->mytexy); @@ -1192,15 +1191,15 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) GLInterface.Draw(DT_QUADS, qstart, qdone * 4); polymost_setClamp(prevClamp); //------------ - glDisable(GL_CULL_FACE); -// glPopAttrib(); + GLInterface.SetCull(Cull_None); + if (shadowHack) { glDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS // glDepthRange(0.0, 0.99999); } - glLoadIdentity(); - + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_ModelView, &identity); return 1; } #endif diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index e2140aa1c..930e2bcc2 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -14,6 +14,30 @@ void GLInstance::Init() } } +void GLInstance::InitGLState(int fogmode, int multisample) +{ + glShadeModel(GL_SMOOTH); // GL_FLAT + glClearColor(0, 0, 0, 1.0); // Black Background + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glDisable(GL_DITHER); + glEnable(GL_TEXTURE_2D); + glHint(GL_FOG_HINT, GL_NICEST); + glFogi(GL_FOG_MODE, (fogmode < 2) ? GL_EXP2 : GL_LINEAR); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glEnable(GL_DEPTH_CLAMP); + + if (multisample > 0 ) + { + glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); + glEnable(GL_MULTISAMPLE); + } + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); +} + void GLInstance::Deinit() { if (mSamplers) delete mSamplers; @@ -93,3 +117,82 @@ void GLInstance::UnbindAllTextures() UnbindTexture(texunit); } } + +void GLInstance::EnableBlend(bool on) +{ + if (on) glEnable (GL_BLEND); + else glDisable (GL_BLEND); +} + +void GLInstance::EnableAlphaTest(bool on) +{ + if (on) glEnable (GL_ALPHA_TEST); + else glDisable (GL_ALPHA_TEST); +} + +void GLInstance::EnableDepthTest(bool on) +{ + if (on) glEnable (GL_DEPTH_TEST); + else glDisable (GL_DEPTH_TEST); +} + +void GLInstance::SetMatrix(int num, const VSMatrix *mat) +{ + matrices[num] = *mat; + switch(num) + { + case Matrix_Projection: + glMatrixMode(GL_PROJECTION); + break; + + case Matrix_ModelView: + glMatrixMode(GL_MODELVIEW); + break; + + default: + glActiveTexture(GL_TEXTURE0 + num - Matrix_Texture0); + glMatrixMode(GL_TEXTURE); + break; + } + glLoadMatrixf(mat->get()); + glMatrixMode(GL_MODELVIEW); + if (num > Matrix_Texture0) glActiveTexture(GL_TEXTURE0); +} + +void GLInstance::EnableStencilWrite(int value) +{ + glEnable(GL_STENCIL_TEST); + glClear(GL_STENCIL_BUFFER_BIT); + glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); + glStencilFunc(GL_ALWAYS, value, 0xFF); +} + +void GLInstance::EnableStencilTest(int value) +{ + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_EQUAL, value, 0xFF); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); +} + +void GLInstance::DisableStencil() +{ + glDisable(GL_STENCIL_TEST); +} + +void GLInstance::SetCull(int type) +{ + if (type == Cull_None) + { + glDisable(GL_CULL_FACE); + } + else if (type == Cull_Front) + { + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + } + else if (type == Cull_Back) + { + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + } +} diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 3894e158d..eba433950 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -5,6 +5,7 @@ #include #include "gl_samplers.h" #include "gl_hwtexture.h" +#include "matrix.h" class FSamplerManager; @@ -45,6 +46,28 @@ enum EDrawType DT_LINES }; +enum EMatrixType +{ + Matrix_Projection, + Matrix_ModelView, + Matrix_Texture0, + Matrix_Texture1, + Matrix_Texture2, + Matrix_Texture3, + Matrix_Texture4, + Matrix_Texture5, + Matrix_Texture6, + Matrix_Texture7, + NUMMATRICES +}; + +enum ECull +{ + Cull_None, + Cull_Front, + Cull_Back +}; + class GLInstance { enum @@ -56,12 +79,17 @@ class GLInstance unsigned int LastBoundTextures[MAX_TEXTURES]; unsigned TextureHandleCache[THCACHESIZE]; int currentindex = THCACHESIZE; + int maxTextureSize; + + VSMatrix matrices[NUMMATRICES]; public: FSamplerManager *mSamplers; void Init(); + void InitGLState(int fogmode, int multisample); + void Deinit(); static int GetTexDimension(int value) @@ -78,7 +106,23 @@ public: void BindTexture(int texunit, FHardwareTexture *texid, int sampler = NoSampler); void UnbindTexture(int texunit); void UnbindAllTextures(); - + void EnableBlend(bool on); + void EnableAlphaTest(bool on); + void EnableDepthTest(bool on); + const VSMatrix &GetMatrix(int num) + { + return matrices[num]; + } + void SetMatrix(int num, const VSMatrix *mat ); + void SetMatrix(int num, const float *mat) + { + SetMatrix(num, reinterpret_cast(mat)); + } + void SetCull(int type); + + void EnableStencilWrite(int value); + void EnableStencilTest(int value); + void DisableStencil(); }; -extern GLInstance GLInterface; \ No newline at end of file +extern GLInstance GLInterface;