diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 045c534ebe..a9ce3abbcb 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -1849,16 +1849,6 @@ setup_scene(GraphicsStateGuardian *gsg, DisplayRegionPipelineReader *dr) { CPT(TransformState) cs_world_transform = cs_transform->compose(world_transform); scene_setup->set_cs_world_transform(cs_world_transform); - // Make sure that the GSG has a ShaderGenerator for the munger to use. We - // have to do this here because the ShaderGenerator needs a host window - // pointer. Hopefully we'll be able to eliminate that requirement in the - // future. -#ifdef HAVE_CG - if (gsg->get_shader_generator() == NULL) { - gsg->set_shader_generator(new ShaderGenerator(gsg, window)); - } -#endif - return scene_setup; } diff --git a/panda/src/display/standardMunger.cxx b/panda/src/display/standardMunger.cxx index b6bc1ada2a..4b6aa01f67 100644 --- a/panda/src/display/standardMunger.cxx +++ b/panda/src/display/standardMunger.cxx @@ -344,11 +344,11 @@ munge_state_impl(const RenderState *state) { #ifdef HAVE_CG if (_auto_shader) { CPT(RenderState) shader_state = munged_state->get_auto_shader_state(); - ShaderGenerator *shader_generator = get_gsg()->get_shader_generator(); - if (shader_generator == NULL) { - pgraph_cat.error() - << "auto_shader enabled, but GSG has no shader generator assigned!\n"; - return munged_state; + GraphicsStateGuardian *gsg = get_gsg(); + ShaderGenerator *shader_generator = gsg->get_shader_generator(); + if (shader_generator == nullptr) { + shader_generator = new ShaderGenerator(gsg); + gsg->set_shader_generator(shader_generator); } if (shader_state->_generated_shader == NULL) { // Cache the generated ShaderAttrib on the shader state. diff --git a/panda/src/pgraph/geomNode.cxx b/panda/src/pgraph/geomNode.cxx index 7b850fafc6..11d319212f 100644 --- a/panda/src/pgraph/geomNode.cxx +++ b/panda/src/pgraph/geomNode.cxx @@ -15,6 +15,7 @@ #include "geom.h" #include "geomTransformer.h" #include "sceneGraphReducer.h" +#include "stateMunger.h" #include "accumulatedAttribs.h" #include "colorAttrib.h" #include "colorScaleAttrib.h" @@ -391,33 +392,32 @@ r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state, ((GeomPrimitive *)prim.p())->prepare(prepared_objects); } + if (munger->is_of_type(StateMunger::get_class_type())) { + StateMunger *state_munger = (StateMunger *)munger.p(); + geom_state = state_munger->munge_state(geom_state); + } + // And now prepare each of the textures. - const RenderAttrib *attrib = - geom_state->get_attrib(TextureAttrib::get_class_slot()); - if (attrib != (const RenderAttrib *)NULL) { - const TextureAttrib *ta; - DCAST_INTO_V(ta, attrib); + const TextureAttrib *ta; + if (geom_state->get_attrib(ta)) { int num_stages = ta->get_num_on_stages(); for (int i = 0; i < num_stages; ++i) { Texture *texture = ta->get_on_texture(ta->get_on_stage(i)); // TODO: prepare the sampler states, if specified. - if (texture != (Texture *)NULL) { + if (texture != nullptr) { texture->prepare(prepared_objects); } } } // As well as the shaders. - attrib = geom_state->get_attrib(ShaderAttrib::get_class_slot()); - if (attrib != (const RenderAttrib *)NULL) { - const ShaderAttrib *sa; - DCAST_INTO_V(sa, attrib); + const ShaderAttrib *sa; + if (geom_state->get_attrib(sa)) { Shader *shader = (Shader *)sa->get_shader(); - if (shader != (Shader *)NULL) { + if (shader != nullptr) { shader->prepare(prepared_objects); } - // TODO: prepare the shader inputs. TODO: Invoke the shader generator - // if enabled. + // TODO: prepare the shader inputs. } } diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 63973c6bc3..f5c15f136c 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -55,8 +55,8 @@ TypeHandle ShaderGenerator::_type_handle; * shader generator belongs. */ ShaderGenerator:: -ShaderGenerator(GraphicsStateGuardianBase *gsg, GraphicsOutputBase *host) : - _gsg(gsg), _host(host) { +ShaderGenerator(GraphicsStateGuardianBase *gsg) : + _gsg(gsg) { // The ATTR# input semantics seem to map to generic vertex attributes in // both arbvp1 and glslv, which behave more consistently. However, they diff --git a/panda/src/pgraphnodes/shaderGenerator.h b/panda/src/pgraphnodes/shaderGenerator.h index a1d83f0919..1fd597b215 100644 --- a/panda/src/pgraphnodes/shaderGenerator.h +++ b/panda/src/pgraphnodes/shaderGenerator.h @@ -60,7 +60,7 @@ class GeomVertexAnimationSpec; */ class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedReferenceCount { PUBLISHED: - ShaderGenerator(GraphicsStateGuardianBase *gsg, GraphicsOutputBase *host); + ShaderGenerator(GraphicsStateGuardianBase *gsg); virtual ~ShaderGenerator(); virtual CPT(ShaderAttrib) synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim); @@ -144,7 +144,6 @@ protected: // This is not a PT() to prevent a circular reference. GraphicsStateGuardianBase *_gsg; - GraphicsOutputBase *_host; public: static TypeHandle get_class_type() {