- debug_string("disabled depth-buffer writing");
-
- GlobalOpenGL_debugAssertNoErrors();
- }
-
- if (delta & state & RENDER_COLOURWRITE) {
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- GlobalOpenGL_debugAssertNoErrors();
- } else if (delta & ~state & RENDER_COLOURWRITE) {
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- GlobalOpenGL_debugAssertNoErrors();
- }
-
- setState(state, delta, RENDER_ALPHATEST, GL_ALPHA_TEST);
-
- if (delta & state & RENDER_COLOURARRAY) {
- glEnableClientState(GL_COLOR_ARRAY);
- GlobalOpenGL_debugAssertNoErrors();
- debug_colour("enabling color_array");
- g_colorArray_enabled = true;
- } else if (delta & ~state & RENDER_COLOURARRAY) {
- glDisableClientState(GL_COLOR_ARRAY);
- glColor4fv(vector4_to_array(self.m_colour));
- debug_colour("cleaning color_array");
- GlobalOpenGL_debugAssertNoErrors();
- g_colorArray_enabled = false;
- }
-
- if (delta & ~state & RENDER_COLOURCHANGE) {
- glColor4fv(vector4_to_array(self.m_colour));
- GlobalOpenGL_debugAssertNoErrors();
- }
-
- setState(state, delta, RENDER_LINESTIPPLE, GL_LINE_STIPPLE);
- setState(state, delta, RENDER_LINESMOOTH, GL_LINE_SMOOTH);
-
- setState(state, delta, RENDER_POLYGONSTIPPLE, GL_POLYGON_STIPPLE);
- setState(state, delta, RENDER_POLYGONSMOOTH, GL_POLYGON_SMOOTH);
-
- setState(state, delta, RENDER_FOG, GL_FOG);
-
- if ((state & RENDER_FOG) != 0) {
- setFogState(self.m_fog);
- GlobalOpenGL_debugAssertNoErrors();
- current.m_fog = self.m_fog;
- }
-
- if (state & RENDER_DEPTHTEST && self.m_depthfunc != current.m_depthfunc) {
- glDepthFunc(self.m_depthfunc);
- GlobalOpenGL_debugAssertNoErrors();
- current.m_depthfunc = self.m_depthfunc;
- }
-
- if (state & RENDER_LINESTIPPLE
- && (self.m_linestipple_factor != current.m_linestipple_factor
- || self.m_linestipple_pattern != current.m_linestipple_pattern)) {
- glLineStipple(self.m_linestipple_factor, self.m_linestipple_pattern);
- GlobalOpenGL_debugAssertNoErrors();
- current.m_linestipple_factor = self.m_linestipple_factor;
- current.m_linestipple_pattern = self.m_linestipple_pattern;
- }
-
-
- if (state & RENDER_ALPHATEST
- && (self.m_alphafunc != current.m_alphafunc
- || self.m_alpharef != current.m_alpharef)) {
- glAlphaFunc(self.m_alphafunc, self.m_alpharef);
- GlobalOpenGL_debugAssertNoErrors();
- current.m_alphafunc = self.m_alphafunc;
- current.m_alpharef = self.m_alpharef;
- }
-
- {
- GLint texture0 = 0;
- GLint texture1 = 0;
- GLint texture2 = 0;
- GLint texture3 = 0;
- GLint texture4 = 0;
- GLint texture5 = 0;
- GLint texture6 = 0;
- GLint texture7 = 0;
- //if(state & RENDER_TEXTURE) != 0)
- {
- texture0 = self.m_texture;
- texture1 = self.m_texture1;
- texture2 = self.m_texture2;
- texture3 = self.m_texture3;
- texture4 = self.m_texture4;
- texture5 = self.m_texture5;
- texture6 = self.m_texture6;
- texture7 = self.m_texture7;
- }
-
- if (GlobalOpenGL().GL_1_3()) {
- setTextureState(current.m_texture, texture0, GL_TEXTURE0);
- setTextureState(current.m_texture1, texture1, GL_TEXTURE1);
- setTextureState(current.m_texture2, texture2, GL_TEXTURE2);
- setTextureState(current.m_texture3, texture3, GL_TEXTURE3);
- setTextureState(current.m_texture4, texture4, GL_TEXTURE4);
- setTextureState(current.m_texture5, texture5, GL_TEXTURE5);
- setTextureState(current.m_texture6, texture6, GL_TEXTURE6);
- setTextureState(current.m_texture7, texture7, GL_TEXTURE7);
- } else {
- setTextureState(current.m_texture, texture0);
- }
- }
-
-
- if (state & RENDER_TEXTURE && self.m_colour[3] != current.m_colour[3]) {
- debug_colour("setting alpha");
- glColor4f(1, 1, 1, self.m_colour[3]);
- GlobalOpenGL_debugAssertNoErrors();
- }
-
- if (!(state & RENDER_TEXTURE)
- && (self.m_colour[0] != current.m_colour[0]
- || self.m_colour[1] != current.m_colour[1]
- || self.m_colour[2] != current.m_colour[2]
- || self.m_colour[3] != current.m_colour[3])) {
- glColor4fv(vector4_to_array(self.m_colour));
- debug_colour("setting non-texture");
- GlobalOpenGL_debugAssertNoErrors();
- }
- current.m_colour = self.m_colour;
-
- if (state & RENDER_BLEND
- && (self.m_blend_src != current.m_blend_src || self.m_blend_dst != current.m_blend_dst)) {
- glBlendFunc(self.m_blend_src, self.m_blend_dst);
- GlobalOpenGL_debugAssertNoErrors();
- current.m_blend_src = self.m_blend_src;
- current.m_blend_dst = self.m_blend_dst;
- }
-
- if (!(state & RENDER_FILL)
- && self.m_linewidth != current.m_linewidth) {
- glLineWidth(self.m_linewidth);
- GlobalOpenGL_debugAssertNoErrors();
- current.m_linewidth = self.m_linewidth;
- }
-
- if (!(state & RENDER_FILL)
- && self.m_pointsize != current.m_pointsize) {
- glPointSize(self.m_pointsize);
- GlobalOpenGL_debugAssertNoErrors();
- current.m_pointsize = self.m_pointsize;
- }
-
- current.m_state = state;
-
- GlobalOpenGL_debugAssertNoErrors();
-}
-
-void Renderables_flush(OpenGLStateBucket::Renderables &renderables, OpenGLState ¤t, unsigned int globalstate,
- const Vector3 &viewer)
-{
- const Matrix4 *transform = 0;
- glPushMatrix();
- for (OpenGLStateBucket::Renderables::const_iterator i = renderables.begin(); i != renderables.end(); ++i) {
- //qglLoadMatrixf(i->m_transform);
- if (!transform || (transform != (*i).m_transform && !matrix4_affine_equal(*transform, *(*i).m_transform))) {
- count_transform();
- transform = (*i).m_transform;
- glPopMatrix();
- glPushMatrix();
- glMultMatrixf(reinterpret_cast<const float *>( transform ));
- glFrontFace(
- ((current.m_state & RENDER_CULLFACE) != 0 && matrix4_handedness(*transform) == MATRIX4_RIGHTHANDED)
- ? GL_CW : GL_CCW);
- }
-
- count_prim();
-
- if (current.m_program != 0 && (*i).m_light != 0) {
- const IShader &lightShader = static_cast<OpenGLShader *>((*i).m_light->getShader())->getShader();
- if (lightShader.firstLayer() != 0) {
- GLuint attenuation_xy = lightShader.firstLayer()->texture()->texture_number;
- GLuint attenuation_z = lightShader.lightFalloffImage() != 0
- ? lightShader.lightFalloffImage()->texture_number
- : static_cast<OpenGLShader *>( g_defaultPointLight )->getShader().lightFalloffImage()->texture_number;
-
- setTextureState(current.m_texture3, attenuation_xy, GL_TEXTURE3);
- glActiveTexture(GL_TEXTURE3);
- glBindTexture(GL_TEXTURE_2D, attenuation_xy);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-
- setTextureState(current.m_texture4, attenuation_z, GL_TEXTURE4);
- glActiveTexture(GL_TEXTURE4);
- glBindTexture(GL_TEXTURE_2D, attenuation_z);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
-
- AABB lightBounds((*i).m_light->aabb());
-
- Matrix4 world2light(g_matrix4_identity);
-
- if ((*i).m_light->isProjected()) {
- world2light = (*i).m_light->projection();
- matrix4_multiply_by_matrix4(world2light, matrix4_transposed((*i).m_light->rotation()));
- matrix4_translate_by_vec3(world2light, vector3_negated(lightBounds.origin)); // world->lightBounds
- }
- if (!(*i).m_light->isProjected()) {
- matrix4_translate_by_vec3(world2light, Vector3(0.5f, 0.5f, 0.5f));
- matrix4_scale_by_vec3(world2light, Vector3(0.5f, 0.5f, 0.5f));
- matrix4_scale_by_vec3(world2light,
- Vector3(1.0f / lightBounds.extents.x(), 1.0f / lightBounds.extents.y(),
- 1.0f / lightBounds.extents.z()));
- matrix4_multiply_by_matrix4(world2light, matrix4_transposed((*i).m_light->rotation()));
- matrix4_translate_by_vec3(world2light, vector3_negated(lightBounds.origin)); // world->lightBounds
- }
-
- current.m_program->setParameters(viewer, *(*i).m_transform, lightBounds.origin + (*i).m_light->offset(),
- (*i).m_light->colour(), world2light);
- debug_string("set lightBounds parameters");
- }
- }
-
- (*i).m_renderable->render(current.m_state);
- }
- glPopMatrix();
- renderables.clear();
-}
-
-void OpenGLStateBucket::render(OpenGLState ¤t, unsigned int globalstate, const Vector3 &viewer)
-{
- if ((globalstate & m_state.m_state & RENDER_SCREEN) != 0) {
- OpenGLState_apply(m_state, current, globalstate);
- debug_colour("screen fill");
+ debug_string( "disabled depth-buffer writing" );
+
+ GlobalOpenGL_debugAssertNoErrors();
+ }
+
+ if ( delta & state & RENDER_COLOURWRITE ) {
+ glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
+ GlobalOpenGL_debugAssertNoErrors();
+ }
+ else if ( delta & ~state & RENDER_COLOURWRITE ) {
+ glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
+ GlobalOpenGL_debugAssertNoErrors();
+ }
+
+ setState( state, delta, RENDER_ALPHATEST, GL_ALPHA_TEST );
+
+ if ( delta & state & RENDER_COLOURARRAY ) {
+ glEnableClientState( GL_COLOR_ARRAY );
+ GlobalOpenGL_debugAssertNoErrors();
+ debug_colour( "enabling color_array" );
+ g_colorArray_enabled = true;
+ }
+ else if ( delta & ~state & RENDER_COLOURARRAY ) {
+ glDisableClientState( GL_COLOR_ARRAY );
+ glColor4fv( vector4_to_array( self.m_colour ) );
+ debug_colour( "cleaning color_array" );
+ GlobalOpenGL_debugAssertNoErrors();
+ g_colorArray_enabled = false;
+ }
+
+ if ( delta & ~state & RENDER_COLOURCHANGE ) {
+ glColor4fv( vector4_to_array( self.m_colour ) );
+ GlobalOpenGL_debugAssertNoErrors();
+ }
+
+ setState( state, delta, RENDER_LINESTIPPLE, GL_LINE_STIPPLE );
+ setState( state, delta, RENDER_LINESMOOTH, GL_LINE_SMOOTH );
+
+ setState( state, delta, RENDER_POLYGONSTIPPLE, GL_POLYGON_STIPPLE );
+ setState( state, delta, RENDER_POLYGONSMOOTH, GL_POLYGON_SMOOTH );
+
+ setState( state, delta, RENDER_FOG, GL_FOG );
+
+ if ( ( state & RENDER_FOG ) != 0 ) {
+ setFogState( self.m_fog );
+ GlobalOpenGL_debugAssertNoErrors();
+ current.m_fog = self.m_fog;
+ }
+
+ if ( state & RENDER_DEPTHTEST && self.m_depthfunc != current.m_depthfunc ) {
+ glDepthFunc( self.m_depthfunc );
+ GlobalOpenGL_debugAssertNoErrors();
+ current.m_depthfunc = self.m_depthfunc;
+ }
+
+ if ( state & RENDER_LINESTIPPLE
+ && ( self.m_linestipple_factor != current.m_linestipple_factor
+ || self.m_linestipple_pattern != current.m_linestipple_pattern ) ) {
+ glLineStipple( self.m_linestipple_factor, self.m_linestipple_pattern );
+ GlobalOpenGL_debugAssertNoErrors();
+ current.m_linestipple_factor = self.m_linestipple_factor;
+ current.m_linestipple_pattern = self.m_linestipple_pattern;
+ }
+
+
+ if ( state & RENDER_ALPHATEST
+ && ( self.m_alphafunc != current.m_alphafunc
+ || self.m_alpharef != current.m_alpharef ) ) {
+ glAlphaFunc( self.m_alphafunc, self.m_alpharef );
+ GlobalOpenGL_debugAssertNoErrors();
+ current.m_alphafunc = self.m_alphafunc;
+ current.m_alpharef = self.m_alpharef;
+ }
+
+ {
+ GLint texture0 = 0;
+ GLint texture1 = 0;
+ GLint texture2 = 0;
+ GLint texture3 = 0;
+ GLint texture4 = 0;
+ GLint texture5 = 0;
+ GLint texture6 = 0;
+ GLint texture7 = 0;
+ //if(state & RENDER_TEXTURE) != 0)
+ {
+ texture0 = self.m_texture;
+ texture1 = self.m_texture1;
+ texture2 = self.m_texture2;
+ texture3 = self.m_texture3;
+ texture4 = self.m_texture4;
+ texture5 = self.m_texture5;
+ texture6 = self.m_texture6;
+ texture7 = self.m_texture7;
+ }
+
+ if ( GlobalOpenGL().GL_1_3() ) {
+ setTextureState( current.m_texture, texture0, GL_TEXTURE0 );
+ setTextureState( current.m_texture1, texture1, GL_TEXTURE1 );
+ setTextureState( current.m_texture2, texture2, GL_TEXTURE2 );
+ setTextureState( current.m_texture3, texture3, GL_TEXTURE3 );
+ setTextureState( current.m_texture4, texture4, GL_TEXTURE4 );
+ setTextureState( current.m_texture5, texture5, GL_TEXTURE5 );
+ setTextureState( current.m_texture6, texture6, GL_TEXTURE6 );
+ setTextureState( current.m_texture7, texture7, GL_TEXTURE7 );
+ }
+ else
+ {
+ setTextureState( current.m_texture, texture0 );
+ }
+ }
+
+
+ if ( state & RENDER_TEXTURE && self.m_colour[3] != current.m_colour[3] ) {
+ debug_colour( "setting alpha" );
+ glColor4f( 1,1,1,self.m_colour[3] );
+ GlobalOpenGL_debugAssertNoErrors();
+ }
+
+ if ( !( state & RENDER_TEXTURE )
+ && ( self.m_colour[0] != current.m_colour[0]
+ || self.m_colour[1] != current.m_colour[1]
+ || self.m_colour[2] != current.m_colour[2]
+ || self.m_colour[3] != current.m_colour[3] ) ) {
+ glColor4fv( vector4_to_array( self.m_colour ) );
+ debug_colour( "setting non-texture" );
+ GlobalOpenGL_debugAssertNoErrors();
+ }
+ current.m_colour = self.m_colour;
+
+ if ( state & RENDER_BLEND
+ && ( self.m_blend_src != current.m_blend_src || self.m_blend_dst != current.m_blend_dst ) ) {
+ glBlendFunc( self.m_blend_src, self.m_blend_dst );
+ GlobalOpenGL_debugAssertNoErrors();
+ current.m_blend_src = self.m_blend_src;
+ current.m_blend_dst = self.m_blend_dst;
+ }
+
+ if ( !( state & RENDER_FILL )
+ && self.m_linewidth != current.m_linewidth ) {
+ glLineWidth( self.m_linewidth );
+ GlobalOpenGL_debugAssertNoErrors();
+ current.m_linewidth = self.m_linewidth;
+ }
+
+ if ( !( state & RENDER_FILL )
+ && self.m_pointsize != current.m_pointsize ) {
+ glPointSize( self.m_pointsize );
+ GlobalOpenGL_debugAssertNoErrors();
+ current.m_pointsize = self.m_pointsize;
+ }
+
+ current.m_state = state;
+
+ GlobalOpenGL_debugAssertNoErrors();
+}
+
+void Renderables_flush( OpenGLStateBucket::Renderables& renderables, OpenGLState& current, unsigned int globalstate, const Vector3& viewer ){
+ const Matrix4* transform = 0;
+ glPushMatrix();
+ for ( OpenGLStateBucket::Renderables::const_iterator i = renderables.begin(); i != renderables.end(); ++i )
+ {
+ //qglLoadMatrixf(i->m_transform);
+ if ( !transform || ( transform != ( *i ).m_transform && !matrix4_affine_equal( *transform, *( *i ).m_transform ) ) ) {
+ count_transform();
+ transform = ( *i ).m_transform;
+ glPopMatrix();
+ glPushMatrix();
+ glMultMatrixf( reinterpret_cast<const float*>( transform ) );
+ glFrontFace( ( ( current.m_state & RENDER_CULLFACE ) != 0 && matrix4_handedness( *transform ) == MATRIX4_RIGHTHANDED ) ? GL_CW : GL_CCW );
+ }
+
+ count_prim();
+
+ if ( current.m_program != 0 && ( *i ).m_light != 0 ) {
+ const IShader& lightShader = static_cast<OpenGLShader*>( ( *i ).m_light->getShader() )->getShader();
+ if ( lightShader.firstLayer() != 0 ) {
+ GLuint attenuation_xy = lightShader.firstLayer()->texture()->texture_number;
+ GLuint attenuation_z = lightShader.lightFalloffImage() != 0
+ ? lightShader.lightFalloffImage()->texture_number
+ : static_cast<OpenGLShader*>( g_defaultPointLight )->getShader().lightFalloffImage()->texture_number;
+
+ setTextureState( current.m_texture3, attenuation_xy, GL_TEXTURE3 );
+ glActiveTexture( GL_TEXTURE3 );
+ glBindTexture( GL_TEXTURE_2D, attenuation_xy );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
+
+ setTextureState( current.m_texture4, attenuation_z, GL_TEXTURE4 );
+ glActiveTexture( GL_TEXTURE4 );
+ glBindTexture( GL_TEXTURE_2D, attenuation_z );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+
+
+ AABB lightBounds( ( *i ).m_light->aabb() );
+
+ Matrix4 world2light( g_matrix4_identity );
+
+ if ( ( *i ).m_light->isProjected() ) {
+ world2light = ( *i ).m_light->projection();
+ matrix4_multiply_by_matrix4( world2light, matrix4_transposed( ( *i ).m_light->rotation() ) );
+ matrix4_translate_by_vec3( world2light, vector3_negated( lightBounds.origin ) ); // world->lightBounds
+ }
+ if ( !( *i ).m_light->isProjected() ) {
+ matrix4_translate_by_vec3( world2light, Vector3( 0.5f, 0.5f, 0.5f ) );
+ matrix4_scale_by_vec3( world2light, Vector3( 0.5f, 0.5f, 0.5f ) );
+ matrix4_scale_by_vec3( world2light, Vector3( 1.0f / lightBounds.extents.x(), 1.0f / lightBounds.extents.y(), 1.0f / lightBounds.extents.z() ) );
+ matrix4_multiply_by_matrix4( world2light, matrix4_transposed( ( *i ).m_light->rotation() ) );
+ matrix4_translate_by_vec3( world2light, vector3_negated( lightBounds.origin ) ); // world->lightBounds
+ }
+
+ current.m_program->setParameters( viewer, *( *i ).m_transform, lightBounds.origin + ( *i ).m_light->offset(), ( *i ).m_light->colour(), world2light );
+ debug_string( "set lightBounds parameters" );
+ }
+ }
+
+ ( *i ).m_renderable->render( current.m_state );
+ }
+ glPopMatrix();
+ renderables.clear();
+}