New error checking for missing ShaderInput

This commit is contained in:
Josh Yelon 2007-11-12 06:26:25 +00:00
parent 2f42e29cf7
commit 91f0ffed00
4 changed files with 102 additions and 44 deletions

View File

@ -886,15 +886,13 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
return &t;
}
case ShaderExpansion::SMO_mat_constant_x: {
const ShaderInput *input = _target._shader->get_shader_input(name);
if (input->get_nodepath().is_empty()) {
return &LMatrix4f::ident_mat();
}
return &(input->get_nodepath().node()->get_transform()->get_mat());
const NodePath &np = _target._shader->get_shader_input_nodepath(name);
nassertr(!np.is_empty(), &LMatrix4f::ident_mat());
return &(np.node()->get_transform()->get_mat());
}
case ShaderExpansion::SMO_vec_constant_x: {
const ShaderInput *input = _target._shader->get_shader_input(name);
const float *data = input->get_vector().get_data();
const LVector4f &input = _target._shader->get_shader_input_vector(name);
const float *data = input.get_data();
t = LMatrix4f(data[0],data[1],data[2],data[3],
data[0],data[1],data[2],data[3],
data[0],data[1],data[2],data[3],
@ -949,67 +947,51 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
return &t;
}
case ShaderExpansion::SMO_view_x_to_view: {
const ShaderInput *input = _target._shader->get_shader_input(name);
if (input->get_nodepath().is_empty()) {
gsg_cat.error()
<< "SHADER INPUT ASSERT: "
<< name
<< "\n";
}
nassertr(!input->get_nodepath().is_empty(), &LMatrix4f::ident_mat());
t = input->get_nodepath().get_net_transform()->get_mat() *
const NodePath &np = _target._shader->get_shader_input_nodepath(name);
nassertr(!np.is_empty(), &LMatrix4f::ident_mat());
t = np.get_net_transform()->get_mat() *
get_scene()->get_world_transform()->get_mat();
return &t;
}
case ShaderExpansion::SMO_view_to_view_x: {
const ShaderInput *input = _target._shader->get_shader_input(name);
if (input->get_nodepath().is_empty()) {
gsg_cat.error()
<< "SHADER INPUT ASSERT: "
<< name
<< "\n";
}
nassertr(!input->get_nodepath().is_empty(), &LMatrix4f::ident_mat());
const NodePath &np = _target._shader->get_shader_input_nodepath(name);
nassertr(!np.is_empty(), &LMatrix4f::ident_mat());
t = get_scene()->get_camera_transform()->get_mat() *
invert(input->get_nodepath().get_net_transform()->get_mat());
invert(np.get_net_transform()->get_mat());
return &t;
}
case ShaderExpansion::SMO_apiview_x_to_view: {
const ShaderInput *input = _target._shader->get_shader_input(name);
nassertr(!input->get_nodepath().is_empty(), &LMatrix4f::ident_mat());
const NodePath &np = _target._shader->get_shader_input_nodepath(name);
nassertr(!np.is_empty(), &LMatrix4f::ident_mat());
t = LMatrix4f::convert_mat(_internal_coordinate_system, _coordinate_system) *
input->get_nodepath().get_net_transform()->get_mat() *
np.get_net_transform()->get_mat() *
get_scene()->get_world_transform()->get_mat();
return &t;
}
case ShaderExpansion::SMO_view_to_apiview_x: {
const ShaderInput *input = _target._shader->get_shader_input(name);
nassertr(!input->get_nodepath().is_empty(), &LMatrix4f::ident_mat());
const NodePath &np = _target._shader->get_shader_input_nodepath(name);
nassertr(!np.is_empty(), &LMatrix4f::ident_mat());
t = (get_scene()->get_camera_transform()->get_mat() *
invert(input->get_nodepath().get_net_transform()->get_mat()) *
invert(np.get_net_transform()->get_mat()) *
LMatrix4f::convert_mat(_coordinate_system, _internal_coordinate_system));
return &t;
}
case ShaderExpansion::SMO_clip_x_to_view: {
const ShaderInput *input = _target._shader->get_shader_input(name);
nassertr(!input->get_nodepath().is_empty(), &LMatrix4f::ident_mat());
Lens *lens = DCAST(LensNode, input->get_nodepath().node())->get_lens();
const NodePath &np = _target._shader->get_shader_input_nodepath(name);
nassertr(!np.is_empty(), &LMatrix4f::ident_mat());
Lens *lens = DCAST(LensNode, np.node())->get_lens();
t = lens->get_projection_mat_inv(_current_stereo_channel) *
LMatrix4f::convert_mat(lens->get_coordinate_system(), _coordinate_system) *
input->get_nodepath().get_net_transform()->get_mat() *
np.get_net_transform()->get_mat() *
get_scene()->get_world_transform()->get_mat();
return &t;
}
case ShaderExpansion::SMO_view_to_clip_x: {
const ShaderInput *input = _target._shader->get_shader_input(name);
nassertr(!input->get_nodepath().is_empty(), &LMatrix4f::ident_mat());
Lens *lens = DCAST(LensNode, input->get_nodepath().node())->get_lens();
const NodePath &np = _target._shader->get_shader_input_nodepath(name);
nassertr(!np.is_empty(), &LMatrix4f::ident_mat());
Lens *lens = DCAST(LensNode, np.node())->get_lens();
t = get_scene()->get_camera_transform()->get_mat() *
invert(input->get_nodepath().get_net_transform()->get_mat()) *
invert(np.get_net_transform()->get_mat()) *
LMatrix4f::convert_mat(_coordinate_system, lens->get_coordinate_system()) *
lens->get_projection_mat(_current_stereo_channel);
return &t;

View File

@ -257,6 +257,78 @@ get_shader_input(const string &id) const {
return get_shader_input(InternalName::make(id));
}
////////////////////////////////////////////////////////////////////
// Function: ShaderAttrib::get_shader_input_nodepath
// Access: Published
// Description: Returns the ShaderInput as a nodepath. Assertion
// fails if there is none, or if it is not a nodepath.
////////////////////////////////////////////////////////////////////
const NodePath &ShaderAttrib::
get_shader_input_nodepath(InternalName *id) const {
static NodePath resfail;
Inputs::const_iterator i = _inputs.find(id);
if (i == _inputs.end()) {
pgraph_cat.error() << "Shader input " << id->get_name() << " is not present.\n";
nassertr(false, resfail);
} else {
const ShaderInput *p = (*i).second;
if (p->get_value_type() != ShaderInput::M_nodepath) {
pgraph_cat.error() << "Shader input " << id->get_name() << " is not a nodepath.\n";
nassertr(false, resfail);
}
return p->get_nodepath();
}
}
////////////////////////////////////////////////////////////////////
// Function: ShaderAttrib::get_shader_input_vector
// Access: Published
// Description: Returns the ShaderInput as a vector. Assertion
// fails if there is none, or if it is not a vector.
////////////////////////////////////////////////////////////////////
const LVector4f &ShaderAttrib::
get_shader_input_vector(InternalName *id) const {
static LVector4f resfail(0,0,0,0);
Inputs::const_iterator i = _inputs.find(id);
if (i == _inputs.end()) {
pgraph_cat.error() << "Shader input " << id->get_name() << " is not present.\n";
nassertr(false, resfail);
return resfail;
} else {
const ShaderInput *p = (*i).second;
if (p->get_value_type() != ShaderInput::M_vector) {
pgraph_cat.error() << "Shader input " << id->get_name() << " is not a vector.\n";
nassertr(false, resfail);
return resfail;
}
return p->get_vector();
}
}
////////////////////////////////////////////////////////////////////
// Function: ShaderAttrib::get_shader_input_texture
// Access: Published
// Description: Returns the ShaderInput as a texture. Assertion
// fails if there is none, or if it is not a texture.
////////////////////////////////////////////////////////////////////
Texture *ShaderAttrib::
get_shader_input_texture(InternalName *id) const {
Inputs::const_iterator i = _inputs.find(id);
if (i == _inputs.end()) {
pgraph_cat.error() << "Shader input " << id->get_name() << " is not present.\n";
nassertr(false, NULL);
return NULL;
} else {
const ShaderInput *p = (*i).second;
if (p->get_value_type() != ShaderInput::M_texture) {
pgraph_cat.error() << "Shader input " << id->get_name() << " is not a texture.\n";
nassertr(false, NULL);
return NULL;
}
return p->get_texture();
}
}
////////////////////////////////////////////////////////////////////
// Function: ShaderAttrib::get_shader
// Access: Published

View File

@ -64,6 +64,10 @@ PUBLISHED:
const ShaderInput *get_shader_input(InternalName *id) const;
const ShaderInput *get_shader_input(const string &id) const;
const NodePath &get_shader_input_nodepath(InternalName *id) const;
const LVector4f &get_shader_input_vector(InternalName *id) const;
Texture* get_shader_input_texture(InternalName *id) const;
static void register_with_read_factory();
public: