Modifications to eliminate class ShaderExpansion

This commit is contained in:
Josh Yelon 2007-12-13 20:56:29 +00:00
parent 7cd589972f
commit d8e6dc13a3
30 changed files with 440 additions and 748 deletions

View File

@ -1603,7 +1603,7 @@ TargetAdd('pgraph_composite1.obj', opts=OPTS, input='pgraph_composite1.cxx')
TargetAdd('pgraph_composite2.obj', opts=OPTS, input='pgraph_composite2.cxx')
TargetAdd('pgraph_composite3.obj', opts=OPTS, input='pgraph_composite3.cxx')
TargetAdd('pgraph_composite4.obj', opts=OPTS, input='pgraph_composite4.cxx')
IGATEFILES=GetDirectoryContents('panda/src/pgraph', ["*.h", "*_composite.cxx"])
IGATEFILES=GetDirectoryContents('panda/src/pgraph', ["*.h", "nodePath.cxx", "*_composite.cxx"])
# IGATEFILES.remove("antialiasAttrib.h")
TargetAdd('libpgraph.in', opts=OPTS, input=IGATEFILES)
TargetAdd('libpgraph.in', opts=['IMOD:panda', 'ILIB:libpgraph', 'SRCDIR:panda/src/pgraph'])

View File

@ -523,7 +523,7 @@ release_geom(GeomContext *) {
// Description: Compile a vertex/fragment shader body.
////////////////////////////////////////////////////////////////////
ShaderContext *GraphicsStateGuardian::
prepare_shader(ShaderExpansion *shader) {
prepare_shader(Shader *shader) {
return (ShaderContext *)NULL;
}
@ -819,7 +819,7 @@ clear(DrawableRegion *clearable) {
//
////////////////////////////////////////////////////////////////////
const LMatrix4f *GraphicsStateGuardian::
fetch_specified_value(ShaderExpansion::ShaderMatSpec &spec, bool altered) {
fetch_specified_value(Shader::ShaderMatSpec &spec, bool altered) {
static LMatrix4f acc;
const LMatrix4f *val1;
const LMatrix4f *val2;
@ -827,26 +827,26 @@ fetch_specified_value(ShaderExpansion::ShaderMatSpec &spec, bool altered) {
static LMatrix4f t2;
switch(spec._func) {
case ShaderExpansion::SMF_compose:
case Shader::SMF_compose:
val1 = fetch_specified_part(spec._part[0], spec._arg[0], t1);
val2 = fetch_specified_part(spec._part[1], spec._arg[1], t2);
acc.multiply(*val1, *val2);
return &acc;
case ShaderExpansion::SMF_compose_cache_first:
case Shader::SMF_compose_cache_first:
if (altered) {
spec._cache = *fetch_specified_part(spec._part[0], spec._arg[0], t1);
}
val2 = fetch_specified_part(spec._part[1], spec._arg[1], t2);
acc.multiply(spec._cache, *val2);
return &acc;
case ShaderExpansion::SMF_compose_cache_second:
case Shader::SMF_compose_cache_second:
if (altered) {
spec._cache = *fetch_specified_part(spec._part[1], spec._arg[1], t2);
}
val1 = fetch_specified_part(spec._part[0], spec._arg[0], t1);
acc.multiply(*val1, spec._cache);
return &acc;
case ShaderExpansion::SMF_first:
case Shader::SMF_first:
return fetch_specified_part(spec._part[0], spec._arg[0], t1);
default:
// should never get here
@ -860,24 +860,24 @@ fetch_specified_value(ShaderExpansion::ShaderMatSpec &spec, bool altered) {
// Description: See fetch_specified_value
////////////////////////////////////////////////////////////////////
const LMatrix4f *GraphicsStateGuardian::
fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, LMatrix4f &t) {
fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, LMatrix4f &t) {
switch(part) {
case ShaderExpansion::SMO_identity: {
case Shader::SMO_identity: {
return &LMatrix4f::ident_mat();
}
case ShaderExpansion::SMO_window_size: {
case Shader::SMO_window_size: {
t = LMatrix4f::translate_mat(_current_display_region->get_pixel_width(),
_current_display_region->get_pixel_height(),
0.0);
return &t;
}
case ShaderExpansion::SMO_pixel_size: {
case Shader::SMO_pixel_size: {
t = LMatrix4f::translate_mat(_current_display_region->get_pixel_width(),
_current_display_region->get_pixel_height(),
0.0);
return &t;
}
case ShaderExpansion::SMO_card_center: {
case Shader::SMO_card_center: {
int px = _current_display_region->get_pixel_width();
int py = _current_display_region->get_pixel_height();
t = LMatrix4f::translate_mat((px*0.5) / Texture::up_to_power_2(px),
@ -885,12 +885,12 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
0.0);
return &t;
}
case ShaderExpansion::SMO_mat_constant_x: {
case Shader::SMO_mat_constant_x: {
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: {
case Shader::SMO_vec_constant_x: {
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],
@ -899,28 +899,28 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
data[0],data[1],data[2],data[3]);
return &t;
}
case ShaderExpansion::SMO_world_to_view: {
case Shader::SMO_world_to_view: {
return &(get_scene()->get_world_transform()->get_mat());
break;
}
case ShaderExpansion::SMO_view_to_world: {
case Shader::SMO_view_to_world: {
return &(get_scene()->get_camera_transform()->get_mat());
}
case ShaderExpansion::SMO_model_to_view: {
case Shader::SMO_model_to_view: {
return &(get_external_transform()->get_mat());
}
case ShaderExpansion::SMO_view_to_model: {
case Shader::SMO_view_to_model: {
// DANGER: SLOW AND NOT CACHEABLE!
t.invert_from(get_external_transform()->get_mat());
return &t;
}
case ShaderExpansion::SMO_apiview_to_view: {
case Shader::SMO_apiview_to_view: {
return &(_inv_cs_transform->get_mat());
}
case ShaderExpansion::SMO_view_to_apiview: {
case Shader::SMO_view_to_apiview: {
return &(_cs_transform->get_mat());
}
case ShaderExpansion::SMO_clip_to_view: {
case Shader::SMO_clip_to_view: {
if (_current_lens->get_coordinate_system() == _coordinate_system) {
return &(_current_lens->get_projection_mat_inv(_current_stereo_channel));
} else {
@ -929,7 +929,7 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
return &t;
}
}
case ShaderExpansion::SMO_view_to_clip: {
case Shader::SMO_view_to_clip: {
if (_current_lens->get_coordinate_system() == _coordinate_system) {
return &(_current_lens->get_projection_mat(_current_stereo_channel));
} else {
@ -938,29 +938,29 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
return &t;
}
}
case ShaderExpansion::SMO_apiclip_to_view: {
case Shader::SMO_apiclip_to_view: {
t = _projection_mat_inv->get_mat() * _inv_cs_transform->get_mat();
return &t;
}
case ShaderExpansion::SMO_view_to_apiclip: {
case Shader::SMO_view_to_apiclip: {
t = _cs_transform->get_mat() * _projection_mat->get_mat();
return &t;
}
case ShaderExpansion::SMO_view_x_to_view: {
case Shader::SMO_view_x_to_view: {
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: {
case Shader::SMO_view_to_view_x: {
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(np.get_net_transform()->get_mat());
return &t;
}
case ShaderExpansion::SMO_apiview_x_to_view: {
case Shader::SMO_apiview_x_to_view: {
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) *
@ -968,7 +968,7 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
get_scene()->get_world_transform()->get_mat();
return &t;
}
case ShaderExpansion::SMO_view_to_apiview_x: {
case Shader::SMO_view_to_apiview_x: {
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() *
@ -976,7 +976,7 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
LMatrix4f::convert_mat(_coordinate_system, _internal_coordinate_system));
return &t;
}
case ShaderExpansion::SMO_clip_x_to_view: {
case Shader::SMO_clip_x_to_view: {
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();
@ -986,7 +986,7 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
get_scene()->get_world_transform()->get_mat();
return &t;
}
case ShaderExpansion::SMO_view_to_clip_x: {
case Shader::SMO_view_to_clip_x: {
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();
@ -996,11 +996,11 @@ fetch_specified_part(ShaderExpansion::ShaderMatInput part, InternalName *name, L
lens->get_projection_mat(_current_stereo_channel);
return &t;
}
case ShaderExpansion::SMO_apiclip_x_to_view: {
case Shader::SMO_apiclip_x_to_view: {
// NOT IMPLEMENTED
return &LMatrix4f::ident_mat();
}
case ShaderExpansion::SMO_view_to_apiclip_x: {
case Shader::SMO_view_to_apiclip_x: {
// NOT IMPLEMENTED
return &LMatrix4f::ident_mat();
}

View File

@ -166,7 +166,7 @@ public:
virtual GeomContext *prepare_geom(Geom *geom);
virtual void release_geom(GeomContext *gc);
virtual ShaderContext *prepare_shader(ShaderExpansion *shader);
virtual ShaderContext *prepare_shader(Shader *shader);
virtual void release_shader(ShaderContext *sc);
virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data);
@ -195,8 +195,8 @@ public:
void clear(DrawableRegion *clearable);
const LMatrix4f *fetch_specified_value(ShaderExpansion::ShaderMatSpec &spec, bool altered);
const LMatrix4f *fetch_specified_part(ShaderExpansion::ShaderMatInput input, InternalName *name, LMatrix4f &t);
const LMatrix4f *fetch_specified_value(Shader::ShaderMatSpec &spec, bool altered);
const LMatrix4f *fetch_specified_part(Shader::ShaderMatInput input, InternalName *name, LMatrix4f &t);
virtual void prepare_display_region(DisplayRegionPipelineReader *dr,
Lens::StereoChannel stereo_channel);
@ -418,7 +418,7 @@ protected:
static PT(TextureStage) _alpha_scale_texture_stage;
ShaderExpansion::ShaderCaps _shader_caps;
Shader::ShaderCaps _shader_caps;
float _gamma;

View File

@ -351,7 +351,7 @@ release_texture(TextureContext *tc) {
// Description:
////////////////////////////////////////////////////////////////////
ShaderContext *DXGraphicsStateGuardian9::
prepare_shader(ShaderExpansion *se) {
prepare_shader(Shader *se) {
#ifdef HAVE_CG
CLP(ShaderContext) *result = new CLP(ShaderContext)(se, this);
return result;
@ -1272,7 +1272,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
update_shader_vertex_arrays(_vertex_array_shader_context,this);
}
}
_vertex_array_shader_expansion = _current_shader_expansion;
_vertex_array_shader = _current_shader;
_vertex_array_shader_context = _current_shader_context;
const GeomVertexFormat *format = _data_reader->get_format ( );
@ -3016,11 +3016,11 @@ reset() {
// must check (_screen->_d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_BLENDOP) (yes on GF2/Radeon8500, no on TNT)
set_render_state(D3DRS_BLENDOP, D3DBLENDOP_ADD);
_current_shader_expansion = (ShaderExpansion *)NULL;
_current_shader = (Shader *)NULL;
_current_shader_context = (CLP(ShaderContext) *)NULL;
_vertex_array_shader_expansion = (ShaderExpansion *)NULL;
_vertex_array_shader = (Shader *)NULL;
_vertex_array_shader_context = (CLP(ShaderContext) *)NULL;
_texture_binding_shader_expansion = (ShaderExpansion *)NULL;
_texture_binding_shader = (Shader *)NULL;
_texture_binding_shader_context = (CLP(ShaderContext) *)NULL;
PRINT_REFCNT(dxgsg9, _d3d_device);
@ -3157,25 +3157,21 @@ do_issue_shader() {
DBG_SH3 dxgsg9_cat.debug ( ) << "SHADER: do_issue_shader\n"; DBG_E
CLP(ShaderContext) *context = 0;
ShaderExpansion *expansion = _target_rs->get_shader_expansion();
if (expansion == 0) {
if (_target._shader->get_shader() != 0) {
expansion = _target._shader->get_shader()->macroexpand(_target_rs, _shader_caps);
// I am casting away the const-ness of this pointer, because
// the 'shader-expansion' field is just a cache.
((RenderState *)((const RenderState*)_target_rs))->
set_shader_expansion(expansion);
}
const ShaderAttrib *attr = _target_rs->get_generated_shader();
if (attr == 0) {
attr = _target._shader;
// if (attr is auto) then generate a shader.
// store that shader using set_generated_shader.
}
if (expansion) {
context = (CLP(ShaderContext) *)(expansion->prepare_now(get_prepared_objects(), this));
Shader *shader = (Shader *)(attr->get_shader());
if (shader) {
context = (CLP(ShaderContext) *)(shader->prepare_now(get_prepared_objects(), this));
}
if (context == 0 || (context && context -> valid (this) == false)) {
if (_current_shader_context != 0) {
_current_shader_context->unbind(this);
_current_shader_expansion = 0;
_current_shader = 0;
_current_shader_context = 0;
disable_standard_texture_bindings();
}
@ -3188,12 +3184,12 @@ do_issue_shader() {
if (_current_shader_context != 0) {
_current_shader_context->unbind(this);
_current_shader_context = 0;
_current_shader_expansion = 0;
_current_shader = 0;
disable_standard_texture_bindings();
}
if (context != 0) {
context->bind(this);
_current_shader_expansion = expansion;
_current_shader = shader;
_current_shader_context = context;
}
} else {
@ -3822,7 +3818,7 @@ do_issue_texture() {
update_shader_texture_bindings(_texture_binding_shader_context,this);
}
}
_texture_binding_shader_expansion = _current_shader_expansion;
_texture_binding_shader = _current_shader;
_texture_binding_shader_context = _current_shader_context;
}

View File

@ -89,7 +89,7 @@ public:
void apply_texture(int i, TextureContext *tc);
virtual void release_texture(TextureContext *tc);
ShaderContext *prepare_shader(ShaderExpansion *se);
ShaderContext *prepare_shader(Shader *se);
void release_shader(ShaderContext *sc);
virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data);
@ -302,11 +302,11 @@ protected:
CullFaceAttrib::Mode _cull_face_mode;
RenderModeAttrib::Mode _current_fill_mode; //point/wireframe/solid
PT(ShaderExpansion) _current_shader_expansion;
PT(Shader) _current_shader;
CLP(ShaderContext) *_current_shader_context;
PT(ShaderExpansion) _vertex_array_shader_expansion;
PT(Shader) _vertex_array_shader;
CLP(ShaderContext) *_vertex_array_shader_context;
PT(ShaderExpansion) _texture_binding_shader_expansion;
PT(Shader) _texture_binding_shader;
CLP(ShaderContext) *_texture_binding_shader_context;
const DXVertexBufferContext9 *_active_vbuffer;

View File

@ -39,16 +39,16 @@ TypeHandle CLP(ShaderContext)::_type_handle;
// Description: xyz
////////////////////////////////////////////////////////////////////
CLP(ShaderContext)::
CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
CLP(ShaderContext)(Shader *s, GSG *gsg) : ShaderContext(s) {
_vertex_size = 0;
_vertex_element_array = 0;
_name = s->get_name ( );
_name = s->get_filename ( );
#ifdef HAVE_CG
if (s->get_header() == "//Cg") {
// Ask the shader expansion to compile itself for us and
// Ask the shader to compile itself for us and
// to give us the resulting Cg program objects.
if (!s->cg_compile_for(gsg->_shader_caps,
@ -277,7 +277,7 @@ unbind(GSG *gsg) {
// Function: DXShaderContext9::issue_parameters
// Access: Public
// Description: This function gets called whenever the RenderState
// or TransformState has changed, but the ShaderExpansion
// or TransformState has changed, but the Shader
// itself has not changed. It loads new values into the
// shader's parameters.
//
@ -301,13 +301,13 @@ issue_parameters(GSG *gsg, bool altered)
{
#ifdef HAVE_CG
if (_cg_context) {
for (int i=0; i<(int)_expansion->_mat_spec.size(); i++) {
if (altered || _expansion->_mat_spec[i]._trans_dependent) {
CGparameter p = _cg_parameter_map[_expansion->_mat_spec[i]._id._seqno];
for (int i=0; i<(int)_shader->_mat_spec.size(); i++) {
if (altered || _shader->_mat_spec[i]._trans_dependent) {
CGparameter p = _cg_parameter_map[_shader->_mat_spec[i]._id._seqno];
if (p == NULL) {
continue;
}
const LMatrix4f *val = gsg->fetch_specified_value(_expansion->_mat_spec[i], altered);
const LMatrix4f *val = gsg->fetch_specified_value(_shader->_mat_spec[i], altered);
if (val) {
HRESULT hr;
float v [4];
@ -322,13 +322,13 @@ issue_parameters(GSG *gsg, bool altered)
#if DEBUG_SHADER
// DEBUG
global_data = (float *) data;
global_shader_mat_spec = &_expansion->_mat_spec[i];
global_shader_mat_spec = &_shader->_mat_spec[i];
global_internal_name_0 = global_shader_mat_spec -> _arg [0];
global_internal_name_1 = global_shader_mat_spec -> _arg [1];
#endif
switch (_expansion->_mat_spec[i]._piece) {
case ShaderExpansion::SMP_whole:
switch (_shader->_mat_spec[i]._piece) {
case Shader::SMP_whole:
// TRANSPOSE REQUIRED
temp_matrix.transpose_from (*val);
data = temp_matrix.get_data();
@ -336,7 +336,7 @@ issue_parameters(GSG *gsg, bool altered)
hr = cgD3D9SetUniform (p, data);
DBG_SH2
dxgsg9_cat.debug ( ) << "ShaderExpansion::SMP_whole MATRIX \n" <<
dxgsg9_cat.debug ( ) << "Shader::SMP_whole MATRIX \n" <<
data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" <<
data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" <<
data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" <<
@ -345,44 +345,44 @@ issue_parameters(GSG *gsg, bool altered)
break;
case ShaderExpansion::SMP_transpose:
case Shader::SMP_transpose:
// NO TRANSPOSE REQUIRED
hr = cgD3D9SetUniform (p, data);
break;
case ShaderExpansion::SMP_row0:
case Shader::SMP_row0:
hr = cgD3D9SetUniform (p, data + 0);
break;
case ShaderExpansion::SMP_row1:
case Shader::SMP_row1:
hr = cgD3D9SetUniform (p, data + 4);
break;
case ShaderExpansion::SMP_row2:
case Shader::SMP_row2:
hr = cgD3D9SetUniform (p, data + 8);
break;
case ShaderExpansion::SMP_row3:
case Shader::SMP_row3:
hr = cgD3D9SetUniform (p, data + 12);
break;
case ShaderExpansion::SMP_col0:
case Shader::SMP_col0:
v[0] = data[0]; v[1] = data[4]; v[2] = data[8]; v[3] = data[12];
hr = cgD3D9SetUniform (p, v);
break;
case ShaderExpansion::SMP_col1:
case Shader::SMP_col1:
v[0] = data[1]; v[1] = data[5]; v[2] = data[9]; v[3] = data[13];
hr = cgD3D9SetUniform (p, v);
break;
case ShaderExpansion::SMP_col2:
case Shader::SMP_col2:
v[0] = data[2]; v[1] = data[6]; v[2] = data[10]; v[3] = data[14];
hr = cgD3D9SetUniform (p, v);
break;
case ShaderExpansion::SMP_col3:
case Shader::SMP_col3:
v[0] = data[3]; v[1] = data[7]; v[2] = data[11]; v[3] = data[15];
hr = cgD3D9SetUniform (p, v);
break;
default:
dxgsg9_cat.error()
<< "issue_parameters ( ) SMP parameter type not implemented " << _expansion->_mat_spec[i]._piece << "\n";
<< "issue_parameters ( ) SMP parameter type not implemented " << _shader->_mat_spec[i]._piece << "\n";
break;
}
@ -390,14 +390,14 @@ issue_parameters(GSG *gsg, bool altered)
string name = "unnamed";
if (_expansion->_mat_spec[i]._arg [0]) {
name = _expansion->_mat_spec[i]._arg [0] -> get_basename ( );
if (_shader->_mat_spec[i]._arg [0]) {
name = _shader->_mat_spec[i]._arg [0] -> get_basename ( );
}
dxgsg9_cat.error()
<< "NAME " << name << "\n"
<< "MAT TYPE "
<< _expansion->_mat_spec[i]._piece
<< _shader->_mat_spec[i]._piece
<< " cgD3D9SetUniform failed "
<< D3DERRORSTRING(hr);
@ -465,7 +465,7 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
const GeomVertexArrayDataHandle *array_reader;
Geom::NumericType numeric_type;
int start, stride, num_values;
int nvarying = _expansion->_var_spec.size();
int nvarying = _shader->_var_spec.size();
int stream_index;
VertexElementArray *vertex_element_array;
@ -481,12 +481,12 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
#endif
for (int i=0; i<nvarying; i++) {
CGparameter p = _cg_parameter_map[_expansion->_var_spec[i]._id._seqno];
CGparameter p = _cg_parameter_map[_shader->_var_spec[i]._id._seqno];
if (p == NULL) {
continue;
}
InternalName *name = _expansion->_var_spec[i]._name;
int texslot = _expansion->_var_spec[i]._append_uv;
InternalName *name = _shader->_var_spec[i]._name;
int texslot = _shader->_var_spec[i]._append_uv;
if (texslot >= 0) {
const Geom::ActiveTextureStages &active_stages =
gsg->_state._texture->get_on_stages();
@ -688,8 +688,8 @@ disable_shader_texture_bindings(GSG *gsg)
{
#ifdef HAVE_CG
if (_cg_context) {
for (int i=0; i<(int)_expansion->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_expansion->_tex_spec[i]._id._seqno];
for (int i=0; i<(int)_shader->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_shader->_tex_spec[i]._id._seqno];
if (p == NULL) {
continue;
}
@ -728,31 +728,31 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg)
#ifdef HAVE_CG
if (_cg_context) {
for (int i=0; i<(int)_expansion->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_expansion->_tex_spec[i]._id._seqno];
for (int i=0; i<(int)_shader->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_shader->_tex_spec[i]._id._seqno];
if (p == NULL) {
continue;
}
Texture *tex = 0;
InternalName *id = _expansion->_tex_spec[i]._name;
InternalName *id = _shader->_tex_spec[i]._name;
if (id != 0) {
const ShaderInput *input = gsg->_target._shader->get_shader_input(id);
tex = input->get_texture();
} else {
if (_expansion->_tex_spec[i]._stage >= gsg->_target._texture->get_num_on_stages()) {
if (_shader->_tex_spec[i]._stage >= gsg->_target._texture->get_num_on_stages()) {
continue;
}
TextureStage *stage = gsg->_target._texture->get_on_stage(_expansion->_tex_spec[i]._stage);
TextureStage *stage = gsg->_target._texture->get_on_stage(_shader->_tex_spec[i]._stage);
tex = gsg->_target._texture->get_on_texture(stage);
}
if (_expansion->_tex_spec[i]._suffix != 0) {
if (_shader->_tex_spec[i]._suffix != 0) {
// The suffix feature is inefficient. It is a temporary hack.
if (tex == 0) {
continue;
}
tex = tex->load_related(_expansion->_tex_spec[i]._suffix);
tex = tex->load_related(_shader->_tex_spec[i]._suffix);
}
if ((tex == 0) || (tex->get_texture_type() != _expansion->_tex_spec[i]._desired_type)) {
if ((tex == 0) || (tex->get_texture_type() != _shader->_tex_spec[i]._desired_type)) {
continue;
}
TextureContext *tc = tex->prepare_now(gsg->_prepared_objects, gsg);

View File

@ -23,7 +23,7 @@
#include "pandabase.h"
#include "string_utils.h"
#include "internalName.h"
#include "shaderExpansion.h"
#include "shader.h"
#include "shaderContext.h"
@ -71,7 +71,7 @@ class EXPCL_PANDADX CLP(ShaderContext): public ShaderContext {
public:
typedef CLP(GraphicsStateGuardian) GSG;
CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg);
CLP(ShaderContext)(Shader *s, GSG *gsg);
~CLP(ShaderContext)();
INLINE bool valid(GSG *gsg);

View File

@ -145,14 +145,14 @@ create_texture(DXScreenData &scrn) {
}
// check for texture compression
Texture::CompressionMode compression_mode = Texture::CompressionMode::CM_off;
Texture::CompressionMode compression_mode = Texture::CM_off;
bool texture_stored_compressed = false;
bool texture_wants_compressed = false;
compression_mode = get_texture()->get_ram_image_compression();
// assert my assumption that CM_dxt1..CM_dxt5 enum values are ascending without gaps
nassertr(((Texture::CompressionMode::CM_dxt1+1)==Texture::CompressionMode::CM_dxt2)&&((Texture::CompressionMode::CM_dxt2+1)==Texture::CompressionMode::CM_dxt3)&&((Texture::CompressionMode::CM_dxt3+1)==Texture::CompressionMode::CM_dxt4)&&((Texture::CompressionMode::CM_dxt4+1)==Texture::CompressionMode::CM_dxt5),false);
if ((compression_mode >= Texture::CompressionMode::CM_dxt1) && (compression_mode <= Texture::CompressionMode::CM_dxt5)) {
nassertr(((Texture::CM_dxt1+1)==Texture::CM_dxt2)&&((Texture::CM_dxt2+1)==Texture::CM_dxt3)&&((Texture::CM_dxt3+1)==Texture::CM_dxt4)&&((Texture::CM_dxt4+1)==Texture::CM_dxt5),false);
if ((compression_mode >= Texture::CM_dxt1) && (compression_mode <= Texture::CM_dxt5)) {
texture_stored_compressed = true;
}
@ -160,11 +160,11 @@ create_texture(DXScreenData &scrn) {
texture_wants_compressed = true;
}
else {
if (get_texture()->get_compression() == Texture::CompressionMode::CM_off) {
if (get_texture()->get_compression() == Texture::CM_off) {
// no compression
}
else {
if (get_texture()->get_compression() == Texture::CompressionMode::CM_default) {
if (get_texture()->get_compression() == Texture::CM_default) {
// default = use "compressed-textures" config setting
if (compressed_textures) {
texture_wants_compressed = true;
@ -374,16 +374,16 @@ create_texture(DXScreenData &scrn) {
// if the texture is already compressed, we need to choose the corresponding format,
// otherwise we might end up cross-compressing from e.g. DXT5 to DXT3
switch (compression_mode){
case Texture::CompressionMode::CM_dxt2:
case Texture::CM_dxt2:
CHECK_FOR_FMT(DXT2, Conv32toDXT2);
break;
case Texture::CompressionMode::CM_dxt3:
case Texture::CM_dxt3:
CHECK_FOR_FMT(DXT3, Conv32toDXT3);
break;
case Texture::CompressionMode::CM_dxt4:
case Texture::CM_dxt4:
CHECK_FOR_FMT(DXT4, Conv32toDXT4);
break;
case Texture::CompressionMode::CM_dxt5:
case Texture::CM_dxt5:
CHECK_FOR_FMT(DXT5, Conv32toDXT5);
break;
}

View File

@ -706,7 +706,7 @@ reset() {
// Bug workaround for radeons.
if (_shader_caps._active_fprofile == CG_PROFILE_ARBFP1) {
if (has_extension("GL_ATI_draw_buffers")) {
_shader_caps._bug_list.insert(ShaderExpansion::SBUG_ati_draw_buffers);
_shader_caps._bug_list.insert(Shader::SBUG_ati_draw_buffers);
}
}
}
@ -1060,11 +1060,11 @@ reset() {
GLP(Disable)(GL_DITHER);
_dithering_enabled = false;
_current_shader_expansion = (ShaderExpansion *)NULL;
_current_shader = (Shader *)NULL;
_current_shader_context = (CLP(ShaderContext) *)NULL;
_vertex_array_shader_expansion = (ShaderExpansion *)NULL;
_vertex_array_shader = (Shader *)NULL;
_vertex_array_shader_context = (CLP(ShaderContext) *)NULL;
_texture_binding_shader_expansion = (ShaderExpansion *)NULL;
_texture_binding_shader = (Shader *)NULL;
_texture_binding_shader_context = (CLP(ShaderContext) *)NULL;
// Count the max number of lights
@ -1748,7 +1748,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
}
}
}
_vertex_array_shader_expansion = _current_shader_expansion;
_vertex_array_shader = _current_shader;
_vertex_array_shader_context = _current_shader_context;
report_my_gl_errors();
@ -2723,7 +2723,7 @@ release_geom(GeomContext *gc) {
// Description: yadda.
////////////////////////////////////////////////////////////////////
ShaderContext *CLP(GraphicsStateGuardian)::
prepare_shader(ShaderExpansion *se) {
prepare_shader(Shader *se) {
CLP(ShaderContext) *result = new CLP(ShaderContext)(se, this);
if (result->valid()) return result;
delete result;
@ -3529,24 +3529,21 @@ do_issue_shade_model() {
void CLP(GraphicsStateGuardian)::
do_issue_shader() {
CLP(ShaderContext) *context = 0;
ShaderExpansion *expansion = _target_rs->get_shader_expansion();
if (expansion == 0) {
if (_target._shader->get_shader() != 0) {
expansion = _target._shader->get_shader()->macroexpand(_target_rs, _shader_caps);
// I am casting away the const-ness of this pointer, because
// the 'shader-expansion' field is just a cache.
((RenderState *)((const RenderState*)_target_rs))->
set_shader_expansion(expansion);
}
const ShaderAttrib *attr = _target_rs->get_generated_shader();
if (attr == 0) {
attr = _target._shader;
// if (attr is auto) then generate a shader.
// store that shader using set_generated_shader.
}
if (expansion) {
context = (CLP(ShaderContext) *)(expansion->prepare_now(get_prepared_objects(), this));
Shader *shader = (Shader *)(attr->get_shader());
if (shader) {
context = (CLP(ShaderContext) *)(shader->prepare_now(get_prepared_objects(), this));
}
if (context == 0 || (context -> valid ( ) == false)) {
if (_current_shader_context != 0) {
_current_shader_context->unbind();
_current_shader_expansion = 0;
_current_shader = 0;
_current_shader_context = 0;
}
} else {
@ -3557,7 +3554,7 @@ do_issue_shader() {
_current_shader_context->unbind();
}
context->bind(this);
_current_shader_expansion = expansion;
_current_shader = shader;
_current_shader_context = context;
} else {
// Use the same shader as before, but with new input arguments.
@ -6086,7 +6083,7 @@ do_issue_texture() {
update_shader_texture_bindings(_texture_binding_shader_context,this);
}
}
_texture_binding_shader_expansion = _current_shader_expansion;
_texture_binding_shader = _current_shader;
_texture_binding_shader_context = _current_shader_context;
}

View File

@ -133,7 +133,7 @@ public:
virtual GeomContext *prepare_geom(Geom *geom);
virtual void release_geom(GeomContext *gc);
virtual ShaderContext *prepare_shader(ShaderExpansion *shader);
virtual ShaderContext *prepare_shader(Shader *shader);
virtual void release_shader(ShaderContext *sc);
void record_deleted_display_list(GLuint index);
@ -359,11 +359,11 @@ protected:
bool _point_perspective;
bool _vertex_blending_enabled;
PT(ShaderExpansion) _current_shader_expansion;
PT(Shader) _current_shader;
CLP(ShaderContext) *_current_shader_context;
PT(ShaderExpansion) _vertex_array_shader_expansion;
PT(Shader) _vertex_array_shader;
CLP(ShaderContext) *_vertex_array_shader_context;
PT(ShaderExpansion) _texture_binding_shader_expansion;
PT(Shader) _texture_binding_shader;
CLP(ShaderContext) *_texture_binding_shader_context;
#ifdef SUPPORT_IMMEDIATE_MODE

View File

@ -31,11 +31,11 @@ TypeHandle CLP(ShaderContext)::_type_handle;
// Description: xyz
////////////////////////////////////////////////////////////////////
CLP(ShaderContext)::
CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
CLP(ShaderContext)(Shader *s, GSG *gsg) : ShaderContext(s) {
#ifdef HAVE_CG
if (s->get_header() == "//Cg") {
// Ask the shader expansion to compile itself for us and
// Ask the shader to compile itself for us and
// to give us the resulting Cg program objects.
if (!s->cg_compile_for(gsg->_shader_caps,
@ -52,7 +52,7 @@ CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
CGerror verror = cgGetError();
if (verror != CG_NO_ERROR) {
const char *str = (const char *)GLP(GetString)(GL_PROGRAM_ERROR_STRING_ARB);
GLCAT.error() << "Could not load Cg vertex program:" << s->get_name() << " (" <<
GLCAT.error() << "Could not load Cg vertex program:" << s->get_filename() << " (" <<
cgGetProfileString(cgGetProgramProfile(_cg_vprogram)) << " " << str << ")\n";
release_resources();
}
@ -60,7 +60,7 @@ CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
CGerror ferror = cgGetError();
if (ferror != CG_NO_ERROR) {
const char *str = (const char *)GLP(GetString)(GL_PROGRAM_ERROR_STRING_ARB);
GLCAT.error() << "Could not load Cg fragment program:" << s->get_name() << " (" <<
GLCAT.error() << "Could not load Cg fragment program:" << s->get_filename() << " (" <<
cgGetProfileString(cgGetProgramProfile(_cg_fprogram)) << " " << str << ")\n";
release_resources();
}
@ -142,7 +142,7 @@ unbind() {
// Function: GLShaderContext::issue_parameters
// Access: Public
// Description: This function gets called whenever the RenderState
// or TransformState has changed, but the ShaderExpansion
// or TransformState has changed, but the Shader
// itself has not changed. It loads new values into the
// shader's parameters.
//
@ -160,23 +160,23 @@ issue_parameters(GSG *gsg, bool altered) {
return;
}
for (int i=0; i<(int)_expansion->_mat_spec.size(); i++) {
if (altered || _expansion->_mat_spec[i]._trans_dependent) {
CGparameter p = _cg_parameter_map[_expansion->_mat_spec[i]._id._seqno];
const LMatrix4f *val = gsg->fetch_specified_value(_expansion->_mat_spec[i], altered);
for (int i=0; i<(int)_shader->_mat_spec.size(); i++) {
if (altered || _shader->_mat_spec[i]._trans_dependent) {
CGparameter p = _cg_parameter_map[_shader->_mat_spec[i]._id._seqno];
const LMatrix4f *val = gsg->fetch_specified_value(_shader->_mat_spec[i], altered);
if (val) {
const float *data = val->get_data();
switch (_expansion->_mat_spec[i]._piece) {
case ShaderExpansion::SMP_whole: cgGLSetMatrixParameterfc(p, data); break;
case ShaderExpansion::SMP_transpose: cgGLSetMatrixParameterfr(p, data); break;
case ShaderExpansion::SMP_row0: cgGLSetParameter4fv(p, data+ 0); break;
case ShaderExpansion::SMP_row1: cgGLSetParameter4fv(p, data+ 4); break;
case ShaderExpansion::SMP_row2: cgGLSetParameter4fv(p, data+ 8); break;
case ShaderExpansion::SMP_row3: cgGLSetParameter4fv(p, data+12); break;
case ShaderExpansion::SMP_col0: cgGLSetParameter4f(p, data[0], data[4], data[ 8], data[12]); break;
case ShaderExpansion::SMP_col1: cgGLSetParameter4f(p, data[1], data[5], data[ 9], data[13]); break;
case ShaderExpansion::SMP_col2: cgGLSetParameter4f(p, data[2], data[6], data[10], data[14]); break;
case ShaderExpansion::SMP_col3: cgGLSetParameter4f(p, data[3], data[7], data[11], data[15]); break;
switch (_shader->_mat_spec[i]._piece) {
case Shader::SMP_whole: cgGLSetMatrixParameterfc(p, data); break;
case Shader::SMP_transpose: cgGLSetMatrixParameterfr(p, data); break;
case Shader::SMP_row0: cgGLSetParameter4fv(p, data+ 0); break;
case Shader::SMP_row1: cgGLSetParameter4fv(p, data+ 4); break;
case Shader::SMP_row2: cgGLSetParameter4fv(p, data+ 8); break;
case Shader::SMP_row3: cgGLSetParameter4fv(p, data+12); break;
case Shader::SMP_col0: cgGLSetParameter4f(p, data[0], data[4], data[ 8], data[12]); break;
case Shader::SMP_col1: cgGLSetParameter4f(p, data[1], data[5], data[ 9], data[13]); break;
case Shader::SMP_col2: cgGLSetParameter4f(p, data[2], data[6], data[10], data[14]); break;
case Shader::SMP_col3: cgGLSetParameter4f(p, data[3], data[7], data[11], data[15]); break;
}
}
}
@ -197,8 +197,8 @@ disable_shader_vertex_arrays(GSG *gsg) {
return;
}
for (int i=0; i<(int)_expansion->_var_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_expansion->_var_spec[i]._id._seqno];
for (int i=0; i<(int)_shader->_var_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_shader->_var_spec[i]._id._seqno];
if (p == 0) continue;
cgGLDisableClientState(p);
}
@ -236,12 +236,12 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg,
const GeomVertexArrayDataHandle *array_reader;
Geom::NumericType numeric_type;
int start, stride, num_values;
int nvarying = _expansion->_var_spec.size();
int nvarying = _shader->_var_spec.size();
for (int i=0; i<nvarying; i++) {
CGparameter p = _cg_parameter_map[_expansion->_var_spec[i]._id._seqno];
CGparameter p = _cg_parameter_map[_shader->_var_spec[i]._id._seqno];
if (p == 0) continue;
InternalName *name = _expansion->_var_spec[i]._name;
int texslot = _expansion->_var_spec[i]._append_uv;
InternalName *name = _shader->_var_spec[i]._name;
int texslot = _shader->_var_spec[i]._append_uv;
if (texslot >= 0) {
const Geom::ActiveTextureStages &active_stages =
gsg->_state._texture->get_on_stages();
@ -288,8 +288,8 @@ disable_shader_texture_bindings(GSG *gsg) {
return;
}
for (int i=0; i<(int)_expansion->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_expansion->_tex_spec[i]._id._seqno];
for (int i=0; i<(int)_shader->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_shader->_tex_spec[i]._id._seqno];
if (p == 0) continue;
int texunit = cgGetParameterResourceIndex(p);
gsg->_glActiveTexture(GL_TEXTURE0 + texunit);
@ -327,29 +327,29 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) {
return;
}
for (int i=0; i<(int)_expansion->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_expansion->_tex_spec[i]._id._seqno];
for (int i=0; i<(int)_shader->_tex_spec.size(); i++) {
CGparameter p = _cg_parameter_map[_shader->_tex_spec[i]._id._seqno];
if (p == 0) continue;
Texture *tex = 0;
InternalName *id = _expansion->_tex_spec[i]._name;
InternalName *id = _shader->_tex_spec[i]._name;
if (id != 0) {
const ShaderInput *input = gsg->_target._shader->get_shader_input(id);
tex = input->get_texture();
} else {
if (_expansion->_tex_spec[i]._stage >= gsg->_target._texture->get_num_on_stages()) {
if (_shader->_tex_spec[i]._stage >= gsg->_target._texture->get_num_on_stages()) {
continue;
}
TextureStage *stage = gsg->_target._texture->get_on_stage(_expansion->_tex_spec[i]._stage);
TextureStage *stage = gsg->_target._texture->get_on_stage(_shader->_tex_spec[i]._stage);
tex = gsg->_target._texture->get_on_texture(stage);
}
if (_expansion->_tex_spec[i]._suffix != 0) {
if (_shader->_tex_spec[i]._suffix != 0) {
// The suffix feature is inefficient. It is a temporary hack.
if (tex == 0) {
continue;
}
tex = tex->load_related(_expansion->_tex_spec[i]._suffix);
tex = tex->load_related(_shader->_tex_spec[i]._suffix);
}
if ((tex == 0) || (tex->get_texture_type() != _expansion->_tex_spec[i]._desired_type)) {
if ((tex == 0) || (tex->get_texture_type() != _shader->_tex_spec[i]._desired_type)) {
continue;
}
TextureContext *tc = tex->prepare_now(gsg->_prepared_objects, gsg);
@ -383,7 +383,7 @@ void CLP(ShaderContext)::
cg_report_errors() {
CGerror err = cgGetError();
if (err != CG_NO_ERROR) {
GLCAT.error() << _expansion->get_name() << " " << cgGetErrorString(err) << "\n";
GLCAT.error() << _shader->get_filename() << " " << cgGetErrorString(err) << "\n";
}
}
#endif

View File

@ -19,7 +19,7 @@
#include "pandabase.h"
#include "string_utils.h"
#include "internalName.h"
#include "shaderExpansion.h"
#include "shader.h"
#include "shaderContext.h"
#include "deletedChain.h"
@ -34,7 +34,7 @@ class EXPCL_GL CLP(ShaderContext): public ShaderContext {
public:
typedef CLP(GraphicsStateGuardian) GSG;
CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg);
CLP(ShaderContext)(Shader *s, GSG *gsg);
~CLP(ShaderContext)();
ALLOC_DELETED_CHAIN(CLP(ShaderContext));

View File

@ -44,7 +44,7 @@
#include "texturePoolFilter.h"
#include "textureStage.h"
#include "textureContext.h"
#include "shaderExpansion.h"
#include "shader.h"
#include "shaderContext.h"
#include "transformBlend.h"
#include "transformBlendTable.h"
@ -356,7 +356,7 @@ ConfigureFn(config_gobj) {
PerspectiveLens::init_type();
QueryContext::init_type();
ShaderContext::init_type();
ShaderExpansion::init_type();
Shader::init_type();
SliderTable::init_type();
Texture::init_type();
TextureContext::init_type();
@ -392,6 +392,7 @@ ConfigureFn(config_gobj) {
MatrixLens::register_with_read_factory();
OrthographicLens::register_with_read_factory();
PerspectiveLens::register_with_read_factory();
Shader::register_with_read_factory();
SliderTable::register_with_read_factory();
Texture::register_with_read_factory();
TextureStage::register_with_read_factory();

View File

@ -8,7 +8,7 @@
#include "queryContext.cxx"
#include "savedContext.cxx"
#include "shaderContext.cxx"
#include "shaderExpansion.cxx"
#include "shader.cxx"
#include "simpleAllocator.cxx"
#include "simpleLru.cxx"
#include "sliderTable.cxx"

View File

@ -24,7 +24,7 @@
#include "geom.h"
#include "geomVertexArrayData.h"
#include "geomPrimitive.h"
#include "shaderExpansion.h"
#include "shader.h"
#include "reMutexHolder.h"
#include "geomContext.h"
#include "shaderContext.h"
@ -487,7 +487,7 @@ prepare_geom_now(Geom *geom, GraphicsStateGuardianBase *gsg) {
// do this (presumably at the next frame).
////////////////////////////////////////////////////////////////////
void PreparedGraphicsObjects::
enqueue_shader(ShaderExpansion *se) {
enqueue_shader(Shader *se) {
ReMutexHolder holder(_lock);
_enqueued_shaders.insert(se);
@ -500,10 +500,10 @@ enqueue_shader(ShaderExpansion *se) {
// GSG, false otherwise.
////////////////////////////////////////////////////////////////////
bool PreparedGraphicsObjects::
is_shader_queued(const ShaderExpansion *shader) const {
is_shader_queued(const Shader *shader) const {
ReMutexHolder holder(_lock);
EnqueuedShaders::const_iterator qi = _enqueued_shaders.find((ShaderExpansion *)shader);
EnqueuedShaders::const_iterator qi = _enqueued_shaders.find((Shader *)shader);
return (qi != _enqueued_shaders.end());
}
@ -522,7 +522,7 @@ is_shader_queued(const ShaderExpansion *shader) const {
// queued.
////////////////////////////////////////////////////////////////////
bool PreparedGraphicsObjects::
dequeue_shader(ShaderExpansion *se) {
dequeue_shader(Shader *se) {
ReMutexHolder holder(_lock);
EnqueuedShaders::iterator qi = _enqueued_shaders.find(se);
@ -540,7 +540,7 @@ dequeue_shader(ShaderExpansion *se) {
// this GSG, false otherwise.
////////////////////////////////////////////////////////////////////
bool PreparedGraphicsObjects::
is_shader_prepared(const ShaderExpansion *shader) const {
is_shader_prepared(const Shader *shader) const {
return shader->is_prepared((PreparedGraphicsObjects *)this);
}
@ -561,12 +561,12 @@ void PreparedGraphicsObjects::
release_shader(ShaderContext *sc) {
ReMutexHolder holder(_lock);
sc->_expansion->clear_prepared(this);
sc->_shader->clear_prepared(this);
// We have to set the Shader pointer to NULL at this point, since
// the Shader itself might destruct at any time after it has been
// released.
sc->_expansion = (ShaderExpansion *)NULL;
sc->_shader = (Shader *)NULL;
bool removed = (_prepared_shaders.erase(sc) != 0);
nassertv(removed);
@ -593,8 +593,8 @@ release_all_shaders() {
sci != _prepared_shaders.end();
++sci) {
ShaderContext *sc = (*sci);
sc->_expansion->clear_prepared(this);
sc->_expansion = (ShaderExpansion *)NULL;
sc->_shader->clear_prepared(this);
sc->_shader = (Shader *)NULL;
_released_shaders.insert(sc);
}
@ -650,7 +650,7 @@ get_num_prepared_shaders() const {
// ShaderContext will be deleted.
////////////////////////////////////////////////////////////////////
ShaderContext *PreparedGraphicsObjects::
prepare_shader_now(ShaderExpansion *se, GraphicsStateGuardianBase *gsg) {
prepare_shader_now(Shader *se, GraphicsStateGuardianBase *gsg) {
ReMutexHolder holder(_lock);
// Ask the GSG to create a brand new ShaderContext. There might
@ -1226,7 +1226,7 @@ begin_frame(GraphicsStateGuardianBase *gsg, Thread *current_thread) {
for (qsi = _enqueued_shaders.begin();
qsi != _enqueued_shaders.end();
++qsi) {
ShaderExpansion *shader = (*qsi);
Shader *shader = (*qsi);
shader->prepare_now(this, gsg);
}

View File

@ -25,7 +25,7 @@
#include "geom.h"
#include "geomVertexArrayData.h"
#include "geomPrimitive.h"
#include "shaderExpansion.h"
#include "shader.h"
#include "pointerTo.h"
#include "pStatCollector.h"
#include "pset.h"
@ -92,16 +92,16 @@ PUBLISHED:
GeomContext *prepare_geom_now(Geom *geom, GraphicsStateGuardianBase *gsg);
void enqueue_shader(ShaderExpansion *shader);
bool is_shader_queued(const ShaderExpansion *shader) const;
bool dequeue_shader(ShaderExpansion *shader);
bool is_shader_prepared(const ShaderExpansion *shader) const;
void enqueue_shader(Shader *shader);
bool is_shader_queued(const Shader *shader) const;
bool dequeue_shader(Shader *shader);
bool is_shader_prepared(const Shader *shader) const;
void release_shader(ShaderContext *sc);
int release_all_shaders();
int get_num_queued_shaders() const;
int get_num_prepared_shaders() const;
ShaderContext *prepare_shader_now(ShaderExpansion *shader, GraphicsStateGuardianBase *gsg);
ShaderContext *prepare_shader_now(Shader *shader, GraphicsStateGuardianBase *gsg);
void enqueue_vertex_buffer(GeomVertexArrayData *data);
bool is_vertex_buffer_queued(const GeomVertexArrayData *data) const;
@ -143,7 +143,7 @@ private:
typedef phash_set<GeomContext *, pointer_hash> Geoms;
typedef phash_set< PT(Geom) > EnqueuedGeoms;
typedef phash_set<ShaderContext *, pointer_hash> Shaders;
typedef phash_set< PT(ShaderExpansion) > EnqueuedShaders;
typedef phash_set< PT(Shader) > EnqueuedShaders;
typedef phash_set<BufferContext *, pointer_hash> Buffers;
typedef phash_set< PT(GeomVertexArrayData) > EnqueuedVertexBuffers;
typedef phash_set< PT(GeomPrimitive) > EnqueuedIndexBuffers;

View File

@ -1,4 +1,4 @@
// Filename: shaderExpansion.I
// Filename: shader.I
// Heavily Modified: jyelon (Sep05)
//
////////////////////////////////////////////////////////////////////
@ -17,80 +17,63 @@
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::get_name
// Function: Shader::get_filename
// Access: Public
// Description: Return the ShaderExpansion's text.
// Description: Return the Shader's filename.
////////////////////////////////////////////////////////////////////
INLINE const string &ShaderExpansion::
get_name() const {
return _name;
INLINE const Filename &Shader::
get_filename() const {
return _filename;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::get_text
// Function: Shader::get_text
// Access: Public
// Description: Return the ShaderExpansion's text.
// Description: Return the Shader's text.
////////////////////////////////////////////////////////////////////
INLINE const string &ShaderExpansion::
INLINE const string &Shader::
get_text() const {
return _text;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::get_header
// Function: Shader::get_header
// Access: Public
// Description: Return the ShaderExpansion's header line.
// Description: Return the Shader's header line.
////////////////////////////////////////////////////////////////////
INLINE const string &ShaderExpansion::
INLINE const string &Shader::
get_header() const {
return _header;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::get_error_flag
// Function: Shader::get_error_flag
// Access: Public
// Description: Returns true if the shader contains a compile-time
// error. This doesn't tell you whether or not the
// shader is supported on the current video card.
////////////////////////////////////////////////////////////////////
INLINE bool ShaderExpansion::
INLINE bool Shader::
get_error_flag() const {
return _error_flag;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::ShaderCapabilities Constructor
// Function: Shader::ShaderCapabilities Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ShaderExpansion::ShaderCaps::
INLINE Shader::ShaderCaps::
ShaderCaps() {
clear();
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::ShaderCapabilities::clear()
// Function: Shader::ShaderCapabilities::operator ==
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void ShaderExpansion::ShaderCaps::
clear() {
#ifdef HAVE_CG
_active_vprofile = 0;
_active_fprofile = 0;
_ultimate_vprofile = 0;
_ultimate_fprofile = 0;
#endif
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::ShaderCapabilities::operator ==
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool ShaderExpansion::ShaderCaps::
INLINE bool Shader::ShaderCaps::
operator == (const ShaderCaps &other) const {
#ifdef HAVE_CG
if ((_active_vprofile != other._active_vprofile) ||

View File

@ -1,4 +1,4 @@
// Filename: shaderExpansion.cxx
// Filename: shader.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
@ -17,23 +17,26 @@
////////////////////////////////////////////////////////////////////
#include "pandabase.h"
#include "shaderExpansion.h"
#include "shader.h"
#include "preparedGraphicsObjects.h"
#include "virtualFileSystem.h"
#ifdef HAVE_CG
#include "Cg/cg.h"
#endif
TypeHandle ShaderExpansion::_type_handle;
ShaderExpansion::ExpansionCache ShaderExpansion::_expansion_cache;
TypeHandle Shader::_type_handle;
Shader::LoadTable Shader::_load_table;
Shader::MakeTable Shader::_make_table;
Shader::ShaderCaps Shader::_default_caps;
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_report_error
// Function: Shader::cp_report_error
// Access: Public
// Description: Generate an error message including a description
// of the specified parameter.
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
cp_report_error(ShaderArgInfo &p, const string &msg)
{
string vstr;
@ -59,19 +62,19 @@ cp_report_error(ShaderArgInfo &p, const string &msg)
case SAT_unknown: tstr = "unknown "; break;
}
string fn = get_name();
Filename fn = get_filename();
p._cat->error() << fn << ": " << msg << " (" <<
vstr << dstr << tstr << p._id._name << ")\n";
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_errchk_parameter_words
// Function: Shader::cp_errchk_parameter_words
// Access: Public, Static
// Description: Make sure the provided parameter contains
// the specified number of words. If not, print
// error message and return false.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cp_errchk_parameter_words(ShaderArgInfo &p, int len)
{
vector_string words;
@ -84,13 +87,13 @@ cp_errchk_parameter_words(ShaderArgInfo &p, int len)
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_errchk_parameter_in
// Function: Shader::cp_errchk_parameter_in
// Access: Public, Static
// Description: Make sure the provided parameter has the
// 'in' direction. If not, print
// error message and return false.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cp_errchk_parameter_in(ShaderArgInfo &p)
{
if (p._direction != SAD_in) {
@ -101,13 +104,13 @@ cp_errchk_parameter_in(ShaderArgInfo &p)
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_errchk_parameter_varying
// Function: Shader::cp_errchk_parameter_varying
// Access: Public, Static
// Description: Make sure the provided parameter has the
// correct variance. If not, print
// error message and return false.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cp_errchk_parameter_varying(ShaderArgInfo &p)
{
if (!p._varying) {
@ -118,13 +121,13 @@ cp_errchk_parameter_varying(ShaderArgInfo &p)
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_errchk_parameter_uniform
// Function: Shader::cp_errchk_parameter_uniform
// Access: Public, Static
// Description: Make sure the provided parameter has the
// correct variance. If not, print
// error message and return false.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cp_errchk_parameter_uniform(ShaderArgInfo &p)
{
if (p._varying) {
@ -135,13 +138,13 @@ cp_errchk_parameter_uniform(ShaderArgInfo &p)
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_errchk_parameter_float
// Function: Shader::cp_errchk_parameter_float
// Access: Public, Static
// Description: Make sure the provided parameter has
// a floating point type. If not, print
// error message and return false.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cp_errchk_parameter_float(ShaderArgInfo &p, int lo, int hi)
{
int nfloat;
@ -162,13 +165,13 @@ cp_errchk_parameter_float(ShaderArgInfo &p, int lo, int hi)
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_errchk_parameter_sampler
// Function: Shader::cp_errchk_parameter_sampler
// Access: Public, Static
// Description: Make sure the provided parameter has
// a texture type. If not, print
// error message and return false.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cp_errchk_parameter_sampler(ShaderArgInfo &p)
{
if ((p._type!=SAT_sampler1d)&&
@ -182,11 +185,11 @@ cp_errchk_parameter_sampler(ShaderArgInfo &p)
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_parse_trans_clause
// Function: Shader::cp_parse_trans_clause
// Access: Public
// Description: Parses a single clause of a "trans" parameter.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cp_parse_trans_clause(ShaderArgInfo &p, ShaderMatSpec &spec,
int part, const vector_string &pieces,
int &next, ShaderMatInput ofop, ShaderMatInput op) {
@ -208,7 +211,7 @@ cp_parse_trans_clause(ShaderArgInfo &p, ShaderMatSpec &spec,
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cp_optimize_mat_spec
// Function: Shader::cp_optimize_mat_spec
// Access: Public
// Description: Analyzes a ShaderMatSpec and decides what it should
// use its cache for. It can cache the results of any
@ -216,7 +219,7 @@ cp_parse_trans_clause(ShaderArgInfo &p, ShaderMatSpec &spec,
// routine needs to be smart enough to know which
// data items can be correctly cached, and which cannot.
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
cp_optimize_mat_spec(ShaderMatSpec &spec) {
// If we're composing with identity, simplify.
@ -263,7 +266,7 @@ cp_optimize_mat_spec(ShaderMatSpec &spec) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::compile_parameter
// Function: Shader::compile_parameter
// Access: Public
// Description: Analyzes a parameter and decides how to
// bind the parameter to some part of panda's
@ -273,7 +276,7 @@ cp_optimize_mat_spec(ShaderMatSpec &spec) {
// If there is an error, this routine will append
// an error message onto the error messages.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
compile_parameter(const ShaderArgId &arg_id,
ShaderArgType arg_type,
ShaderArgDir arg_direction,
@ -702,11 +705,11 @@ compile_parameter(const ShaderArgId &arg_id,
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::clear_parameters
// Function: Shader::clear_parameters
// Access: Private
// Description:
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
clear_parameters() {
_mat_spec.clear();
_var_spec.clear();
@ -715,47 +718,47 @@ clear_parameters() {
#ifdef HAVE_CG
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_parameter_type
// Function: Shader::cg_parameter_type
// Access: Private
// Description:
////////////////////////////////////////////////////////////////////
ShaderExpansion::ShaderArgType ShaderExpansion::
Shader::ShaderArgType Shader::
cg_parameter_type(CGparameter p) {
switch (cgGetParameterType(p)) {
case CG_FLOAT1: return ShaderExpansion::SAT_float1;
case CG_FLOAT2: return ShaderExpansion::SAT_float2;
case CG_FLOAT3: return ShaderExpansion::SAT_float3;
case CG_FLOAT4: return ShaderExpansion::SAT_float4;
case CG_FLOAT4x4: return ShaderExpansion::SAT_float4x4;
case CG_SAMPLER1D: return ShaderExpansion::SAT_sampler1d;
case CG_SAMPLER2D: return ShaderExpansion::SAT_sampler2d;
case CG_SAMPLER3D: return ShaderExpansion::SAT_sampler3d;
case CG_SAMPLERCUBE: return ShaderExpansion::SAT_samplercube;
default: return ShaderExpansion::SAT_unknown;
case CG_FLOAT1: return Shader::SAT_float1;
case CG_FLOAT2: return Shader::SAT_float2;
case CG_FLOAT3: return Shader::SAT_float3;
case CG_FLOAT4: return Shader::SAT_float4;
case CG_FLOAT4x4: return Shader::SAT_float4x4;
case CG_SAMPLER1D: return Shader::SAT_sampler1d;
case CG_SAMPLER2D: return Shader::SAT_sampler2d;
case CG_SAMPLER3D: return Shader::SAT_sampler3d;
case CG_SAMPLERCUBE: return Shader::SAT_samplercube;
default: return Shader::SAT_unknown;
}
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_parameter_dir
// Function: Shader::cg_parameter_dir
// Access: Private
// Description:
////////////////////////////////////////////////////////////////////
ShaderExpansion::ShaderArgDir ShaderExpansion::
Shader::ShaderArgDir Shader::
cg_parameter_dir(CGparameter p) {
switch (cgGetParameterDirection(p)) {
case CG_IN: return ShaderExpansion::SAD_in;
case CG_OUT: return ShaderExpansion::SAD_out;
case CG_INOUT: return ShaderExpansion::SAD_inout;
default: return ShaderExpansion::SAD_unknown;
case CG_IN: return Shader::SAD_in;
case CG_OUT: return Shader::SAD_out;
case CG_INOUT: return Shader::SAD_inout;
default: return Shader::SAD_unknown;
}
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_release_resources
// Function: Shader::cg_release_resources
// Access: Private
// Description: xyz
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
cg_release_resources() {
if (_cg_vprogram != 0) {
cgDestroyProgram(_cg_vprogram);
@ -772,11 +775,11 @@ cg_release_resources() {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_compile_entry_point
// Function: Shader::cg_compile_entry_point
// Access: Private
// Description: xyz
////////////////////////////////////////////////////////////////////
CGprogram ShaderExpansion::
CGprogram Shader::
cg_compile_entry_point(char *entry, const ShaderCaps &caps, bool fshader)
{
CGprogram prog;
@ -818,11 +821,11 @@ cg_compile_entry_point(char *entry, const ShaderCaps &caps, bool fshader)
for (int i=0; i<(int)errlines.size(); i++) {
string line = trim(errlines[i]);
if (line != "") {
gobj_cat.error() << _name << " " << errlines[i] << "\n";
gobj_cat.error() << get_filename() << ": " << errlines[i] << "\n";
}
}
} else {
gobj_cat.error() << _name << ": " << cgGetErrorString(err) << "\n";
gobj_cat.error() << get_filename() << ": " << cgGetErrorString(err) << "\n";
}
if (prog != 0) {
cgDestroyProgram(prog);
@ -832,13 +835,13 @@ cg_compile_entry_point(char *entry, const ShaderCaps &caps, bool fshader)
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_compile_shader
// Function: Shader::cg_compile_shader
// Access: Private
// Description: Compiles a Cg shader for a given set of capabilities.
// If successful, the shader is stored in the instance
// variables _cg_context, _cg_vprogram, _cg_fprogram.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cg_compile_shader(const ShaderCaps &caps) {
// If we already tried compiling for this set of caps, there's no point
@ -872,11 +875,11 @@ cg_compile_shader(const ShaderCaps &caps) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_analyze_entry_point
// Function: Shader::cg_analyze_entry_point
// Access: Private
// Description:
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cg_analyze_entry_point(CGprogram prog, bool fshader) {
CGparameter parameter;
bool success = true;
@ -901,7 +904,7 @@ cg_analyze_entry_point(CGprogram prog, bool fshader) {
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_analyze_shader
// Function: Shader::cg_analyze_shader
// Access: Private
// Description: This subroutine analyzes the parameters of a Cg
// shader. The output is stored in instance variables:
@ -932,7 +935,7 @@ cg_analyze_entry_point(CGprogram prog, bool fshader) {
// profile.
//
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cg_analyze_shader(const ShaderCaps &caps) {
if (!cg_compile_shader(caps)) {
@ -1059,14 +1062,14 @@ cg_analyze_shader(const ShaderCaps &caps) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::cg_compile_for
// Function: Shader::cg_compile_for
// Access: Public
// Description: This routine is used by the ShaderContext constructor
// to compile the shader. The CGprogram
// objects are turned over to the ShaderContext, we no
// longer own them.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
cg_compile_for(const ShaderCaps &caps,
CGcontext &ctx,
CGprogram &vprogram,
@ -1079,10 +1082,11 @@ cg_compile_for(const ShaderCaps &caps,
vprogram = 0;
fprogram = 0;
map.clear();
// Make sure the shader is compiled for the target caps.
// Most of the time, it will already be - this is usually a no-op.
_default_caps = caps;
if (!cg_compile_shader(caps)) {
return false;
}
@ -1093,7 +1097,7 @@ cg_compile_for(const ShaderCaps &caps,
if ((cgGetProgramProfile(_cg_vprogram) != caps._active_vprofile)||
(cgGetProgramProfile(_cg_fprogram) != caps._active_fprofile)) {
gobj_cat.error() << "Cg program too complex for driver:" << get_name() << "\n";
gobj_cat.error() << "Cg program too complex for driver:" << get_filename() << "\n";
return false;
}
@ -1143,14 +1147,13 @@ cg_compile_for(const ShaderCaps &caps,
#endif // HAVE_CG
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::Constructor
// Function: Shader::Constructor
// Access: Private
// Description: Construct a ShaderExpansion.
// Description: Construct a Shader.
////////////////////////////////////////////////////////////////////
ShaderExpansion::
ShaderExpansion(const string &name, const string &text,
const ShaderCaps &caps) :
_name(name),
Shader::
Shader(const Filename &filename, const string &text) :
_filename(filename),
_text(text),
_header(""),
_error_flag(true),
@ -1164,8 +1167,14 @@ ShaderExpansion(const string &name, const string &text,
_cg_context = 0;
_cg_vprogram = 0;
_cg_fprogram = 0;
if (_default_caps._ultimate_vprofile == 0) {
_default_caps._active_vprofile = CG_PROFILE_UNKNOWN;
_default_caps._active_fprofile = CG_PROFILE_UNKNOWN;
_default_caps._ultimate_vprofile = CG_PROFILE_VS_3_0;
_default_caps._ultimate_fprofile = CG_PROFILE_PS_3_0;
}
if (_header == "//Cg") {
if (cg_analyze_shader(caps)) {
if (cg_analyze_shader(_default_caps)) {
_error_flag = false;
}
} else {
@ -1178,53 +1187,87 @@ ShaderExpansion(const string &name, const string &text,
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::Destructor
// Function: Shader::Destructor
// Access: Public
// Description: Delete the compiled code, if it exists.
////////////////////////////////////////////////////////////////////
ShaderExpansion::
~ShaderExpansion() {
Shader::
~Shader() {
release_all();
_expansion_cache.erase(ExpansionKey(_name,_text));
if (_loaded) {
_load_table.erase(_filename);
} else {
_make_table.erase(_text);
}
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::make
// Access: Public, Static
// Description: Create a shader expansion (or reuse one from cache)
// Function: Shader::load
// Access: Published, Static
// Description:
////////////////////////////////////////////////////////////////////
PT(ShaderExpansion) ShaderExpansion::
make(const string &name, const string &text,
const ShaderCaps &caps) {
ExpansionKey key(name, text);
ExpansionCache::const_iterator i = _expansion_cache.find(key);
if (i != _expansion_cache.end()) {
PT(Shader) Shader::
load(const string &file) {
return load(Filename(file));
}
////////////////////////////////////////////////////////////////////
// Function: Shader::load
// Access: Published, Static
// Description:
////////////////////////////////////////////////////////////////////
PT(Shader) Shader::
load(const Filename &file) {
LoadTable::const_iterator i = _load_table.find(file);
if (i != _load_table.end()) {
return i->second;
}
ShaderExpansion *result = new ShaderExpansion(name, text, caps);
_expansion_cache.insert(ExpansionCache::value_type(key,result));
string body;
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
if (!vfs->read_file(file, body, true)) {
gobj_cat.error() << "Could not read shader file: " << file << "\n";
return NULL;
}
PT(Shader) result = new Shader(file, body);
_load_table[file] = result;
return result;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::parse_init
// Function: Shader::make
// Access: Published, Static
// Description:
////////////////////////////////////////////////////////////////////
PT(Shader) Shader::
make(const string &body) {
MakeTable::const_iterator i = _make_table.find(body);
if (i != _make_table.end()) {
return i->second;
}
PT(Shader) result = new Shader("created-shader", body);
_make_table[body] = result;
return result;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::parse_init
// Access: Public
// Description: Set a 'parse pointer' to the beginning of the shader.
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
parse_init() {
_parse = 0;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::parse_line
// Function: Shader::parse_line
// Access: Public
// Description: Parse a line of text. If 'lt' is true, trim blanks
// from the left end of the line. If 'rt' is true, trim
// blanks from the right end (the newline is always
// trimmed).
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
parse_line(string &result, bool lt, bool rt) {
int len = _text.size();
int head = _parse;
@ -1245,14 +1288,14 @@ parse_line(string &result, bool lt, bool rt) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::parse_upto
// Function: Shader::parse_upto
// Access: Public
// Description: Parse lines until you read a line that matches the
// specified pattern. Returns all the preceding lines,
// and if the include flag is set, returns the final
// line as well.
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
parse_upto(string &result, string pattern, bool include) {
GlobPattern endpat(pattern);
int start = _parse;
@ -1271,22 +1314,22 @@ parse_upto(string &result, string pattern, bool include) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::parse_rest
// Function: Shader::parse_rest
// Access: Public
// Description: Returns the rest of the text from the current
// parse location.
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
parse_rest(string &result) {
result = _text.substr(_parse, _text.size() - _parse);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::parse_lineno
// Function: Shader::parse_lineno
// Access: Public
// Description: Returns the line number of the current parse pointer.
////////////////////////////////////////////////////////////////////
int ShaderExpansion::
int Shader::
parse_lineno() {
int result = 1;
for (int i=0; i<_parse; i++) {
@ -1296,18 +1339,18 @@ parse_lineno() {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::parse_eof
// Function: Shader::parse_eof
// Access: Public
// Description: Returns true if the parse pointer is at the end of
// the shader.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
parse_eof() {
return (int)_text.size() == _parse;
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::prepare
// Function: Shader::prepare
// Access: Published
// Description: Indicates that the shader should be enqueued to be
// prepared in the indicated prepared_objects at the
@ -1318,19 +1361,19 @@ parse_eof() {
// Use this function instead of prepare_now() to preload
// textures from a user interface standpoint.
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
prepare(PreparedGraphicsObjects *prepared_objects) {
prepared_objects->enqueue_shader(this);
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::is_prepared
// Function: Shader::is_prepared
// Access: Published
// Description: Returns true if the shader has already been prepared
// or enqueued for preparation on the indicated GSG,
// false otherwise.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
is_prepared(PreparedGraphicsObjects *prepared_objects) const {
Contexts::const_iterator ci;
ci = _contexts.find(prepared_objects);
@ -1341,13 +1384,13 @@ is_prepared(PreparedGraphicsObjects *prepared_objects) const {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::release
// Function: Shader::release
// Access: Published
// Description: Frees the texture context only on the indicated object,
// if it exists there. Returns true if it was released,
// false if it had not been prepared.
////////////////////////////////////////////////////////////////////
bool ShaderExpansion::
bool Shader::
release(PreparedGraphicsObjects *prepared_objects) {
Contexts::iterator ci;
ci = _contexts.find(prepared_objects);
@ -1366,7 +1409,7 @@ release(PreparedGraphicsObjects *prepared_objects) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::prepare_now
// Function: Shader::prepare_now
// Access: Published
// Description: Creates a context for the texture on the particular
// GSG, if it does not already exist. Returns the new
@ -1381,7 +1424,7 @@ release(PreparedGraphicsObjects *prepared_objects) {
// explicitly prepared by the user before it may be
// rendered.
////////////////////////////////////////////////////////////////////
ShaderContext *ShaderExpansion::
ShaderContext *Shader::
prepare_now(PreparedGraphicsObjects *prepared_objects,
GraphicsStateGuardianBase *gsg) {
Contexts::const_iterator ci;
@ -1397,15 +1440,15 @@ prepare_now(PreparedGraphicsObjects *prepared_objects,
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::clear_prepared
// Function: Shader::clear_prepared
// Access: Private
// Description: Removes the indicated PreparedGraphicsObjects table
// from the ShaderExpansion's table, without actually releasing
// from the Shader's table, without actually releasing
// the texture. This is intended to be called only from
// PreparedGraphicsObjects::release_texture(); it should
// never be called by user code.
////////////////////////////////////////////////////////////////////
void ShaderExpansion::
void Shader::
clear_prepared(PreparedGraphicsObjects *prepared_objects) {
Contexts::iterator ci;
ci = _contexts.find(prepared_objects);
@ -1419,13 +1462,13 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) {
}
////////////////////////////////////////////////////////////////////
// Function: ShaderExpansion::release_all
// Function: Shader::release_all
// Access: Published
// Description: Frees the context allocated on all objects for which
// the texture has been declared. Returns the number of
// contexts which have been freed.
////////////////////////////////////////////////////////////////////
int ShaderExpansion::
int Shader::
release_all() {
// We have to traverse a copy of the _contexts list, because the
// PreparedGraphicsObjects object will call clear_prepared() in response
@ -1450,3 +1493,28 @@ release_all() {
return num_freed;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::ShaderCapabilities::clear()
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void Shader::ShaderCaps::
clear() {
#ifdef HAVE_CG
_active_vprofile = 0;
_active_fprofile = 0;
_ultimate_vprofile = 0;
_ultimate_fprofile = 0;
#endif
}
////////////////////////////////////////////////////////////////////
// Function: Shader::register_with_read_factory
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
void Shader::
register_with_read_factory() {
// IMPLEMENT ME
}

View File

@ -1,4 +1,4 @@
// Filename: shaderExpansion.h
// Filename: shader.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
@ -16,8 +16,8 @@
//
////////////////////////////////////////////////////////////////////
#ifndef SHADEREXPANSION_H
#define SHADEREXPANSION_H
#ifndef SHADER_H
#define SHADER_H
#include "pandabase.h"
#include "typedReferenceCount.h"
@ -34,23 +34,21 @@ typedef struct _CGparameter *CGparameter;
#endif
////////////////////////////////////////////////////////////////////
// Class : ShaderExpansion
// Summary: A shader can contain context-sensitive macros.
// A ShaderExpansion is the output you get when you
// run the macro preprocessor on a shader.
// The ShaderExpansion contains the shader's
// macroexpanded text, an analysis of the shader's
// parameters, and a map of ShaderContext
// objects.
// Class : Shader
// Summary:
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_GOBJ ShaderExpansion: public TypedReferenceCount {
class EXPCL_PANDA_GOBJ Shader: public TypedReferenceCount {
PUBLISHED:
INLINE const string &get_name() const;
INLINE const string &get_text() const;
INLINE const string &get_header() const;
static PT(Shader) load(const Filename &file);
static PT(Shader) load(const string &file);
static PT(Shader) make(const string &body);
INLINE const Filename &get_filename() const;
INLINE const string &get_text() const;
INLINE const string &get_header() const;
INLINE bool get_error_flag() const;
void prepare(PreparedGraphicsObjects *prepared_objects);
@ -191,7 +189,7 @@ public:
int _ultimate_fprofile;
pset <ShaderBug> _bug_list;
#endif
INLINE void clear();
void clear();
INLINE bool operator == (const ShaderCaps &other) const;
INLINE ShaderCaps();
};
@ -262,15 +260,20 @@ public:
pvector <ShaderVarSpec> _var_spec;
protected:
string _name;
Filename _filename;
string _text;
string _header;
bool _error_flag;
int _parse;
bool _loaded;
typedef pair < string, string > ExpansionKey;
typedef pmap < ExpansionKey, ShaderExpansion * > ExpansionCache;
static ExpansionCache _expansion_cache;
static ShaderCaps _default_caps;
typedef phash_map < Filename , Shader * > LoadTable;
typedef phash_map < string , Shader * > MakeTable;
static LoadTable _load_table;
static MakeTable _make_table;
friend class ShaderContext;
friend class PreparedGraphicsObjects;
@ -278,17 +281,15 @@ public:
typedef pmap <PreparedGraphicsObjects *, ShaderContext *> Contexts;
Contexts _contexts;
private:
ShaderExpansion(const string &name, const string &text,
const ShaderCaps &caps);
Shader(const Filename &name, const string &text);
void clear_prepared(PreparedGraphicsObjects *prepared_objects);
public:
static PT(ShaderExpansion) make(const string &name, const string &body,
const ShaderCaps &caps);
static void register_with_read_factory();
static PT(Shader) make(const string &name, const string &body);
~ShaderExpansion();
~Shader();
public:
static TypeHandle get_class_type() {
@ -296,7 +297,7 @@ public:
}
static void init_type() {
TypedReferenceCount::init_type();
register_type(_type_handle, "ShaderExpansion",
register_type(_type_handle, "Shader",
TypedReferenceCount::get_class_type());
}
virtual TypeHandle get_type() const {
@ -308,6 +309,6 @@ public:
static TypeHandle _type_handle;
};
#include "shaderExpansion.I"
#include "shader.I"
#endif

View File

@ -22,8 +22,8 @@
// Description:
////////////////////////////////////////////////////////////////////
INLINE ShaderContext::
ShaderContext(ShaderExpansion *se) :
_expansion(se)
ShaderContext(Shader *se) :
_shader(se)
{
}
@ -32,7 +32,7 @@ ShaderContext(ShaderExpansion *se) :
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE ShaderExpansion *ShaderContext::
get_expansion() const {
return _expansion;
INLINE Shader *ShaderContext::
get_shader() const {
return _shader;
}

View File

@ -22,7 +22,7 @@
#include "pandabase.h"
#include "internalName.h"
#include "savedContext.h"
#include "shaderExpansion.h"
#include "shader.h"
////////////////////////////////////////////////////////////////////
// Class : ShaderContext
@ -38,13 +38,13 @@
class EXPCL_PANDA_GOBJ ShaderContext: public SavedContext {
public:
INLINE ShaderContext(ShaderExpansion *se);
INLINE ShaderContext(Shader *se);
PUBLISHED:
INLINE ShaderExpansion *get_expansion() const;
INLINE Shader *get_shader() const;
public:
ShaderExpansion *_expansion;
Shader *_shader;
public:
static TypeHandle get_class_type() {

View File

@ -58,7 +58,7 @@ class GraphicsOutput;
class Texture;
class TextureContext;
class ShaderContext;
class ShaderExpansion;
class Shader;
class RenderState;
class TransformState;
class Material;
@ -138,7 +138,7 @@ public:
virtual GeomContext *prepare_geom(Geom *geom)=0;
virtual void release_geom(GeomContext *gc)=0;
virtual ShaderContext *prepare_shader(ShaderExpansion *shader)=0;
virtual ShaderContext *prepare_shader(Shader *shader)=0;
virtual void release_shader(ShaderContext *sc)=0;
virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data)=0;

View File

@ -32,6 +32,7 @@
#include "cullTraverserData.h"
#include "pStatCollector.h"
#include "deletedChain.h"
#include "graphicsStateGuardianBase.h"
class CullTraverser;

View File

@ -9,7 +9,6 @@
#include "selectiveChildNode.cxx"
#include "sequenceNode.cxx"
#include "shadeModelAttrib.cxx"
#include "shader.cxx"
#include "shaderInput.cxx"
#include "shaderAttrib.cxx"
#include "shaderPool.cxx"

View File

@ -602,23 +602,23 @@ compare_to(const Attribute &other) const {
}
////////////////////////////////////////////////////////////////////
// Function: RenderState::get_shader_expansion
// Function: RenderState::get_generated_shader
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ShaderExpansion *RenderState::
get_shader_expansion() const {
return _shader_expansion;
INLINE ShaderAttrib *RenderState::
get_generated_shader() const {
return (ShaderAttrib*)(RenderAttrib*)_generated_shader;
}
////////////////////////////////////////////////////////////////////
// Function: RenderState::set_shader_expansion
// Function: RenderState::set_generated_shader
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void RenderState::
set_shader_expansion(ShaderExpansion *exp) {
_shader_expansion = exp;
set_generated_shader(ShaderAttrib *attr) {
_generated_shader = (RenderAttrib*)attr;
}
////////////////////////////////////////////////////////////////////

View File

@ -31,7 +31,6 @@
#include "texMatrixAttrib.h"
#include "geomMunger.h"
#include "weakPointerTo.h"
#include "shaderExpansion.h"
#include "reMutex.h"
#include "pmutex.h"
#include "deletedChain.h"
@ -159,8 +158,8 @@ public:
void store_into_slots(AttribSlots *slots) const;
static void bin_removed(int bin_index);
INLINE ShaderExpansion *get_shader_expansion() const;
INLINE void set_shader_expansion(ShaderExpansion *exp);
INLINE ShaderAttrib *get_generated_shader() const;
INLINE void set_generated_shader(ShaderAttrib *attr);
INLINE static void flush_level();
@ -300,10 +299,11 @@ private:
int _bin_index;
int _draw_order;
// If this renderstate contains a Shader, then the macroexpansion
// of the shader needs to be cached (to avoid having to regenerate
// it each time this RenderState is applied).
PT(ShaderExpansion) _shader_expansion;
// If this state contains an "auto" ShaderAttrib, then an explicit
// ShaderAttrib will be synthesized by the runtime and stored here.
// I can't declare this as a ShaderAttrib because that would create
// a circular include-file dependency problem. Aaargh.
PT(RenderAttrib) _generated_shader;
// We also cache the pointer to some critical attribs stored in the
// state, if they exist.

View File

@ -1,79 +0,0 @@
// Filename: shader.I
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: Shader::get_file
// Access: Published
// Description: Returns null string if shader was not loaded from
// a source file.
////////////////////////////////////////////////////////////////////
INLINE const Filename &Shader::
get_file() const {
return _file;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::get_body
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE const string &Shader::
get_body() const {
return _body;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::get_name
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE const string &Shader::
get_name() const {
return _name;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::get_loaded
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool Shader::
get_loaded() const {
return _loaded;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::get_load_error
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool Shader::
get_load_error() const {
return _load_error;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::get_preprocessor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE int Shader::
get_preprocessor() const {
return _preprocessor;
}

View File

@ -1,169 +0,0 @@
// Filename: shader.cxx
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "shader.h"
#include "virtualFileSystem.h"
TypeHandle Shader::_type_handle;
Shader::LoadTable Shader::_load_table;
Shader::MakeTable Shader::_make_table;
////////////////////////////////////////////////////////////////////
// Function: Shader::Constructor
// Access: Private
// Description:
////////////////////////////////////////////////////////////////////
Shader::
Shader() {
this -> _load_error = false;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::Destructor
// Access: Private
// Description:
////////////////////////////////////////////////////////////////////
Shader::
~Shader() {
if (_loaded) {
LoadTableKey key(_file, _preprocessor);
_load_table.erase(key);
} else {
MakeTableKey key(_body, _preprocessor);
_make_table.erase(key);
}
}
////////////////////////////////////////////////////////////////////
// Function: Shader::load
// Access: Published, Static
// Description:
////////////////////////////////////////////////////////////////////
CPT(Shader) Shader::
load(const string &file, int preprocessor) {
return load(Filename(file), preprocessor);
}
////////////////////////////////////////////////////////////////////
// Function: Shader::load
// Access: Published, Static
// Description:
////////////////////////////////////////////////////////////////////
CPT(Shader) Shader::
load(const Filename &file, int preprocessor) {
LoadTableKey key(file, preprocessor);
LoadTable::const_iterator i = _load_table.find(key);
if (i != _load_table.end()) {
return i->second;
}
Shader *result = new Shader;
result->_name = file;
result->_file = file;
result->_loaded = true;
result->_preprocessor = preprocessor;
result->_fixed_expansion = 0;
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
if (!vfs->read_file(file, result->_body, true)) {
cerr << "Could not read shader file: " << file << "\n";
result->_body = "";
result->_load_error = true;
}
_load_table[key] = result;
return result;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::make
// Access: Published, Static
// Description:
////////////////////////////////////////////////////////////////////
CPT(Shader) Shader::
make(const string &body, int preprocessor) {
MakeTableKey key(body, preprocessor);
MakeTable::const_iterator i = _make_table.find(key);
if (i != _make_table.end()) {
return i->second;
}
Shader *result = new Shader;
result->_name = "generated shader";
result->_file = "";
result->_loaded = false;
result->_preprocessor = preprocessor;
result->_fixed_expansion = 0;
result->_body = body;
_make_table[key] = result;
return result;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::macroexpand
// Access: Public
// Description: The eventual plan is that shaders will be run through
// a macro preprocessor in order to generate the actual
// shader text in Cg, GLSL, HLSL, or whatever. The
// macro preprocessor will be able to query the RenderState
// and generate different shader code for different states.
//
// The macroexpansion of the shader is stored in an object
// of class ShaderExpansion. This is somewhat expensive
// to generate, so the ShaderExpansion is cached inside the
// the RenderState itself. The ShaderExpansion contains
// a map of ShaderContexts, each containing a compiled
// copy of the shader's macroexpansion.
//
// Any given shader might not contain any ifdefs that
// depend on the RenderState. If macroexpand determines
// that a given shader is not state-sensitive, it can cache
// the macroexpansion in the field "_fixed_expansion."
//
// The preprocessing is usually done by a built-in macro
// preprocessing function. However, the user can write
// his own preprocessor if he wishes to do so. A user-
// supplied preprocessor can generate arbitrary code ---
// in fact, it doesn't need to look at the input string
// if it does not wish to do so.
//
// Currently, macroexpand is just a stub that returns an
// expansion which is exactly equal to the input string.
//
// The "caps" parameter should describe the capabilities
// of the gsg on which this is intended to run.
////////////////////////////////////////////////////////////////////
PT(ShaderExpansion) Shader::
macroexpand(const RenderState *context,
const ShaderExpansion::ShaderCaps &caps) const {
if (_fixed_expansion) {
return _fixed_expansion;
}
// I am casting away the 'const' so as to be able
// to write to this field. This field is just a cache.
((Shader*)this)->_fixed_expansion = ShaderExpansion::make(_name,_body,caps);
return _fixed_expansion;
}
////////////////////////////////////////////////////////////////////
// Function: Shader::register_with_read_factory
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
void Shader::
register_with_read_factory() {
// IMPLEMENT ME
}

View File

@ -1,97 +0,0 @@
// Filename: shader.h
// Created by: jyelon (01Sep05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef SHADER_H
#define SHADER_H
#include "pandabase.h"
#include "typedWritableReferenceCount.h"
#include "shaderExpansion.h"
#include "pointerTo.h"
#include "dcast.h"
class RenderState;
////////////////////////////////////////////////////////////////////
// Class : Shader
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PGRAPH Shader: public TypedWritableReferenceCount {
PUBLISHED:
static CPT(Shader) load(const Filename &file, int preprocessor=0);
static CPT(Shader) load(const string &file, int preprocessor=0);
static CPT(Shader) make(const string &body, int preprocessor=0);
INLINE const string &get_name() const;
INLINE const Filename &get_file() const;
INLINE const string &get_body() const;
INLINE int get_preprocessor() const;
INLINE bool get_loaded() const;
INLINE bool get_load_error() const;
PT(ShaderExpansion) macroexpand(const RenderState *context,
const ShaderExpansion::ShaderCaps &caps) const;
public:
Shader();
~Shader();
private:
string _name;
Filename _file;
string _body;
bool _loaded;
bool _load_error;
int _preprocessor;
PT(ShaderExpansion) _fixed_expansion;
typedef pair < Filename, int > LoadTableKey;
typedef pair < string, int > MakeTableKey;
typedef pmap < LoadTableKey , Shader * > LoadTable;
typedef pmap < MakeTableKey , Shader * > MakeTable;
static LoadTable _load_table;
static MakeTable _make_table;
public:
static void register_with_read_factory();
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedWritableReferenceCount::init_type();
register_type(_type_handle, "Shader",
TypedWritableReferenceCount::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "shader.I"
#endif // SHADER_H

View File

@ -100,16 +100,7 @@ ns_load_shader(const string &str) {
// ***** face_index ???
if (shader == (CPT(Shader)) NULL) {
int preprocessor;
preprocessor = 0;
shader = Shader::load (filename, preprocessor);
if (shader) {
if (shader -> get_load_error ( )) {
// delete shader;
shader = (CPT(Shader)) NULL;
}
}
shader = Shader::load (filename);
}
if (shader == (CPT(Shader)) NULL) {