View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002728 | FSSCP | OpenGL | public | 2012-11-16 18:53 | 2012-11-18 18:45 |
| Reporter | Valathil | Assigned To | Valathil | ||
| Priority | normal | Severity | tweak | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | 3.6.16 | ||||
| Target Version | 3.7.0 | ||||
| Summary | 0002728: Redundant OpenGL calls | ||||
| Description | ur OpenGL render pipeline has a lot of redundant gl calls. I used gDebugger to profile the game and got this. https://docs.google.com/spreadsheet/ccc?key=0AqWZPyuAdLfddFkxSWJtaDZveWdHMFJ3R1ByMktvbEE#gid=0 Not good! So a few hours of cleaning up and I got this https://docs.google.com/spreadsheet/ccc?key=0AqWZPyuAdLfddEtnR283anpBbUhNakV2UzJZSGlpSVE#gid=0 I haven't fixed the glLight calls since they will be insignificant when deferred rendering is implemented. But since gl calls are expensive I got some speed up from the game look at the attached chart for Artemis Station @ 1920*1080 VSYNC on. Patch for Code Review is also attached. | ||||
| Tags | No tags attached. | ||||
|
|
|
|
|
gl_cleanup.patch (23,247 bytes)
Index: code/cutscene/mveplayer.cpp
===================================================================
--- code/cutscene/mveplayer.cpp (revision 9348)
+++ code/cutscene/mveplayer.cpp (working copy)
@@ -700,7 +700,7 @@
glTexImage2D(GL_state.Texture.GetTarget(), 0, GL_RGB5_A1, wp2, hp2, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL);
// set our color so that we can make sure that it's correct
- glColor3f(1.0f, 1.0f, 1.0f);
+ GL_state.Color(255, 255, 255, 255);
}
memset(g_palette, 0, 768);
Index: code/cutscene/oggplayer.cpp
===================================================================
--- code/cutscene/oggplayer.cpp (revision 9348)
+++ code/cutscene/oggplayer.cpp (working copy)
@@ -496,7 +496,7 @@
}
// set our color so that we can make sure that it's correct
- glColor3f(1.0f, 1.0f, 1.0f);
+ GL_state.Color(255, 255, 255, 255);
}
if(!use_shaders) {
Index: code/graphics/gropengl.cpp
===================================================================
--- code/graphics/gropengl.cpp (revision 9348)
+++ code/graphics/gropengl.cpp (working copy)
@@ -1347,6 +1347,9 @@
int opengl_check_for_errors(char *err_at)
{
+#ifdef NDEBUG
+ return 0;
+#endif
const char *error_str = NULL;
int num_errors = 0;
Index: code/graphics/gropengldraw.cpp
===================================================================
--- code/graphics/gropengldraw.cpp (revision 9348)
+++ code/graphics/gropengldraw.cpp (working copy)
@@ -110,7 +110,7 @@
gr_resize_screen_posf(&x2, &y2);
}
- glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
if (mirror) {
float temp = u0;
@@ -346,9 +346,9 @@
// set color!
if (gr_screen.current_color.is_alphacolor) {
- glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
} else {
- glColor3ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue);
}
// if ( (gr_screen.custom_size && resize) || (gr_screen.rendering_to_texture != -1) ) {
@@ -560,7 +560,7 @@
gr_opengl_set_2d_matrix();
GLfloat vert[3]= {sx1, sy1, -0.99f};
- glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
GL_state.Array.EnableClientVertex();
GL_state.Array.VertexPointer(3, GL_FLOAT, 0, vert);
@@ -597,7 +597,7 @@
sx1, sy1, -0.99f
};
- glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
GL_state.Array.EnableClientVertex();
GL_state.Array.VertexPointer(3, GL_FLOAT, 0, line);
@@ -624,10 +624,10 @@
if (gr_screen.current_color.is_alphacolor) {
GL_state.SetAlphaBlendMode(ALPHA_BLEND_ALPHA_BLEND_ALPHA);
- glColor4ub( gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha );
+ GL_state.Color( gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha );
} else {
GL_state.SetAlphaBlendMode(ALPHA_BLEND_NONE);
- glColor3ub( gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue );
+ GL_state.Color( gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue );
}
GLfloat line[6] = {
@@ -677,7 +677,7 @@
if ( (x1 == x2) && (y1 == y2) ) {
gr_opengl_set_2d_matrix();
- glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
GLfloat vert[3]= {sx1, sy1, -0.99f};
@@ -711,7 +711,7 @@
gr_opengl_set_2d_matrix();
- glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue, gr_screen.current_color.alpha);
GLfloat line[6] = {
sx2, sy2, -0.99f,
sx1, sy1, -0.99f
@@ -988,7 +988,7 @@
isRGB = true;
}
} else {
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, alpha );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, alpha );
}
if (flags & TMAP_FLAG_TRISTRIP) {
@@ -1212,7 +1212,7 @@
// use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
if ( !isRGB ) {
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
}
SCP_vector<ubyte> colour;
@@ -1328,18 +1328,17 @@
if (flags & TMAP_FLAG_ALPHA) {
GL_state.Array.ColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), &verts[0].r);
} else {
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
GL_state.Array.ColorPointer(3, GL_UNSIGNED_BYTE, sizeof(vertex), &verts[0].r);
}
}
// use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
else {
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
+ GL_state.Color( (ubyte)r-1, (ubyte)g, (ubyte)b, (ubyte)alpha );
}
float offset_z = -0.99f;
- glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef((float)gr_screen.offset_x, (float)gr_screen.offset_y, offset_z);
@@ -1360,7 +1359,6 @@
glMatrixMode(GL_MODELVIEW);
}
- glMatrixMode(GL_MODELVIEW);
glPopMatrix();
GL_state.Array.DisableClientTexture();
@@ -1411,7 +1409,7 @@
}
// use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
else {
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
}
GL_state.Array.EnableClientVertex();
@@ -1535,7 +1533,7 @@
}
// use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
else {
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
}
GL_state.Array.EnableClientVertex();
@@ -1758,7 +1756,7 @@
gr_opengl_set_2d_matrix();
- glColor4ub( (GLubyte)gr_screen.current_shader.r, (GLubyte)gr_screen.current_shader.g,
+ GL_state.Color( (GLubyte)gr_screen.current_shader.r, (GLubyte)gr_screen.current_shader.g,
(GLubyte)gr_screen.current_shader.b, (GLubyte)gr_screen.current_shader.c );
opengl_draw_coloured_quad((GLint)x1, (GLint)y1, (GLint)x2, (GLint)y2);
@@ -1785,7 +1783,7 @@
int x2 = (gr_screen.clip_right + gr_screen.offset_x) + 1;
int y2 = (gr_screen.clip_bottom + gr_screen.offset_y) + 1;
- glColor4ub( (GLubyte)r, (GLubyte)g, (GLubyte)b, 255 );
+ GL_state.Color( (GLubyte)r, (GLubyte)g, (GLubyte)b, 255 );
opengl_draw_coloured_quad((GLint)x1, (GLint)y1, (GLint)x2, (GLint)y2);
}
@@ -1810,7 +1808,7 @@
int x2 = (gr_screen.clip_right + gr_screen.offset_x) + 1;
int y2 = (gr_screen.clip_bottom + gr_screen.offset_y) + 1;
- glColor4ub( (GLubyte)r, (GLubyte)g, (GLubyte)b, (GLubyte)a );
+ GL_state.Color( (GLubyte)r, (GLubyte)g, (GLubyte)b, (GLubyte)a );
opengl_draw_coloured_quad((GLint)x1, (GLint)y1, (GLint)x2, (GLint)y2);
}
@@ -1869,7 +1867,7 @@
gr_resize_screen_posf(&x2, &y2);
}
- glColor4f(1.0f, 1.0f, 1.0f, gr_screen.current_alpha);
+ GL_state.Color(255, 255, 255, (GLubyte)(gr_screen.current_alpha * 255));
opengl_draw_textured_quad(x1, y1, u0, v0, x2, y2, u1, v1);
}
@@ -2057,7 +2055,7 @@
GL_state.SetAlphaBlendMode(ALPHA_BLEND_NONE);
GL_state.SetZbufferType(ZBUFFER_TYPE_NONE);
- glColor3fv(pre_set_colours[colour]);
+ GL_state.Color((GLubyte)(pre_set_colours[colour][0] * 255) , (GLubyte)(pre_set_colours[colour][1] * 255), (GLubyte)(pre_set_colours[colour][2] * 255));
opengl_draw_coloured_quad(x, y, x+w, y+h);
}
@@ -2083,7 +2081,7 @@
GL_state.SetAlphaBlendMode(ALPHA_BLEND_NONE);
GL_state.SetZbufferType(ZBUFFER_TYPE_FULL);
- glColor3ub(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue);
+ GL_state.Color(gr_screen.current_color.red, gr_screen.current_color.green, gr_screen.current_color.blue);
// FIXME: opengl_check_for_errors() needs to be modified to work with this at
// some point but for now I just don't care so it does nothing
@@ -2433,7 +2431,7 @@
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ GL_state.Color(255, 255, 255, 255);
GL_state.Array.BindArrayBuffer(0);
@@ -2532,7 +2530,7 @@
GL_state.Texture.Enable(Distortion_texture[Distortion_switch]);
glClearColor(0.5f, 0.5f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ GL_state.Color(255, 255, 255, 255);
GLfloat texcoord[8] = {
0.0f, 0.0f,
Index: code/graphics/gropengllight.cpp
===================================================================
--- code/graphics/gropengllight.cpp (revision 9348)
+++ code/graphics/gropengllight.cpp (working copy)
@@ -170,9 +170,9 @@
glLightfv(GL_LIGHT0+light_num, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0+light_num, GL_SPECULAR, ltp->Specular);
glLightfv(GL_LIGHT0+light_num, GL_SPOT_DIRECTION, ltp->SpotDir);
- glLightf(GL_LIGHT0+light_num, GL_CONSTANT_ATTENUATION, ltp->ConstantAtten);
+ //glLightf(GL_LIGHT0+light_num, GL_CONSTANT_ATTENUATION, ltp->ConstantAtten); Default is 1.0 and we only use 1.0 - Valathil
glLightf(GL_LIGHT0+light_num, GL_LINEAR_ATTENUATION, ltp->LinearAtten);
- glLightf(GL_LIGHT0+light_num, GL_QUADRATIC_ATTENUATION, ltp->QuadraticAtten);
+ //glLightf(GL_LIGHT0+light_num, GL_QUADRATIC_ATTENUATION, ltp->QuadraticAtten); Default is 0.0 and we only use 0.0 - Valathil
glLightf(GL_LIGHT0+light_num, GL_SPOT_EXPONENT, ltp->SpotExp);
glLightf(GL_LIGHT0+light_num, GL_SPOT_CUTOFF, ltp->SpotCutOff);
}
@@ -244,7 +244,6 @@
offset = (pos * GL_max_lights) + d_offset;
- glMatrixMode(GL_MODELVIEW);
glPushMatrix();
if ( !memcmp(&Eye_position, &last_view_pos, sizeof(vec3d)) && !memcmp(&Eye_matrix, &last_view_orient, sizeof(matrix)) ) {
@@ -516,33 +515,54 @@
}
extern int Cmdline_no_emissive;
+bool ambient_state = false;
+bool emission_state = false;
+bool specular_state = false;
void opengl_default_light_settings(int ambient, int emission, int specular)
{
if (!lighting_is_enabled)
return;
if (ambient) {
- glMaterialfv( GL_FRONT, GL_DIFFUSE, GL_light_color );
- glMaterialfv( GL_FRONT, GL_AMBIENT, GL_light_ambient );
+ if(!ambient_state) {
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, GL_light_color );
+ glMaterialfv( GL_FRONT, GL_AMBIENT, GL_light_ambient );
+ ambient_state = true;
+ }
} else {
- if (GL_center_alpha) {
- glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, GL_light_true_zero );
- } else {
- glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, GL_light_zero );
+ if(ambient_state) {
+ if (GL_center_alpha) {
+ glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, GL_light_true_zero );
+ } else {
+ glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, GL_light_zero );
+ }
+ ambient_state = false;
}
}
if (emission && !Cmdline_no_emissive) {
// emissive light is just a general glow but without it things are *terribly* dark if there is no light on them
- glMaterialfv( GL_FRONT, GL_EMISSION, GL_light_emission );
+ if(!emission_state) {
+ glMaterialfv( GL_FRONT, GL_EMISSION, GL_light_emission );
+ emission_state = true;
+ }
} else {
- glMaterialfv( GL_FRONT, GL_EMISSION, GL_light_zero );
+ if(emission_state) {
+ glMaterialfv( GL_FRONT, GL_EMISSION, GL_light_zero );
+ emission_state = false;
+ }
}
if (specular) {
- glMaterialfv( GL_FRONT, GL_SPECULAR, GL_light_spec );
+ if(!specular_state) {
+ glMaterialfv( GL_FRONT, GL_SPECULAR, GL_light_spec );
+ specular_state = true;
+ }
} else {
- glMaterialfv( GL_FRONT, GL_SPECULAR, GL_light_zero );
+ if(specular_state) {
+ glMaterialfv( GL_FRONT, GL_SPECULAR, GL_light_zero );
+ specular_state = false;
+ }
}
}
Index: code/graphics/gropenglpostprocessing.cpp
===================================================================
--- code/graphics/gropenglpostprocessing.cpp (revision 9348)
+++ code/graphics/gropenglpostprocessing.cpp (working copy)
@@ -382,7 +382,7 @@
GL_state.Texture.SetActiveUnit(1);
GL_state.Texture.SetTarget(GL_TEXTURE_2D);
GL_state.Texture.Enable(Cockpit_depth_texture);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ GL_state.Color(255, 255, 255, 255);
GL_state.Blend(GL_TRUE);
GL_state.SetAlphaBlendMode(ALPHA_BLEND_ADDITIVE);
@@ -411,7 +411,7 @@
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ GL_state.Color(255, 255, 255, 255);
// set and configure post shader ...
Index: code/graphics/gropenglstate.cpp
===================================================================
--- code/graphics/gropenglstate.cpp (revision 9348)
+++ code/graphics/gropenglstate.cpp (working copy)
@@ -32,12 +32,55 @@
units = (opengl_texture_unit*) vm_malloc(n_units * sizeof(opengl_texture_unit));
num_texture_units = n_units;
- for (unsigned int i = 0; i < num_texture_units; i++) {
- units[i].active = GL_FALSE;
- units[i].enabled = GL_FALSE;
- units[i].used = GL_FALSE;
+ for (unsigned int unit = 0; unit < num_texture_units; unit++) {
+ units[unit].active = GL_FALSE;
+ units[unit].enabled = GL_FALSE;
+ units[unit].used = GL_FALSE;
- default_values(i);
+ default_values(unit);
+
+ vglActiveTextureARB(GL_TEXTURE0 + unit);
+ if (unit < GL_supported_texture_units) {
+ glDisable(GL_TEXTURE_GEN_S);
+ glDisable(GL_TEXTURE_GEN_T);
+ glDisable(GL_TEXTURE_GEN_R);
+ glDisable(GL_TEXTURE_GEN_Q);
+ }
+
+ units[unit].texgen_S = GL_FALSE;
+ units[unit].texgen_T = GL_FALSE;
+ units[unit].texgen_R = GL_FALSE;
+ units[unit].texgen_Q = GL_FALSE;
+
+ if (unit < GL_supported_texture_units) {
+ glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
+ glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
+ glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
+ glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
+ }
+
+ units[unit].texgen_mode_S = GL_EYE_LINEAR;
+ units[unit].texgen_mode_T = GL_EYE_LINEAR;
+ units[unit].texgen_mode_R = GL_EYE_LINEAR;
+ units[unit].texgen_mode_Q = GL_EYE_LINEAR;
+
+ if (unit < GL_supported_texture_units) {
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
+ glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
+ }
+
+ units[unit].env_mode = GL_MODULATE;
+ units[unit].env_combine_rgb = GL_MODULATE;
+ units[unit].env_combine_alpha = GL_MODULATE;
+
+ if (unit < GL_supported_texture_units) {
+ glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
+ glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1.0f);
+ }
+
+ units[unit].rgb_scale = 1.0f;
+ units[unit].alpha_scale = 1.0f;
}
DisableAll();
@@ -59,48 +102,6 @@
units[unit].texture_target = GL_TEXTURE_2D;
units[unit].texture_id = 0;
}
-
- if (unit < GL_supported_texture_units) {
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- glDisable(GL_TEXTURE_GEN_R);
- glDisable(GL_TEXTURE_GEN_Q);
- }
-
- units[unit].texgen_S = GL_FALSE;
- units[unit].texgen_T = GL_FALSE;
- units[unit].texgen_R = GL_FALSE;
- units[unit].texgen_Q = GL_FALSE;
-
- if (unit < GL_supported_texture_units) {
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- }
-
- units[unit].texgen_mode_S = GL_EYE_LINEAR;
- units[unit].texgen_mode_T = GL_EYE_LINEAR;
- units[unit].texgen_mode_R = GL_EYE_LINEAR;
- units[unit].texgen_mode_Q = GL_EYE_LINEAR;
-
- if (unit < GL_supported_texture_units) {
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
- }
-
- units[unit].env_mode = GL_MODULATE;
- units[unit].env_combine_rgb = GL_MODULATE;
- units[unit].env_combine_alpha = GL_MODULATE;
-
- if (unit < GL_supported_texture_units) {
- glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
- glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1.0f);
- }
-
- units[unit].rgb_scale = 1.0f;
- units[unit].alpha_scale = 1.0f;
}
GLboolean opengl_texture_state::TexgenS(GLint state)
@@ -395,6 +396,12 @@
Current_alpha_blend_mode = ALPHA_BLEND_NONE;
Current_zbuffer_type = ZBUFFER_TYPE_READ;
+
+ glColor4ub(255, 255, 255, 255);
+ red_Status = 255;
+ blue_Status = 255;
+ green_Status = 255;
+ alpha_Status = 255;
}
GLboolean opengl_state::Lighting(GLint state)
Index: code/graphics/gropenglstate.h
===================================================================
--- code/graphics/gropenglstate.h (revision 9348)
+++ code/graphics/gropenglstate.h (working copy)
@@ -106,7 +106,10 @@
inline void opengl_texture_state::SetEnvMode(GLenum mode)
{
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
+ if(mode != units[active_texture_unit].env_mode) {
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
+ units[active_texture_unit].env_mode = mode;
+ }
}
inline void opengl_texture_state::SetEnvCombineMode(GLenum cmode, GLenum cfunc)
@@ -281,6 +284,10 @@
GLboolean depthmask_Status;
GLboolean lighting_Status;
GLboolean colormask_Status;
+ GLubyte red_Status;
+ GLubyte blue_Status;
+ GLubyte green_Status;
+ GLubyte alpha_Status;
GLenum frontface_Value;
GLenum cullface_Value;
@@ -330,6 +337,7 @@
inline GLenum BlendFuncDest();
inline GLenum DepthFunc(GLenum new_val = GL_INVALID_ENUM);
inline void AlphaFunc(GLenum f_val, GLclampf r_val);
+ inline void Color(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha = 255);
};
inline GLenum opengl_state::FrontFaceValue(GLenum new_val)
@@ -396,6 +404,17 @@
glAlphaFunc(f_val, r_val);
}
+inline void opengl_state::Color(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
+{
+ if( (red != red_Status) || (green != green_Status) || (blue != blue_Status) || (alpha != alpha_Status) ) {
+ glColor4ub(red, green, blue, alpha);
+ red_Status = red;
+ green_Status = green;
+ blue_Status = blue;
+ alpha_Status = alpha;
+ }
+}
+
extern opengl_state GL_state;
void gr_opengl_flush_data_states();
Index: code/graphics/gropengltnl.cpp
===================================================================
--- code/graphics/gropengltnl.cpp (revision 9348)
+++ code/graphics/gropengltnl.cpp (working copy)
@@ -676,7 +676,7 @@
gr_opengl_set_center_alpha(GL_center_alpha);
opengl_setup_render_states(r, g, b, a, tmap_type, flags);
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)a );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)a );
render_pass = 0;
@@ -792,8 +792,6 @@
render_pass++;
}
- GL_state.Texture.DisableUnused();
-
// Team colors are passed to the shader here, but the shader needs to handle their application.
// By default, this is handled through the r and g channels of the misc map, but this can be changed
// in the shader; test versions of this used the normal map r and b channels
@@ -933,7 +931,7 @@
gr_opengl_set_center_alpha(GL_center_alpha);
opengl_setup_render_states(r, g, b, a, tmap_type, flags);
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)a );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)a );
// basic setup of all data
opengl_init_arrays(vbp, bufferp);
@@ -1453,7 +1451,7 @@
} else {
// use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
GL_state.Array.DisableClientColor();
- glColor4ub( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
+ GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
}
GL_state.Array.EnableClientVertex();
@@ -1488,7 +1486,6 @@
GL_CHECK_FOR_ERRORS("start of start_instance_matrix()");
- glMatrixMode(GL_MODELVIEW);
glPushMatrix();
vec3d axis;
@@ -1496,7 +1493,8 @@
vm_matrix_to_rot_axis_and_angle(rotation, &ang, &axis);
glTranslatef( offset->xyz.x, offset->xyz.y, offset->xyz.z );
- glRotatef( fl_degrees(ang), axis.xyz.x, axis.xyz.y, axis.xyz.z );
+ if(abs(ang) > 0.0f)
+ glRotatef( fl_degrees(ang), axis.xyz.x, axis.xyz.y, axis.xyz.z );
GL_CHECK_FOR_ERRORS("end of start_instance_matrix()");
@@ -1525,7 +1523,6 @@
Assert(GL_htl_projection_matrix_set);
Assert(GL_htl_view_matrix_set);
- glMatrixMode(GL_MODELVIEW);
glPopMatrix();
GL_modelview_matrix_depth--;
@@ -1614,7 +1611,6 @@
GL_CHECK_FOR_ERRORS("start of set_view_matrix()");
- glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// right now it depends on your settings as to whether this has any effect in-mission
@@ -1725,7 +1721,6 @@
Assert(GL_modelview_matrix_depth == 2);
- glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glLoadIdentity();
@@ -1810,32 +1805,27 @@
void gr_opengl_push_scale_matrix(vec3d *scale_factor)
{
- if (GL_scale_matrix_set)
- {
- Int3();
+ if((scale_factor->xyz.x == 1) && (scale_factor->xyz.y == 1) && (scale_factor->xyz.z == 1))
return;
- }
- glMatrixMode(GL_MODELVIEW);
+ GL_scale_matrix_set = true;
+
glPushMatrix();
GL_modelview_matrix_depth++;
-
+
glScalef(scale_factor->xyz.x, scale_factor->xyz.y, scale_factor->xyz.z);
}
void gr_opengl_pop_scale_matrix()
{
- if (GL_scale_matrix_set)
- {
- Int3();
+ if (!GL_scale_matrix_set)
return;
- }
- glMatrixMode(GL_MODELVIEW);
glPopMatrix();
GL_modelview_matrix_depth--;
+ GL_scale_matrix_set = false;
}
void gr_opengl_end_clip_plane()
Index: code/menuui/mainhallmenu.cpp
===================================================================
--- code/menuui/mainhallmenu.cpp (revision 9348)
+++ code/menuui/mainhallmenu.cpp (working copy)
@@ -1681,6 +1681,7 @@
// set the color and print out text and shader
gr_set_color_fast(&Color_bright_white);
+ gr_set_shader(&Main_hall_tooltip_shader);
gr_shade(0, 0, gr_screen.max_w_unscaled, (2*Main_hall_tooltip_padding[gr_screen.res]) + h - y_anim_offset);
gr_string((gr_screen.max_w_unscaled - w)/2, Main_hall_tooltip_padding[gr_screen.res] /*- y_anim_offset*/, str);
}
|
|
|
Awesome, but there are sadly some signed/unsigned mismatches in the existing patch. Fastest way (without out going down a rabbit hole) is to cast 'GL_supported_texture_units' to GLuint in the 'for' I tried making the unit an int, but that just went off the rails in the other direction, unless you want to change 'GL_supported_texture_units' to being GLuint but that's a rabbit hole in another direction. The casting is probably fine, but I don't generally tend to like that option. |
|
|
Cleanup commited to Trunk @ 9353 |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2012-11-16 18:53 | Valathil | New Issue | |
| 2012-11-16 18:53 | Valathil | Status | new => assigned |
| 2012-11-16 18:53 | Valathil | Assigned To | => Valathil |
| 2012-11-16 18:53 | Valathil | File Added: chart_1(5).png | |
| 2012-11-16 18:55 | Valathil | File Added: gl_cleanup.patch | |
| 2012-11-16 19:03 | Valathil | Status | assigned => code review |
| 2012-11-18 05:08 | Zacam | Note Added: 0014046 | |
| 2012-11-18 18:45 | Valathil | Note Added: 0014053 | |
| 2012-11-18 18:45 | Valathil | Status | code review => resolved |
| 2012-11-18 18:45 | Valathil | Resolution | open => fixed |