diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 71cb5ca70375629ee06c7943e0c5be881555a0c1..6fda8d735c0d8745110d3673f5abe4609e6a4f34 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -67,8 +67,9 @@ static RGBA_t *textureBuffer = NULL; static size_t textureBufferSize = 0; RGBA_t myPaletteData[256]; -GLint screen_width = 0; // used by Draw2DLine() +GLint screen_width = 0; // used by Draw2DLine() GLint screen_height = 0; +GLint texsize = 512; // Power-of-two screen texture render resolution GLbyte screen_depth = 0; GLint textureformatGL = 0; GLint maximumAnisotropy = 0; @@ -1199,7 +1200,9 @@ static void GLProject(GLfloat objX, GLfloat objY, GLfloat objZ, // -----------------+ void SetModelView(GLint w, GLint h) { -// GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); + GLint maxtexsize = 0; + + //GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) @@ -1207,6 +1210,22 @@ void SetModelView(GLint w, GLint h) screen_width = w; screen_height = h; + texsize = 512; + while (texsize < w || texsize < h) + { + texsize *= 2; // Use a power of two texture, dammit + } + + pglGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize); // Get the maximum supported texture size + if (texsize > maxtexsize && maxtexsize > 0) + { + // The desired screen texture resolution is too big for the player's GPU! + CONS_Alert(CONS_WARNING, "Tried to make a screen texture for a %dx%d game resolution, but your GPU only supports up to %dx%d! Please switch to the software renderer or lower your game resolution.\n", w, h, maxtexsize, maxtexsize); + + // For now, let's just pray that clamping it to the maximum supported size "works" + // There'll be a stretchy "border" artefact, but it's better than failing to make the screen textures + texsize = maxtexsize; + } pglViewport(0, 0, w, h); @@ -3064,7 +3083,6 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) INT32 x, y; float float_x, float_y, float_nextx, float_nexty; float xfix, yfix; - INT32 texsize = 2048; const float blackBack[16] = { @@ -3074,12 +3092,6 @@ EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) 16.0f, -16.0f, 6.0f }; - // Use a power of two texture, dammit - if(screen_width <= 1024) - texsize = 1024; - if(screen_width <= 512) - texsize = 512; - // X/Y stretch fix for all resolutions(!) xfix = (float)(texsize)/((float)((screen_width)/(float)(SCREENVERTS-1))); yfix = (float)(texsize)/((float)((screen_height)/(float)(SCREENVERTS-1))); @@ -3165,15 +3177,8 @@ EXPORT void HWRAPI(FlushScreenTextures) (void) // Create Screen to fade from EXPORT void HWRAPI(StartScreenWipe) (void) { - INT32 texsize = 2048; boolean firstTime = (startScreenWipe == 0); - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - // Create screen texture if (firstTime) pglGenTextures(1, &startScreenWipe); @@ -3196,15 +3201,8 @@ EXPORT void HWRAPI(StartScreenWipe) (void) // Create Screen to fade to EXPORT void HWRAPI(EndScreenWipe)(void) { - INT32 texsize = 2048; boolean firstTime = (endScreenWipe == 0); - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - // Create screen texture if (firstTime) pglGenTextures(1, &endScreenWipe); @@ -3229,7 +3227,6 @@ EXPORT void HWRAPI(EndScreenWipe)(void) EXPORT void HWRAPI(DrawIntermissionBG)(void) { float xfix, yfix; - INT32 texsize = 2048; const float screenVerts[12] = { @@ -3241,11 +3238,6 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void) float fix[8]; - if(screen_width <= 1024) - texsize = 1024; - if(screen_width <= 512) - texsize = 512; - xfix = 1/((float)(texsize)/((float)((screen_width)))); yfix = 1/((float)(texsize)/((float)((screen_height)))); @@ -3276,7 +3268,6 @@ EXPORT void HWRAPI(DrawIntermissionBG)(void) // Do screen fades! EXPORT void HWRAPI(DoScreenWipe)(void) { - INT32 texsize = 2048; float xfix, yfix; INT32 fademaskdownloaded = tex_downloaded; // the fade mask that has been set @@ -3299,12 +3290,6 @@ EXPORT void HWRAPI(DoScreenWipe)(void) 1.0f, 1.0f }; - // Use a power of two texture, dammit - if(screen_width <= 1024) - texsize = 1024; - if(screen_width <= 512) - texsize = 512; - xfix = 1/((float)(texsize)/((float)((screen_width)))); yfix = 1/((float)(texsize)/((float)((screen_height)))); @@ -3367,15 +3352,8 @@ EXPORT void HWRAPI(DoScreenWipe)(void) // Create a texture from the screen. EXPORT void HWRAPI(MakeScreenTexture) (void) { - INT32 texsize = 2048; boolean firstTime = (screentexture == 0); - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - // Create screen texture if (firstTime) pglGenTextures(1, &screentexture); @@ -3397,15 +3375,8 @@ EXPORT void HWRAPI(MakeScreenTexture) (void) EXPORT void HWRAPI(MakeScreenFinalTexture) (void) { - INT32 texsize = 2048; boolean firstTime = (finalScreenTexture == 0); - // Use a power of two texture, dammit - if(screen_width <= 512) - texsize = 512; - else if(screen_width <= 1024) - texsize = 1024; - // Create screen texture if (firstTime) pglGenTextures(1, &finalScreenTexture); @@ -3431,16 +3402,10 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) float origaspect, newaspect; float xoff = 1, yoff = 1; // xoffset and yoffset for the polygon to have black bars around the screen FRGBAFloat clearColour; - INT32 texsize = 2048; float off[12]; float fix[8]; - if(screen_width <= 1024) - texsize = 1024; - if(screen_width <= 512) - texsize = 512; - xfix = 1/((float)(texsize)/((float)((screen_width)))); yfix = 1/((float)(texsize)/((float)((screen_height))));