mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
ShaderGenerator: prepare_scene now invokes shader generator.
This also necessarily removes ShaderGenerator's dependency on a host window.
This commit is contained in:
parent
751299d65a
commit
b781995ef1
@ -1849,16 +1849,6 @@ setup_scene(GraphicsStateGuardian *gsg, DisplayRegionPipelineReader *dr) {
|
|||||||
CPT(TransformState) cs_world_transform = cs_transform->compose(world_transform);
|
CPT(TransformState) cs_world_transform = cs_transform->compose(world_transform);
|
||||||
scene_setup->set_cs_world_transform(cs_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;
|
return scene_setup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,11 +344,11 @@ munge_state_impl(const RenderState *state) {
|
|||||||
#ifdef HAVE_CG
|
#ifdef HAVE_CG
|
||||||
if (_auto_shader) {
|
if (_auto_shader) {
|
||||||
CPT(RenderState) shader_state = munged_state->get_auto_shader_state();
|
CPT(RenderState) shader_state = munged_state->get_auto_shader_state();
|
||||||
ShaderGenerator *shader_generator = get_gsg()->get_shader_generator();
|
GraphicsStateGuardian *gsg = get_gsg();
|
||||||
if (shader_generator == NULL) {
|
ShaderGenerator *shader_generator = gsg->get_shader_generator();
|
||||||
pgraph_cat.error()
|
if (shader_generator == nullptr) {
|
||||||
<< "auto_shader enabled, but GSG has no shader generator assigned!\n";
|
shader_generator = new ShaderGenerator(gsg);
|
||||||
return munged_state;
|
gsg->set_shader_generator(shader_generator);
|
||||||
}
|
}
|
||||||
if (shader_state->_generated_shader == NULL) {
|
if (shader_state->_generated_shader == NULL) {
|
||||||
// Cache the generated ShaderAttrib on the shader state.
|
// Cache the generated ShaderAttrib on the shader state.
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "geom.h"
|
#include "geom.h"
|
||||||
#include "geomTransformer.h"
|
#include "geomTransformer.h"
|
||||||
#include "sceneGraphReducer.h"
|
#include "sceneGraphReducer.h"
|
||||||
|
#include "stateMunger.h"
|
||||||
#include "accumulatedAttribs.h"
|
#include "accumulatedAttribs.h"
|
||||||
#include "colorAttrib.h"
|
#include "colorAttrib.h"
|
||||||
#include "colorScaleAttrib.h"
|
#include "colorScaleAttrib.h"
|
||||||
@ -391,33 +392,32 @@ r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state,
|
|||||||
((GeomPrimitive *)prim.p())->prepare(prepared_objects);
|
((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.
|
// And now prepare each of the textures.
|
||||||
const RenderAttrib *attrib =
|
const TextureAttrib *ta;
|
||||||
geom_state->get_attrib(TextureAttrib::get_class_slot());
|
if (geom_state->get_attrib(ta)) {
|
||||||
if (attrib != (const RenderAttrib *)NULL) {
|
|
||||||
const TextureAttrib *ta;
|
|
||||||
DCAST_INTO_V(ta, attrib);
|
|
||||||
int num_stages = ta->get_num_on_stages();
|
int num_stages = ta->get_num_on_stages();
|
||||||
for (int i = 0; i < num_stages; ++i) {
|
for (int i = 0; i < num_stages; ++i) {
|
||||||
Texture *texture = ta->get_on_texture(ta->get_on_stage(i));
|
Texture *texture = ta->get_on_texture(ta->get_on_stage(i));
|
||||||
// TODO: prepare the sampler states, if specified.
|
// TODO: prepare the sampler states, if specified.
|
||||||
if (texture != (Texture *)NULL) {
|
if (texture != nullptr) {
|
||||||
texture->prepare(prepared_objects);
|
texture->prepare(prepared_objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// As well as the shaders.
|
// As well as the shaders.
|
||||||
attrib = geom_state->get_attrib(ShaderAttrib::get_class_slot());
|
const ShaderAttrib *sa;
|
||||||
if (attrib != (const RenderAttrib *)NULL) {
|
if (geom_state->get_attrib(sa)) {
|
||||||
const ShaderAttrib *sa;
|
|
||||||
DCAST_INTO_V(sa, attrib);
|
|
||||||
Shader *shader = (Shader *)sa->get_shader();
|
Shader *shader = (Shader *)sa->get_shader();
|
||||||
if (shader != (Shader *)NULL) {
|
if (shader != nullptr) {
|
||||||
shader->prepare(prepared_objects);
|
shader->prepare(prepared_objects);
|
||||||
}
|
}
|
||||||
// TODO: prepare the shader inputs. TODO: Invoke the shader generator
|
// TODO: prepare the shader inputs.
|
||||||
// if enabled.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +55,8 @@ TypeHandle ShaderGenerator::_type_handle;
|
|||||||
* shader generator belongs.
|
* shader generator belongs.
|
||||||
*/
|
*/
|
||||||
ShaderGenerator::
|
ShaderGenerator::
|
||||||
ShaderGenerator(GraphicsStateGuardianBase *gsg, GraphicsOutputBase *host) :
|
ShaderGenerator(GraphicsStateGuardianBase *gsg) :
|
||||||
_gsg(gsg), _host(host) {
|
_gsg(gsg) {
|
||||||
|
|
||||||
// The ATTR# input semantics seem to map to generic vertex attributes in
|
// The ATTR# input semantics seem to map to generic vertex attributes in
|
||||||
// both arbvp1 and glslv, which behave more consistently. However, they
|
// both arbvp1 and glslv, which behave more consistently. However, they
|
||||||
|
@ -60,7 +60,7 @@ class GeomVertexAnimationSpec;
|
|||||||
*/
|
*/
|
||||||
class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedReferenceCount {
|
class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedReferenceCount {
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
ShaderGenerator(GraphicsStateGuardianBase *gsg, GraphicsOutputBase *host);
|
ShaderGenerator(GraphicsStateGuardianBase *gsg);
|
||||||
virtual ~ShaderGenerator();
|
virtual ~ShaderGenerator();
|
||||||
virtual CPT(ShaderAttrib) synthesize_shader(const RenderState *rs,
|
virtual CPT(ShaderAttrib) synthesize_shader(const RenderState *rs,
|
||||||
const GeomVertexAnimationSpec &anim);
|
const GeomVertexAnimationSpec &anim);
|
||||||
@ -144,7 +144,6 @@ protected:
|
|||||||
|
|
||||||
// This is not a PT() to prevent a circular reference.
|
// This is not a PT() to prevent a circular reference.
|
||||||
GraphicsStateGuardianBase *_gsg;
|
GraphicsStateGuardianBase *_gsg;
|
||||||
GraphicsOutputBase *_host;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user