From f96844b2620654892de5f73b46c5775288076552 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 29 May 2017 21:28:36 +0100 Subject: [PATCH 1/3] Fix screenshots taken in OpenGL with 1366x768 being messed up This is based on GZDoom's own fix for the same issue, had to add support for glPixelStorei first though --- src/hardware/r_opengl/r_opengl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 3a0bf7054..a3c47df89 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -244,6 +244,7 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) #define pglMaterialfv glMaterialfv /* Raster functions */ +#define pglPixelStorei glPixelStorei #define pglReadPixels glReadPixels /* Texture mapping */ @@ -365,6 +366,8 @@ typedef void (APIENTRY * PFNglMaterialfv) (GLint face, GLenum pname, GLfloat *pa static PFNglMaterialfv pglMaterialfv; /* Raster functions */ +typedef void (APIENTRY * PFNglPixelStorei) (GLenum pname, GLint param); +static PFNglPixelStorei pglPixelStorei; typedef void (APIENTRY * PFNglReadPixels) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); static PFNglReadPixels pglReadPixels; @@ -494,6 +497,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglLightModelfv , glLightModelfv) GETOPENGLFUNC(pglMaterialfv , glMaterialfv) + GETOPENGLFUNC(pglPixelStorei , glPixelStorei) GETOPENGLFUNC(pglReadPixels , glReadPixels) GETOPENGLFUNC(pglTexEnvi , glTexEnvi) @@ -897,7 +901,9 @@ EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, GLubyte*top = (GLvoid*)dst_data, *bottom = top + dst_stride * (height - 1); GLubyte *row = malloc(dst_stride); if (!row) return; + pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, dst_data); + pglPixelStorei(GL_UNPACK_ALIGNMENT, 1); for(i = 0; i < height/2; i++) { memcpy(row, top, dst_stride); @@ -913,7 +919,9 @@ EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 j; GLubyte *image = malloc(width*height*3*sizeof (*image)); if (!image) return; + pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, image); + pglPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (i = height-1; i >= 0; i--) { for (j = 0; j < width; j++) From 6be7693ecb4ecd4136c3b3434f94ab292f167e2b Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Mon, 29 May 2017 22:52:51 -0400 Subject: [PATCH 2/3] OpenGL: Load the GLU and OpenGL 1.3 multitexturing functions during runtime --- src/hardware/r_opengl/r_opengl.c | 27 +++++---------------------- src/sdl/ogl_sdl.c | 2 -- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index a3c47df89..92e5592e3 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -263,15 +263,8 @@ FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) /* texture mapping */ //GL_EXT_copy_texture #ifndef KOS_GL_COMPATIBILITY #define pglCopyTexImage2D glCopyTexImage2D +#endif -/* GLU functions */ -#define pgluBuild2DMipmaps gluBuild2DMipmaps -#endif -#ifndef MINI_GL_COMPATIBILITY -/* 1.3 functions for multitexturing */ -#define pglActiveTexture glActiveTexture -#define pglMultiTexCoord2f glMultiTexCoord2f -#endif #else //!STATIC_OPENGL /* 1.0 functions */ @@ -394,7 +387,7 @@ static PFNglBindTexture pglBindTexture; /* texture mapping */ //GL_EXT_copy_texture typedef void (APIENTRY * PFNglCopyTexImage2D) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); static PFNglCopyTexImage2D pglCopyTexImage2D; - +#endif /* GLU functions */ typedef GLint (APIENTRY * PFNgluBuild2DMipmaps) (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); static PFNgluBuild2DMipmaps pgluBuild2DMipmaps; @@ -406,7 +399,6 @@ static PFNglActiveTexture pglActiveTexture; typedef void (APIENTRY *PFNglMultiTexCoord2f) (GLenum, GLfloat, GLfloat); static PFNglMultiTexCoord2f pglMultiTexCoord2f; #endif -#endif #ifndef MINI_GL_COMPATIBILITY /* 1.2 Parms */ @@ -523,17 +515,13 @@ boolean SetupGLfunc(void) // This has to be done after the context is created so the version number can be obtained boolean SetupGLFunc13(void) { +#ifdef MINI_GL_COMPATIBILITY + return false; +#else const GLubyte *version = pglGetString(GL_VERSION); int glmajor, glminor; gl13 = false; -#ifdef MINI_GL_COMPATIBILITY - return false; -#else -#ifdef STATIC_OPENGL - gl13 = true; -#else - // Parse the GL version if (version != NULL) { @@ -572,9 +560,6 @@ boolean SetupGLFunc13(void) } else DBG_Printf("GL_ARB_multitexture support: disabled\n"); -#undef GETOPENGLFUNC - -#endif return true; #endif } @@ -1823,13 +1808,11 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) min_filter = GL_NEAREST; #endif } -#ifndef STATIC_OPENGL if (!pgluBuild2DMipmaps) { MipMap = GL_FALSE; min_filter = GL_LINEAR; } -#endif Flush(); //??? if we want to change filter mode by texture, remove this break; diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 21afd831d..cd7ced7ca 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -71,7 +71,6 @@ INT32 oglflags = 0; void *GLUhandle = NULL; SDL_GLContext sdlglcontext = 0; -#ifndef STATIC_OPENGL void *GetGLFunc(const char *proc) { if (strncmp(proc, "glu", 3) == 0) @@ -83,7 +82,6 @@ void *GetGLFunc(const char *proc) } return SDL_GL_GetProcAddress(proc); } -#endif boolean LoadGL(void) { From 6847a89bc2043d536263e98b41d96207ba976242 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Mon, 29 May 2017 23:04:03 -0400 Subject: [PATCH 3/3] OpenGL: check for 1.3+ or 2.0+, not just 1.3/2.X to 4.X --- src/hardware/r_opengl/r_opengl.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 92e5592e3..e6ff83e89 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -528,18 +528,10 @@ boolean SetupGLFunc13(void) if (sscanf((const char*)version, "%d.%d", &glmajor, &glminor) == 2) { // Look, we gotta prepare for the inevitable arrival of GL 2.0 code... - switch (glmajor) - { - case 1: - if (glminor == 3) gl13 = true; - break; - case 2: - case 3: - case 4: - gl13 = true; - default: - break; - } + if (glmajor == 1 && glminor >= 3) + gl13 = true; + else if (glmajor > 1) + gl13 = true; } }