[gl] OpenGL_[state|preferred_state] -> gpu_[state|preferred_state]

This commit is contained in:
Edu García 2024-05-08 17:49:20 +01:00
parent 7c362288ad
commit 061d9ec37b
2 changed files with 162 additions and 159 deletions

View File

@ -57,6 +57,9 @@ bool UseWBuffer = false;
ubyte Renderer_initted = 0;
// Generic GPU data
rendering_state gpu_state;
renderer_preferred_state gpu_preferred_state = {0, 1, 1.5};
int gpu_last_frame_polys_drawn = 0;
int gpu_last_frame_verts_processed = 0;
int gpu_last_uploaded = 0;

View File

@ -148,10 +148,10 @@ ushort *opengl_packed_Upload_data = NULL;
ushort *opengl_packed_Translate_table = NULL;
ushort *opengl_packed_4444_translate_table = NULL;
rendering_state OpenGL_state;
extern rendering_state gpu_state;
static float Alpha_multiplier = 1.0f;
renderer_preferred_state OpenGL_preferred_state = {0, 1, 1.5};
extern renderer_preferred_state gpu_preferred_state;
// These structs are for drawing with OpenGL vertex arrays
// Useful for fast indexing
@ -345,14 +345,14 @@ int opengl_InitCache(void) {
void opengl_SetDefaults() {
mprintf((0, "Setting states\n"));
OpenGL_state.cur_color = 0x00FFFFFF;
OpenGL_state.cur_bilinear_state = -1;
OpenGL_state.cur_zbuffer_state = -1;
OpenGL_state.cur_texture_quality = -1;
OpenGL_state.cur_light_state = LS_GOURAUD;
OpenGL_state.cur_color_model = CM_MONO;
OpenGL_state.cur_bilinear_state = -1;
OpenGL_state.cur_alpha_type = AT_TEXTURE;
gpu_state.cur_color = 0x00FFFFFF;
gpu_state.cur_bilinear_state = -1;
gpu_state.cur_zbuffer_state = -1;
gpu_state.cur_texture_quality = -1;
gpu_state.cur_light_state = LS_GOURAUD;
gpu_state.cur_color_model = CM_MONO;
gpu_state.cur_bilinear_state = -1;
gpu_state.cur_alpha_type = AT_TEXTURE;
// Enable some states
dglAlphaFunc(GL_GREATER, 0);
@ -369,7 +369,7 @@ void opengl_SetDefaults() {
rend_SetColorModel(CM_RGB);
rend_SetZBufferState(1);
rend_SetZValues(0, 3000);
rend_SetGammaValue(OpenGL_preferred_state.gamma);
rend_SetGammaValue(gpu_preferred_state.gamma);
OpenGL_last_bound[0] = 9999999;
OpenGL_last_bound[1] = 9999999;
Last_texel_unit_set = -1;
@ -386,7 +386,7 @@ void opengl_SetDefaults() {
dglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
dglHint(GL_FOG_HINT, GL_NICEST);
dglEnable(GL_SCISSOR_TEST);
dglScissor(0, 0, OpenGL_state.screen_width, OpenGL_state.screen_height);
dglScissor(0, 0, gpu_state.screen_width, gpu_state.screen_height);
dglDisable(GL_SCISSOR_TEST);
dglDepthRange(0.0f, 1.0f);
@ -435,15 +435,15 @@ int opengl_Setup(HDC glhdc) {
/*if (!WindowGL)
{
if (OpenGL_preferred_state.bit_depth==32)
if (gpu_preferred_state.bit_depth==32)
{
pfd.cColorBits = 32;
pfd.cDepthBits = 32;
}
else
{
pfd.cColorBits = OpenGL_preferred_state.bit_depth;
pfd.cDepthBits =OpenGL_preferred_state.bit_depth;
pfd.cColorBits = gpu_preferred_state.bit_depth;
pfd.cDepthBits =gpu_preferred_state.bit_depth;
}
pfd.cColorBits = 16;
@ -686,7 +686,7 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
mprintf((0, "Setting up opengl mode!\n"));
if (pref_state) {
OpenGL_preferred_state = *pref_state;
gpu_preferred_state = *pref_state;
}
if (app != NULL) {
@ -712,9 +712,9 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
devmode.dmSize = sizeof(devmode);
devmode.dmBitsPerPel = 16;
// devmode.dmBitsPerPel=OpenGL_preferred_state.bit_depth;
devmode.dmPelsWidth = OpenGL_preferred_state.width;
devmode.dmPelsHeight = OpenGL_preferred_state.height;
// devmode.dmBitsPerPel=gpu_preferred_state.bit_depth;
devmode.dmPelsWidth = gpu_preferred_state.width;
devmode.dmPelsHeight = gpu_preferred_state.height;
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
#ifdef CHANGE_RESOLUTION_IN_FULLSCREEN
@ -738,17 +738,17 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
opengl_Close();
return 0;
} else {
OpenGL_preferred_state.bit_depth = 16;
OpenGL_preferred_state.width = 640;
OpenGL_preferred_state.height = 480;
gpu_preferred_state.bit_depth = 16;
gpu_preferred_state.width = 640;
gpu_preferred_state.height = 480;
}
} else {
mprintf((0, "Setdisplaymode to %d x %d (%d bits) is successful!\n", OpenGL_preferred_state.width,
OpenGL_preferred_state.height, OpenGL_preferred_state.bit_depth));
mprintf((0, "Setdisplaymode to %d x %d (%d bits) is successful!\n", gpu_preferred_state.width,
gpu_preferred_state.height, gpu_preferred_state.bit_depth));
}
}
memset(&OpenGL_state, 0, sizeof(rendering_state));
memset(&gpu_state, 0, sizeof(rendering_state));
// These values are set here - samir
if (app != NULL) {
@ -771,17 +771,17 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
windowX = topLeft.x;
windowY = topLeft.y;
} else {
SetWindowPos(hOpenGLWnd, HWND_TOPMOST, 0, 0, OpenGL_preferred_state.width, OpenGL_preferred_state.height,
SetWindowPos(hOpenGLWnd, HWND_TOPMOST, 0, 0, gpu_preferred_state.width, gpu_preferred_state.height,
SWP_FRAMECHANGED);
width = OpenGL_preferred_state.width;
height = OpenGL_preferred_state.height;
width = gpu_preferred_state.width;
height = gpu_preferred_state.height;
RECT rect;
GetWindowRect((HWND)hOpenGLWnd, &rect);
mprintf((0, "rect=%d %d %d %d\n", rect.top, rect.right, rect.bottom, rect.left));
}
OpenGL_state.screen_width = width;
OpenGL_state.screen_height = height;
gpu_state.screen_width = width;
gpu_state.screen_height = height;
if (!opengl_Setup(hOpenGLDC)) {
opengl_Close();
@ -796,20 +796,20 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
* LINUX OPENGL
***********************************************************
*/
// Setup OpenGL_state.screen_width & OpenGL_state.screen_height & width & height
width = OpenGL_preferred_state.width;
height = OpenGL_preferred_state.height;
// Setup gpu_state.screen_width & gpu_state.screen_height & width & height
width = gpu_preferred_state.width;
height = gpu_preferred_state.height;
if (!opengl_Setup(app, &width, &height)) {
opengl_Close();
return 0;
}
memset(&OpenGL_state, 0, sizeof(rendering_state));
OpenGL_state.screen_width = width;
OpenGL_state.screen_height = height;
memset(&gpu_state, 0, sizeof(rendering_state));
gpu_state.screen_width = width;
gpu_state.screen_height = height;
#else
// Setup OpenGL_state.screen_width & OpenGL_state.screen_height & width & height
// Setup gpu_state.screen_width & gpu_state.screen_height & width & height
#endif
// Get some info
@ -966,7 +966,7 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
CHECK_ERROR(4)
OpenGL_state.initted = 1;
gpu_state.initted = 1;
mprintf((0, "OpenGL initialization at %d x %d was successful.\n", width, height));
@ -1059,7 +1059,7 @@ void opengl_Close() {
#endif
// mod_FreeModule (OpenGLDLLHandle);
OpenGL_state.initted = 0;
gpu_state.initted = 0;
}
// Takes our 16bit format and converts it into the memory scheme that OpenGL wants
@ -1331,7 +1331,7 @@ void opengl_MakeWrapTypeCurrent(int handle, int map_type, int tn) {
if (tn == 1)
dest_wrap = WT_CLAMP;
else
dest_wrap = OpenGL_state.cur_wrap_type;
dest_wrap = gpu_state.cur_wrap_type;
if (map_type == MAP_TYPE_LIGHTMAP)
uwrap = GET_WRAP_STATE(OpenGL_lightmap_states[handle]);
@ -1350,11 +1350,11 @@ void opengl_MakeWrapTypeCurrent(int handle, int map_type, int tn) {
OpenGL_sets_this_frame[1]++;
if (OpenGL_state.cur_wrap_type == WT_CLAMP) {
if (gpu_state.cur_wrap_type == WT_CLAMP) {
dglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
dglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
} else if (OpenGL_state.cur_wrap_type == WT_WRAP_V) {
} else if (gpu_state.cur_wrap_type == WT_WRAP_V) {
dglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
dglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
} else {
@ -1381,8 +1381,8 @@ void opengl_MakeFilterTypeCurrent(int handle, int map_type, int tn) {
dest_state = 1;
} else {
magf = GET_FILTER_STATE(OpenGL_bitmap_states[handle]);
dest_state = OpenGL_preferred_state.filtering;
if (!OpenGL_state.cur_bilinear_state)
dest_state = gpu_preferred_state.filtering;
if (!gpu_state.cur_bilinear_state)
dest_state = 0;
}
@ -1427,7 +1427,7 @@ void opengl_MakeFilterTypeCurrent(int handle, int map_type, int tn) {
// returns the alpha that we should use
float opengl_GetAlphaMultiplier(void) {
switch (OpenGL_state.cur_alpha_type) {
switch (gpu_state.cur_alpha_type) {
case AT_ALWAYS:
case AT_TEXTURE:
case AT_VERTEX:
@ -1444,7 +1444,7 @@ float opengl_GetAlphaMultiplier(void) {
case AT_LIGHTMAP_BLEND_SATURATE:
case AT_SATURATE_TEXTURE:
case AT_SATURATE_CONSTANT_VERTEX:
return OpenGL_state.cur_alpha / 255.0;
return gpu_state.cur_alpha / 255.0;
default:
// Int3(); // no type defined,get jason
return 0;
@ -1498,10 +1498,10 @@ void opengl_DrawMultitexturePolygon3D(int handle, g3Point **p, int nv, int map_t
ASSERT(nv < 100);
if (OpenGL_state.cur_light_state == LS_NONE) {
fr = GR_COLOR_RED(OpenGL_state.cur_color);
fg = GR_COLOR_GREEN(OpenGL_state.cur_color);
fb = GR_COLOR_BLUE(OpenGL_state.cur_color);
if (gpu_state.cur_light_state == LS_NONE) {
fr = GR_COLOR_RED(gpu_state.cur_color);
fg = GR_COLOR_GREEN(gpu_state.cur_color);
fb = GR_COLOR_BLUE(gpu_state.cur_color);
}
alpha = Alpha_multiplier * gpu_Alpha_factor;
@ -1516,13 +1516,13 @@ void opengl_DrawMultitexturePolygon3D(int handle, g3Point **p, int nv, int map_t
pnt = p[i];
ASSERT(pnt->p3_flags & PF_ORIGPOINT);
if (OpenGL_state.cur_alpha_type & ATF_VERTEX)
if (gpu_state.cur_alpha_type & ATF_VERTEX)
alpha = pnt->p3_a * Alpha_multiplier * gpu_Alpha_factor;
// If we have a lighting model, apply the correct lighting!
if (OpenGL_state.cur_light_state != LS_NONE) {
if (gpu_state.cur_light_state != LS_NONE) {
// Do lighting based on intesity (MONO) or colored (RGB)
if (OpenGL_state.cur_color_model == CM_MONO) {
if (gpu_state.cur_color_model == CM_MONO) {
colorp->r = pnt->p3_l;
colorp->g = pnt->p3_l;
colorp->b = pnt->p3_l;
@ -1602,9 +1602,9 @@ void opengl_DrawFlatPolygon3D(g3Point **p, int nv) {
float alpha = Alpha_multiplier * gpu_Alpha_factor;
fr = GR_COLOR_RED(OpenGL_state.cur_color);
fg = GR_COLOR_GREEN(OpenGL_state.cur_color);
fb = GR_COLOR_BLUE(OpenGL_state.cur_color);
fr = GR_COLOR_RED(gpu_state.cur_color);
fg = GR_COLOR_GREEN(gpu_state.cur_color);
fb = GR_COLOR_BLUE(gpu_state.cur_color);
fr /= 255.0;
fg /= 255.0;
fb /= 255.0;
@ -1615,13 +1615,13 @@ void opengl_DrawFlatPolygon3D(g3Point **p, int nv) {
g3Point *pnt = p[i];
ASSERT(pnt->p3_flags & PF_ORIGPOINT);
if (OpenGL_state.cur_alpha_type & ATF_VERTEX)
if (gpu_state.cur_alpha_type & ATF_VERTEX)
alpha = pnt->p3_a * Alpha_multiplier * gpu_Alpha_factor;
// If we have a lighting model, apply the correct lighting!
if (OpenGL_state.cur_light_state != LS_NONE) {
if (gpu_state.cur_light_state != LS_NONE) {
// Do lighting based on intesity (MONO) or colored (RGB)
if (OpenGL_state.cur_color_model == CM_MONO)
if (gpu_state.cur_color_model == CM_MONO)
dglColor4f(pnt->p3_l, pnt->p3_l, pnt->p3_l, alpha);
else {
dglColor4f(pnt->p3_r, pnt->p3_g, pnt->p3_b, alpha);
@ -1650,7 +1650,7 @@ void rend_SetGammaValue(float val) {
// if( WindowGL )
// return;
OpenGL_preferred_state.gamma = val;
gpu_preferred_state.gamma = val;
mprintf((0, "Setting gamma to %f\n", val));
#if defined(WIN32)
@ -1872,7 +1872,7 @@ void rend_DrawPolygon3D(int handle, g3Point **p, int nv, int map_type) {
g3_RefreshTransforms(false);
if (OpenGL_state.cur_texture_quality == 0) {
if (gpu_state.cur_texture_quality == 0) {
opengl_DrawFlatPolygon3D(p, nv);
return;
}
@ -1882,10 +1882,10 @@ void rend_DrawPolygon3D(int handle, g3Point **p, int nv, int map_type) {
return;
}
if (OpenGL_state.cur_light_state == LS_FLAT_GOURAUD) {
fr = GR_COLOR_RED(OpenGL_state.cur_color) / 255.0;
fg = GR_COLOR_GREEN(OpenGL_state.cur_color) / 255.0;
fb = GR_COLOR_BLUE(OpenGL_state.cur_color) / 255.0;
if (gpu_state.cur_light_state == LS_FLAT_GOURAUD) {
fr = GR_COLOR_RED(gpu_state.cur_color) / 255.0;
fg = GR_COLOR_GREEN(gpu_state.cur_color) / 255.0;
fb = GR_COLOR_BLUE(gpu_state.cur_color) / 255.0;
}
if (UseMultitexture) {
@ -1930,8 +1930,8 @@ void rend_DrawPolygon3D(int handle, g3Point **p, int nv, int map_type) {
vector tempv = pnt->p3_vecPreRot - View_position;
vector testPt = tempv * Unscaled_matrix;
float screenX = pnt->p3_sx + OpenGL_state.clip_x1;
float screenY = pnt->p3_sy + OpenGL_state.clip_y1;
float screenX = pnt->p3_sx + gpu_state.clip_x1;
float screenY = pnt->p3_sy + gpu_state.clip_y1;
// normalize
float oOW = 1.0f / view[3];
@ -1943,20 +1943,20 @@ void rend_DrawPolygon3D(int handle, g3Point **p, int nv, int map_type) {
}
////////////////////////////////////////////
if (OpenGL_state.cur_alpha_type & ATF_VERTEX) {
if (gpu_state.cur_alpha_type & ATF_VERTEX) {
alpha = pnt->p3_a * Alpha_multiplier * gpu_Alpha_factor;
}
// If we have a lighting model, apply the correct lighting!
if (OpenGL_state.cur_light_state != LS_NONE) {
if (OpenGL_state.cur_light_state == LS_FLAT_GOURAUD) {
if (gpu_state.cur_light_state != LS_NONE) {
if (gpu_state.cur_light_state == LS_FLAT_GOURAUD) {
colorp->r = fr;
colorp->g = fg;
colorp->b = fb;
colorp->a = alpha;
} else {
// Do lighting based on intesity (MONO) or colored (RGB)
if (OpenGL_state.cur_color_model == CM_MONO) {
if (gpu_state.cur_color_model == CM_MONO) {
colorp->r = pnt->p3_l;
colorp->g = pnt->p3_l;
colorp->b = pnt->p3_l;
@ -2043,15 +2043,15 @@ void rend_DrawPolygon2D(int handle, g3Point **p, int nv) {
opengl_SetMultitextureBlendMode(false);
}
int xAdd = OpenGL_state.clip_x1;
int yAdd = OpenGL_state.clip_y1;
int xAdd = gpu_state.clip_x1;
int yAdd = gpu_state.clip_y1;
float fr, fg, fb;
if (OpenGL_state.cur_light_state == LS_FLAT_GOURAUD || OpenGL_state.cur_texture_quality == 0) {
if (gpu_state.cur_light_state == LS_FLAT_GOURAUD || gpu_state.cur_texture_quality == 0) {
float scale = 1.0f / 255.0f;
fr = GR_COLOR_RED(OpenGL_state.cur_color) * scale;
fg = GR_COLOR_GREEN(OpenGL_state.cur_color) * scale;
fb = GR_COLOR_BLUE(OpenGL_state.cur_color) * scale;
fr = GR_COLOR_RED(gpu_state.cur_color) * scale;
fg = GR_COLOR_GREEN(gpu_state.cur_color) * scale;
fb = GR_COLOR_BLUE(gpu_state.cur_color) * scale;
}
// make sure our bitmap is ready to be drawn
@ -2070,21 +2070,21 @@ void rend_DrawPolygon2D(int handle, g3Point **p, int nv) {
for (i = 0; i < nv; ++i, ++vertp, ++texp, ++colorp) {
g3Point *pnt = p[i];
if (OpenGL_state.cur_alpha_type & ATF_VERTEX) {
if (gpu_state.cur_alpha_type & ATF_VERTEX) {
// the alpha should come from the vertex
alpha = pnt->p3_a * Alpha_multiplier * gpu_Alpha_factor;
}
// If we have a lighting model, apply the correct lighting!
if (OpenGL_state.cur_light_state == LS_FLAT_GOURAUD || OpenGL_state.cur_texture_quality == 0) {
if (gpu_state.cur_light_state == LS_FLAT_GOURAUD || gpu_state.cur_texture_quality == 0) {
// pull the color from the constant color data
colorp->r = fr;
colorp->g = fg;
colorp->b = fb;
colorp->a = alpha;
} else if (OpenGL_state.cur_light_state != LS_NONE) {
} else if (gpu_state.cur_light_state != LS_NONE) {
// Do lighting based on intensity (MONO) or colored (RGB)
if (OpenGL_state.cur_color_model == CM_MONO) {
if (gpu_state.cur_color_model == CM_MONO) {
colorp->r = pnt->p3_l;
colorp->g = pnt->p3_l;
colorp->b = pnt->p3_l;
@ -2115,7 +2115,7 @@ void rend_DrawPolygon2D(int handle, g3Point **p, int nv) {
}
// And draw!
if (OpenGL_state.cur_texture_quality == 0) {
if (gpu_state.cur_texture_quality == 0) {
// force disable textures
dglDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
@ -2123,7 +2123,7 @@ void rend_DrawPolygon2D(int handle, g3Point **p, int nv) {
// draw the data in the arrays
dglDrawArrays(GL_POLYGON, 0, nv);
if (OpenGL_state.cur_texture_quality == 0) {
if (gpu_state.cur_texture_quality == 0) {
// re-enable textures
dglEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
@ -2136,14 +2136,14 @@ void rend_DrawPolygon2D(int handle, g3Point **p, int nv) {
#endif // DEDICATED_ONLY
void rend_SetFlatColor(ddgr_color color) { OpenGL_state.cur_color = color; }
void rend_SetFlatColor(ddgr_color color) { gpu_state.cur_color = color; }
// Sets the fog state to TRUE or FALSE
void rend_SetFogState(sbyte state) {
if (state == OpenGL_state.cur_fog_state)
if (state == gpu_state.cur_fog_state)
return;
OpenGL_state.cur_fog_state = state;
gpu_state.cur_fog_state = state;
if (state == 1) {
dglEnable(GL_FOG);
} else {
@ -2157,8 +2157,8 @@ void rend_SetFogBorders(float nearz, float farz) {
float fogStart = nearz;
float fogEnd = farz;
OpenGL_state.cur_fog_start = fogStart;
OpenGL_state.cur_fog_end = fogEnd;
gpu_state.cur_fog_start = fogStart;
gpu_state.cur_fog_end = fogEnd;
dglFogi(GL_FOG_MODE, GL_LINEAR);
dglFogf(GL_FOG_START, fogStart);
@ -2171,7 +2171,7 @@ void rend_SetRendererType(renderer_type state) {
}
void rend_SetLighting(light_state state) {
if (state == OpenGL_state.cur_light_state)
if (state == gpu_state.cur_light_state)
return; // No redundant state setting
#if (defined(_USE_OGL_ACTIVE_TEXTURES))
if (UseMultitexture && Last_texel_unit_set != 0) {
@ -2185,16 +2185,16 @@ void rend_SetLighting(light_state state) {
switch (state) {
case LS_NONE:
dglShadeModel(GL_SMOOTH);
OpenGL_state.cur_light_state = LS_NONE;
gpu_state.cur_light_state = LS_NONE;
break;
case LS_FLAT_GOURAUD:
dglShadeModel(GL_SMOOTH);
OpenGL_state.cur_light_state = LS_FLAT_GOURAUD;
gpu_state.cur_light_state = LS_FLAT_GOURAUD;
break;
case LS_GOURAUD:
case LS_PHONG:
dglShadeModel(GL_SMOOTH);
OpenGL_state.cur_light_state = LS_GOURAUD;
gpu_state.cur_light_state = LS_GOURAUD;
break;
default:
Int3();
@ -2207,10 +2207,10 @@ void rend_SetLighting(light_state state) {
void rend_SetColorModel(color_model state) {
switch (state) {
case CM_MONO:
OpenGL_state.cur_color_model = CM_MONO;
gpu_state.cur_color_model = CM_MONO;
break;
case CM_RGB:
OpenGL_state.cur_color_model = CM_RGB;
gpu_state.cur_color_model = CM_RGB;
break;
default:
Int3();
@ -2219,7 +2219,7 @@ void rend_SetColorModel(color_model state) {
}
void rend_SetTextureType(texture_type state) {
if (state == OpenGL_state.cur_texture_type)
if (state == gpu_state.cur_texture_type)
return; // No redundant state setting
#if (defined(_USE_OGL_ACTIVE_TEXTURES))
if (UseMultitexture && Last_texel_unit_set != 0) {
@ -2232,14 +2232,14 @@ void rend_SetTextureType(texture_type state) {
switch (state) {
case TT_FLAT:
dglDisable(GL_TEXTURE_2D);
OpenGL_state.cur_texture_quality = 0;
gpu_state.cur_texture_quality = 0;
break;
case TT_LINEAR:
case TT_LINEAR_SPECIAL:
case TT_PERSPECTIVE:
case TT_PERSPECTIVE_SPECIAL:
dglEnable(GL_TEXTURE_2D);
OpenGL_state.cur_texture_quality = 2;
gpu_state.cur_texture_quality = 2;
break;
default:
Int3(); // huh? Get Jason
@ -2247,17 +2247,17 @@ void rend_SetTextureType(texture_type state) {
}
CHECK_ERROR(12)
OpenGL_state.cur_texture_type = state;
gpu_state.cur_texture_type = state;
}
void rend_StartFrame(int x1, int y1, int x2, int y2, int clear_flags) {
if (clear_flags & RF_CLEAR_ZBUFFER) {
dglClear(GL_DEPTH_BUFFER_BIT);
}
OpenGL_state.clip_x1 = x1;
OpenGL_state.clip_y1 = y1;
OpenGL_state.clip_x2 = x2;
OpenGL_state.clip_y2 = y2;
gpu_state.clip_x1 = x1;
gpu_state.clip_y1 = y1;
gpu_state.clip_x2 = x2;
gpu_state.clip_y2 = y2;
}
#ifdef __CHECK_FOR_TOO_SLOW_RENDERING__
@ -2403,16 +2403,16 @@ void rend_SetSoftwareParameters(float aspect, int width, int height, int pitch,
// Sets the state of bilinear filtering for our textures
void rend_SetFiltering(sbyte state) {
OpenGL_state.cur_bilinear_state = state;
gpu_state.cur_bilinear_state = state;
}
// Sets the state of z-buffering to on or off
void rend_SetZBufferState(sbyte state) {
if (state == OpenGL_state.cur_zbuffer_state)
if (state == gpu_state.cur_zbuffer_state)
return; // No redundant state setting
OpenGL_sets_this_frame[5]++;
OpenGL_state.cur_zbuffer_state = state;
gpu_state.cur_zbuffer_state = state;
// mprintf ((0,"OPENGL: Setting zbuffer state to %d.\n",state));
@ -2428,8 +2428,8 @@ void rend_SetZBufferState(sbyte state) {
// Sets the near and far planes for z buffer
void rend_SetZValues(float nearz, float farz) {
OpenGL_state.cur_near_z = nearz;
OpenGL_state.cur_far_z = farz;
gpu_state.cur_near_z = nearz;
gpu_state.cur_far_z = farz;
// mprintf ((0,"OPENGL:Setting depth range to %f - %f\n",nearz,farz));
// JEFF: glDepthRange must take parameters [0,1]
@ -2472,18 +2472,18 @@ void rend_FillRect(ddgr_color color, int x1, int y1, int x2, int y2) {
int width = x2 - x1;
int height = y2 - y1;
x1 += OpenGL_state.clip_x1;
y1 += OpenGL_state.clip_y1;
x1 += gpu_state.clip_x1;
y1 += gpu_state.clip_y1;
dglEnable(GL_SCISSOR_TEST);
dglScissor(x1, OpenGL_state.screen_height - (height + y1), width, height);
dglScissor(x1, gpu_state.screen_height - (height + y1), width, height);
dglClearColor((float)r / 255.0, (float)g / 255.0, (float)b / 255.0, 0);
dglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
width = OpenGL_state.clip_x2 - OpenGL_state.clip_x1;
height = OpenGL_state.clip_y2 - OpenGL_state.clip_y1;
width = gpu_state.clip_x2 - gpu_state.clip_x1;
height = gpu_state.clip_y2 - gpu_state.clip_y1;
dglScissor(OpenGL_state.clip_x1, OpenGL_state.screen_height - (OpenGL_state.clip_y1 + height), width, height);
dglScissor(gpu_state.clip_x1, gpu_state.screen_height - (gpu_state.clip_y1 + height), width, height);
dglDisable(GL_SCISSOR_TEST);
}
@ -2505,7 +2505,7 @@ void rend_SetPixel(ddgr_color color, int x, int y) {
// Sets a pixel on the display
ddgr_color rend_GetPixel(int x, int y) {
ddgr_color color[4];
dglReadPixels(x, (OpenGL_state.screen_height - 1) - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)color);
dglReadPixels(x, (gpu_state.screen_height - 1) - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)color);
return color[0];
}
@ -2546,7 +2546,7 @@ void rend_DrawLine(int x1, int y1, int x2, int y2) {
sbyte atype;
light_state ltype;
texture_type ttype;
int color = OpenGL_state.cur_color;
int color = gpu_state.cur_color;
g3_RefreshTransforms(true);
@ -2554,9 +2554,9 @@ void rend_DrawLine(int x1, int y1, int x2, int y2) {
int g = GR_COLOR_GREEN(color);
int b = GR_COLOR_BLUE(color);
atype = OpenGL_state.cur_alpha_type;
ltype = OpenGL_state.cur_light_state;
ttype = OpenGL_state.cur_texture_type;
atype = gpu_state.cur_alpha_type;
ltype = gpu_state.cur_light_state;
ttype = gpu_state.cur_texture_type;
rend_SetAlphaType(AT_ALWAYS);
rend_SetLighting(LS_NONE);
@ -2564,9 +2564,9 @@ void rend_DrawLine(int x1, int y1, int x2, int y2) {
dglBegin(GL_LINES);
dglColor4ub(r, g, b, 255);
dglVertex2i(x1 + OpenGL_state.clip_x1, y1 + OpenGL_state.clip_y1);
dglVertex2i(x1 + gpu_state.clip_x1, y1 + gpu_state.clip_y1);
dglColor4ub(r, g, b, 255);
dglVertex2i(x2 + OpenGL_state.clip_x1, y2 + OpenGL_state.clip_y1);
dglVertex2i(x2 + gpu_state.clip_x1, y2 + gpu_state.clip_y1);
dglEnd();
rend_SetAlphaType(atype);
@ -2576,7 +2576,7 @@ void rend_DrawLine(int x1, int y1, int x2, int y2) {
// Sets the color of fog
void rend_SetFogColor(ddgr_color color) {
if (color == OpenGL_state.cur_fog_color)
if (color == gpu_state.cur_fog_color)
return;
float fc[4];
@ -2594,7 +2594,7 @@ void rend_SetFogColor(ddgr_color color) {
// Sets the lighting state of opengl
void rend_SetLightingState(light_state state) {
if (state == OpenGL_state.cur_light_state)
if (state == gpu_state.cur_light_state)
return; // No redundant state setting
if (UseMultitexture && Last_texel_unit_set != 0) {
@ -2609,16 +2609,16 @@ void rend_SetLightingState(light_state state) {
switch (state) {
case LS_NONE:
dglShadeModel(GL_SMOOTH);
OpenGL_state.cur_light_state = LS_NONE;
gpu_state.cur_light_state = LS_NONE;
break;
case LS_FLAT_GOURAUD:
dglShadeModel(GL_SMOOTH);
OpenGL_state.cur_light_state = LS_FLAT_GOURAUD;
gpu_state.cur_light_state = LS_FLAT_GOURAUD;
break;
case LS_GOURAUD:
case LS_PHONG:
dglShadeModel(GL_SMOOTH);
OpenGL_state.cur_light_state = LS_GOURAUD;
gpu_state.cur_light_state = LS_GOURAUD;
break;
default:
Int3();
@ -2629,7 +2629,7 @@ void rend_SetLightingState(light_state state) {
}
void rend_SetAlphaType(sbyte atype) {
if (atype == OpenGL_state.cur_alpha_type)
if (atype == gpu_state.cur_alpha_type)
return; // don't set it redundantly
#if (defined(_USE_OGL_ACTIVE_TEXTURES))
if (UseMultitexture && Last_texel_unit_set != 0) {
@ -2681,32 +2681,32 @@ void rend_SetAlphaType(sbyte atype) {
Int3(); // no type defined,get jason
break;
}
OpenGL_state.cur_alpha_type = atype;
gpu_state.cur_alpha_type = atype;
Alpha_multiplier = opengl_GetAlphaMultiplier();
CHECK_ERROR(15)
}
// Sets the alpha value for constant alpha
void rend_SetAlphaValue(ubyte val) {
OpenGL_state.cur_alpha = val;
gpu_state.cur_alpha = val;
Alpha_multiplier = opengl_GetAlphaMultiplier();
}
// Sets the texture wrapping type
void rend_SetWrapType(wrap_type val) { OpenGL_state.cur_wrap_type = val; }
void rend_SetWrapType(wrap_type val) { gpu_state.cur_wrap_type = val; }
// Draws a line using the states of the renderer
void rend_DrawSpecialLine(g3Point *p0, g3Point *p1) {
g3_RefreshTransforms(true);
int x_add = OpenGL_state.clip_x1;
int y_add = OpenGL_state.clip_y1;
int x_add = gpu_state.clip_x1;
int y_add = gpu_state.clip_y1;
float fr, fg, fb, alpha;
int i;
fr = GR_COLOR_RED(OpenGL_state.cur_color);
fg = GR_COLOR_GREEN(OpenGL_state.cur_color);
fb = GR_COLOR_BLUE(OpenGL_state.cur_color);
fr = GR_COLOR_RED(gpu_state.cur_color);
fg = GR_COLOR_GREEN(gpu_state.cur_color);
fb = GR_COLOR_BLUE(gpu_state.cur_color);
fr /= 255.0f;
fg /= 255.0f;
@ -2722,16 +2722,16 @@ void rend_DrawSpecialLine(g3Point *p0, g3Point *p1) {
if (i == 1)
pnt = p1;
if (OpenGL_state.cur_alpha_type & ATF_VERTEX)
if (gpu_state.cur_alpha_type & ATF_VERTEX)
alpha = pnt->p3_a * Alpha_multiplier * gpu_Alpha_factor;
// If we have a lighting model, apply the correct lighting!
if (OpenGL_state.cur_light_state != LS_NONE) {
if (OpenGL_state.cur_light_state == LS_FLAT_GOURAUD) {
if (gpu_state.cur_light_state != LS_NONE) {
if (gpu_state.cur_light_state == LS_FLAT_GOURAUD) {
dglColor4f(fr, fg, fb, alpha);
} else {
// Do lighting based on intesity (MONO) or colored (RGB)
if (OpenGL_state.cur_color_model == CM_MONO)
if (gpu_state.cur_color_model == CM_MONO)
dglColor4f(pnt->p3_l, pnt->p3_l, pnt->p3_l, alpha);
else {
dglColor4f(pnt->p3_r, pnt->p3_g, pnt->p3_b, alpha);
@ -2754,10 +2754,10 @@ void rend_Screenshot(int bm_handle) {
ushort *dest_data;
uint *temp_data;
int i, t;
int total = OpenGL_state.screen_width * OpenGL_state.screen_height;
int total = gpu_state.screen_width * gpu_state.screen_height;
ASSERT((bm_w(bm_handle, 0)) == OpenGL_state.screen_width);
ASSERT((bm_h(bm_handle, 0)) == OpenGL_state.screen_height);
ASSERT((bm_w(bm_handle, 0)) == gpu_state.screen_width);
ASSERT((bm_h(bm_handle, 0)) == gpu_state.screen_height);
int w = bm_w(bm_handle, 0);
int h = bm_h(bm_handle, 0);
@ -2767,7 +2767,7 @@ void rend_Screenshot(int bm_handle) {
dest_data = bm_data(bm_handle, 0);
dglReadPixels(0, 0, OpenGL_state.screen_width, OpenGL_state.screen_height, GL_RGBA, GL_UNSIGNED_BYTE,
dglReadPixels(0, 0, gpu_state.screen_width, gpu_state.screen_height, GL_RGBA, GL_UNSIGNED_BYTE,
(GLvoid *)temp_data);
for (i = 0; i < h; i++) {
@ -2814,20 +2814,20 @@ void rend_ReleaseLFBLock(renderer_lfb *lfb) {}
// Returns the aspect ratio of the physical screen
void rend_GetProjectionParameters(int *width, int *height) {
*width = OpenGL_state.clip_x2 - OpenGL_state.clip_x1;
*height = OpenGL_state.clip_y2 - OpenGL_state.clip_y1;
*width = gpu_state.clip_x2 - gpu_state.clip_x1;
*height = gpu_state.clip_y2 - gpu_state.clip_y1;
}
void rend_GetProjectionScreenParameters(int &screenLX, int &screenTY, int &screenW, int &screenH) {
screenLX = OpenGL_state.clip_x1;
screenTY = OpenGL_state.clip_y1;
screenW = OpenGL_state.clip_x2 - OpenGL_state.clip_x1 + 1;
screenH = OpenGL_state.clip_y2 - OpenGL_state.clip_y1 + 1;
screenLX = gpu_state.clip_x1;
screenTY = gpu_state.clip_y1;
screenW = gpu_state.clip_x2 - gpu_state.clip_x1 + 1;
screenH = gpu_state.clip_y2 - gpu_state.clip_y1 + 1;
}
// Returns the aspect ratio of the physical screen
float rend_GetAspectRatio(void) {
float aspect_ratio = (float)((3.0f * OpenGL_state.screen_width) / (4.0f * OpenGL_state.screen_height));
float aspect_ratio = (float)((3.0f * gpu_state.screen_width) / (4.0f * gpu_state.screen_height));
return aspect_ratio;
}
@ -2916,29 +2916,29 @@ void rend_DrawScaledChunkedBitmap(chunked_bitmap *chunk, int x, int y, int neww,
// Sets some global preferences for the renderer
int rend_SetPreferredState(renderer_preferred_state *pref_state) {
int retval = 1;
renderer_preferred_state old_state = OpenGL_preferred_state;
renderer_preferred_state old_state = gpu_preferred_state;
OpenGL_preferred_state = *pref_state;
if (OpenGL_state.initted) {
gpu_preferred_state = *pref_state;
if (gpu_state.initted) {
int reinit = 0;
mprintf((0, "Inside pref state!\n"));
// Change gamma if needed
if (pref_state->width != OpenGL_state.screen_width || pref_state->height != OpenGL_state.screen_height ||
if (pref_state->width != gpu_state.screen_width || pref_state->height != gpu_state.screen_height ||
old_state.bit_depth != pref_state->bit_depth) {
reinit = 1;
}
if (reinit) {
opengl_Close();
retval = opengl_Init(NULL, &OpenGL_preferred_state);
retval = opengl_Init(NULL, &gpu_preferred_state);
} else {
if (old_state.gamma != pref_state->gamma) {
rend_SetGammaValue(pref_state->gamma);
}
}
} else {
OpenGL_preferred_state = *pref_state;
gpu_preferred_state = *pref_state;
}
return retval;
@ -2957,7 +2957,7 @@ void rend_DrawSimpleBitmap(int bm_handle, int x, int y) {
}
// Fills in the passed in pointer with the current rendering state
void rend_GetRenderState(rendering_state *rstate) { memcpy(rstate, &OpenGL_state, sizeof(rendering_state)); }
void rend_GetRenderState(rendering_state *rstate) { memcpy(rstate, &gpu_state, sizeof(rendering_state)); }
// Takes a bitmap and blits it to the screen using linear frame buffer stuff
// X and Y are the destination X,Y
@ -3023,8 +3023,8 @@ void *rend_RetrieveDirectDrawObj(void **frontsurf, void **backsurf) {
}
void rend_TransformSetToPassthru(void) {
int width = OpenGL_state.screen_width;
int height = OpenGL_state.screen_height;
int width = gpu_state.screen_width;
int height = gpu_state.screen_height;
// TODO: Generalize
// Projection
@ -3041,7 +3041,7 @@ void rend_TransformSetToPassthru(void) {
}
void rend_TransformSetViewport(int lx, int ty, int width, int height) {
dglViewport(lx, OpenGL_state.screen_height - (ty + height - 1), width, height);
dglViewport(lx, gpu_state.screen_height - (ty + height - 1), width, height);
}
void rend_TransformSetProjection(float trans[4][4]) {