diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 626ba5b1d2..9b99bd127d 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -145,11 +145,9 @@ reset() { _normals_enabled = false; //Color and alpha transform variables - _color_transform_enabled = false; - _alpha_transform_enabled = false; - _current_color_mat = LMatrix4f::ident_mat(); - _current_alpha_offset = 0; - _current_alpha_scale = 1; + _color_transform_enabled = 0; + _current_color_offset.set(0.0f, 0.0f, 0.0f, 0.0f); + _current_color_scale.set(1.0f, 1.0f, 1.0f, 1.0f); _color_write_mode = ColorWriteAttrib::M_on; _color_blend_mode = ColorBlendAttrib::M_none; @@ -674,27 +672,12 @@ issue_transform(const TransformState *) { //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: issue_color_scale(const ColorScaleAttrib *attrib) { - const LVecBase4f &scale = attrib->get_scale(); + _current_color_scale = attrib->get_scale(); - // For now, we set a full-featured matrix, even though we only use - // the scale part of it. Soon we will strip this down. - LVecBase3f color_scale(scale[0], scale[1], scale[2]); - float alpha_scale = scale[3]; - - _current_color_mat = LMatrix4f::scale_mat(color_scale); - _current_alpha_offset= 0.0f; - _current_alpha_scale = alpha_scale; - - if (color_scale == LVecBase3f(1.0f, 1.0f, 1.0f)) { - _color_transform_enabled = false; + if (_current_color_scale == LVecBase4f(1.0f, 1.0f, 1.0f, 1.0f)) { + _color_transform_enabled &= ~CT_scale; } else { - _color_transform_enabled = true; - } - - if (_current_alpha_scale == 1.0f) { - _alpha_transform_enabled = false; - } else { - _alpha_transform_enabled = true; + _color_transform_enabled |= CT_scale; } _scene_graph_color_stale = _has_scene_graph_color; diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index f5cb5af889..76c15bf83f 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -247,11 +247,13 @@ protected: bool _vertex_colors_enabled; bool _lighting_enabled; - bool _color_transform_enabled; - bool _alpha_transform_enabled; - LMatrix4f _current_color_mat; - float _current_alpha_offset; - float _current_alpha_scale; + enum ColorTransform { + CT_offset = 0x01, + CT_scale = 0x02, + }; + int _color_transform_enabled; // Zero or more of ColorTransform bits, above. + LVecBase4f _current_color_offset; + LVecBase4f _current_color_scale; ColorWriteAttrib::Mode _color_write_mode; ColorBlendAttrib::Mode _color_blend_mode; diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx index 3af666f6ce..929dbfc428 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx @@ -54,13 +54,6 @@ #include -// This is a temporary hack. The whole color_transform and -// alpha_transform system will soon be replaced with something a -// little smaller. Until then, we'll just define this macro to -// simulate the variable that used to be cached within the GSG. -#define _color_transform_required (_color_transform_enabled || _alpha_transform_enabled) - - // print out simple drawprim stats every few secs //#define COUNT_DRAWPRIMS @@ -515,14 +508,6 @@ dx_init( void) { #endif _pCurTexContext = NULL; - //Color and alpha transform variables - _color_transform_enabled = false; - _alpha_transform_enabled = false; - - _current_color_mat = LMatrix4f::ident_mat(); - _current_alpha_offset = 0; - _current_alpha_scale = 1; - // none of these are implemented //_multisample_enabled = false; //_point_smooth_enabled = false; @@ -1284,16 +1269,12 @@ typedef enum { INLINE void DXGraphicsStateGuardian:: transform_color(Colorf &InColor,D3DCOLOR &OutRGBAColor) { - // To be truly general, we really need a 5x5 matrix to transform a - // 4-component color. Rather than messing with that, we instead - // treat the color as a 3-component RGB, which can be transformed by - // the ordinary 4x4 matrix, and a separate alpha value, which can be - // scaled and offsetted. - - LPoint4f temp_pnt(InColor[0], InColor[1], InColor[2], 1.0f); - Colorf out_color = temp_pnt * _current_color_mat; // maybe expand this out for efficiency - out_color[3] = (InColor[3] * _current_alpha_scale) + _current_alpha_offset; - OutRGBAColor = Colorf_to_D3DCOLOR(out_color); + Colorf transformed + ((InColor[0] * _current_color_scale[0]) + _current_color_offset[0], + (InColor[1] * _current_color_scale[1]) + _current_color_offset[1], + (InColor[2] * _current_color_scale[2]) + _current_color_offset[2], + (InColor[3] * _current_color_scale[3]) + _current_color_offset[3]); + OutRGBAColor = Colorf_to_D3DCOLOR(InColor); } //////////////////////////////////////////////////////////////////// @@ -1318,7 +1299,7 @@ draw_prim_setup(const Geom *geom) { #define GET_NEXT_TEXCOORD() { p_texcoord = geom->get_next_texcoord(ti); } #define GET_NEXT_COLOR() { \ Colorf tempcolor = geom->get_next_color(ci); \ - if(!_color_transform_required) { \ + if(_color_transform_enabled == 0) { \ _curD3Dcolor = Colorf_to_D3DCOLOR(tempcolor); \ } else { \ transform_color(tempcolor,_curD3Dcolor); \ @@ -1355,10 +1336,10 @@ draw_prim_setup(const Geom *geom) { if (_has_scene_graph_color) { if (_scene_graph_color_stale) { // Compute the D3DCOLOR for the scene graph override color. - if(_color_transform_required) { - transform_color(_scene_graph_color, _scene_graph_color_D3DCOLOR); - } else { + if(_color_transform_enabled == 0) { _scene_graph_color_D3DCOLOR = Colorf_to_D3DCOLOR(_scene_graph_color); + } else { + transform_color(_scene_graph_color, _scene_graph_color_D3DCOLOR); } _scene_graph_color_stale = false; } @@ -1658,17 +1639,18 @@ draw_point(GeomPoint *geom, GeomContext *gc) { // BUGBUG: eventually this hack every-frame all-colors conversion needs // to be done only once as part of a vertex buffer - if(_color_transform_required) { - for (int i=0;iSetRenderState(D3DRS_EDGEANTIALIAS, false); @@ -1407,16 +1393,12 @@ typedef enum { INLINE void DXGraphicsStateGuardian:: transform_color(Colorf &InColor,D3DCOLOR &OutRGBAColor) { - // To be truly general, we really need a 5x5 matrix to transform a - // 4-component color. Rather than messing with that, we instead - // treat the color as a 3-component RGB, which can be transformed by - // the ordinary 4x4 matrix, and a separate alpha value, which can be - // scaled and offsetted. - - LPoint4f temp_pnt(InColor[0], InColor[1], InColor[2], 1.0f); - Colorf out_color = temp_pnt * _current_color_mat; // maybe expand this out for efficiency - out_color[3] = (InColor[3] * _current_alpha_scale) + _current_alpha_offset; - OutRGBAColor = Colorf_to_D3DCOLOR(out_color); + Colorf transformed + ((InColor[0] * _current_color_scale[0]) + _current_color_offset[0], + (InColor[1] * _current_color_scale[1]) + _current_color_offset[1], + (InColor[2] * _current_color_scale[2]) + _current_color_offset[2], + (InColor[3] * _current_color_scale[3]) + _current_color_offset[3]); + OutRGBAColor = Colorf_to_D3DCOLOR(InColor); } //////////////////////////////////////////////////////////////////// @@ -1441,7 +1423,7 @@ draw_prim_setup(const Geom *geom) { #define GET_NEXT_TEXCOORD() { p_texcoord = geom->get_next_texcoord(ti); } #define GET_NEXT_COLOR() { \ Colorf tempcolor = geom->get_next_color(ci); \ - if(!_color_transform_required) { \ + if(_color_transform_enabled == 0) { \ _curD3Dcolor = Colorf_to_D3DCOLOR(tempcolor); \ } else { \ transform_color(tempcolor,_curD3Dcolor); \ @@ -1478,10 +1460,10 @@ draw_prim_setup(const Geom *geom) { if (_has_scene_graph_color) { if (_scene_graph_color_stale) { // Compute the D3DCOLOR for the scene graph override color. - if(_color_transform_required) { - transform_color(_scene_graph_color, _scene_graph_color_D3DCOLOR); - } else { + if(_color_transform_enabled == 0) { _scene_graph_color_D3DCOLOR = Colorf_to_D3DCOLOR(_scene_graph_color); + } else { + transform_color(_scene_graph_color, _scene_graph_color_D3DCOLOR); } _scene_graph_color_stale = false; } diff --git a/panda/src/glgsg/glGraphicsStateGuardian.I b/panda/src/glgsg/glGraphicsStateGuardian.I index 4d11d7aeb2..ce1f49aff1 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.I +++ b/panda/src/glgsg/glGraphicsStateGuardian.I @@ -1000,43 +1000,12 @@ enable_polygon_offset(bool val) { } } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_current_color_mat -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &GLGraphicsStateGuardian:: -get_current_color_mat() const { - return _current_color_mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_current_alpha_offset -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const float &GLGraphicsStateGuardian:: -get_current_alpha_offset() const { - return _current_alpha_offset; -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_current_alpha_scale -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const float &GLGraphicsStateGuardian:: -get_current_alpha_scale() const { - return _current_alpha_scale; -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::get_light_id // Access: Public // Description: Convert index to gl light id //////////////////////////////////////////////////////////////////// -INLINE GLenum GLGraphicsStateGuardian::get_light_id(int index) const -{ +INLINE GLenum GLGraphicsStateGuardian::get_light_id(int index) const { return GL_LIGHT0 + index; } @@ -1047,20 +1016,7 @@ INLINE GLenum GLGraphicsStateGuardian::get_light_id(int index) const //////////////////////////////////////////////////////////////////// INLINE GLenum GLGraphicsStateGuardian:: get_clip_plane_id(int index) const { - switch(index) { - case 0: return GL_CLIP_PLANE0; - case 1: return GL_CLIP_PLANE1; - case 2: return GL_CLIP_PLANE2; - case 3: return GL_CLIP_PLANE3; - case 4: return GL_CLIP_PLANE4; - case 5: return GL_CLIP_PLANE5; - default: - glgsg_cat.error() - << "get_clip_plane_id() - we don't currently support ids " - << "> 5" << endl; - break; - } - return GL_CLIP_PLANE0; + return GL_CLIP_PLANE0 + index; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index 580599693d..be078a30a0 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -498,10 +498,9 @@ draw_point(GeomPoint *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -559,10 +558,9 @@ draw_line(GeomLine *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -628,10 +626,9 @@ draw_linestrip(GeomLinestrip *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -990,10 +987,9 @@ draw_polygon(GeomPolygon *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -1071,10 +1067,9 @@ draw_tri(GeomTri *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -1150,10 +1145,9 @@ draw_quad(GeomQuad *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -1228,10 +1222,9 @@ draw_tristrip(GeomTristrip *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -1327,10 +1320,9 @@ draw_trifan(GeomTrifan *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -1424,10 +1416,9 @@ draw_sphere(GeomSphere *geom, GeomContext *) { GeomIssuer::IssueColor *issue_color; - if (!_color_transform_enabled && !_alpha_transform_enabled) { + if (_color_transform_enabled == 0) { issue_color = issue_color_gl; - } - else { + } else { issue_color = issue_transformed_color_gl; } @@ -3361,22 +3352,12 @@ print_gfx_visual() { //////////////////////////////////////////////////////////////////// void GLGraphicsStateGuardian:: issue_transformed_color(const Colorf &color) const { - // To be truly general, we really need a 5x5 matrix to transform a - // 4-component color. Rather than messing with that, we instead - // treat the color as a 3-component RGB, which can be transformed by - // the ordinary 4x4 matrix, and a separate alpha value, which can be - // scaled and offsetted. - LPoint3f temp(color[0], color[1], color[2]); - temp = temp * get_current_color_mat(); - float alpha = (color[3] * get_current_alpha_scale()) + - get_current_alpha_offset(); + Colorf transformed + ((color[0] * _current_color_scale[0]) + _current_color_offset[0], + (color[1] * _current_color_scale[1]) + _current_color_offset[1], + (color[2] * _current_color_scale[2]) + _current_color_offset[2], + (color[3] * _current_color_scale[3]) + _current_color_offset[3]); - Colorf transformed(temp[0], temp[1], temp[2], alpha); - - // glgsg_cat.debug() << "Issuing color " << transformed << "\n"; - // glgsg_cat.debug() << "\tTransformed by " << get_current_color_mat() << "\n"; - // glgsg_cat.debug() << "\tAlpha Transformed by " << get_current_alpha_offset() << " " - // << get_current_alpha_scale() << "\n"; glColor4fv(transformed.get_data()); } diff --git a/panda/src/glgsg/glGraphicsStateGuardian.h b/panda/src/glgsg/glGraphicsStateGuardian.h index 6d60b52f85..eb363b0a64 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.h +++ b/panda/src/glgsg/glGraphicsStateGuardian.h @@ -144,11 +144,6 @@ public: //enabled/disable GL State compared to what GL says it is void dump_state(void); - //Methods for extracting the current color and alpha transformations - INLINE const LMatrix4f &get_current_color_mat() const; - INLINE const float &get_current_alpha_offset() const; - INLINE const float &get_current_alpha_scale() const; - void issue_transformed_color(const Colorf &color) const; protected: