remove _current_texture, etc.

This commit is contained in:
David Rose 2005-09-25 18:02:11 +00:00
parent deb254eba7
commit e51b471570
5 changed files with 58 additions and 71 deletions

View File

@ -303,11 +303,6 @@ reset() {
_material_force_color.set(1.0f, 1.0f, 1.0f, 1.0f);
_light_color_scale.set(1.0f, 1.0f, 1.0f, 1.0f);
_current_texture = DCAST(TextureAttrib, TextureAttrib::make_all_off());
_current_tex_mat = DCAST(TexMatrixAttrib, TexMatrixAttrib::make());
_needs_tex_mat = false;
_current_tex_gen = DCAST(TexGenAttrib, TexGenAttrib::make());
_needs_tex_gen = false;
_tex_gen_modifies_mat = false;
_last_max_stage_index = 0;
@ -744,10 +739,6 @@ end_scene() {
// Put the state into the 'unknown' state, forcing a reload.
_state_rs = 0;
_state.clear_to_zero();
// We need to reset this to force a dynamic texture to be reloaded
// next frame even if it is the only texture in the scene.
_current_texture = DCAST(TextureAttrib, TextureAttrib::make_all_off());
}
////////////////////////////////////////////////////////////////////

View File

@ -328,11 +328,6 @@ protected:
Colorf _material_force_color;
LVecBase4f _light_color_scale;
CPT(TextureAttrib) _current_texture;
CPT(TexMatrixAttrib) _current_tex_mat;
bool _needs_tex_mat;
CPT(TexGenAttrib) _current_tex_gen;
bool _needs_tex_gen;
bool _tex_gen_modifies_mat;
bool _tex_gen_point_sprite;
int _last_max_stage_index;

View File

@ -1989,6 +1989,10 @@ set_state_and_transform(const RenderState *target,
_target.clear_to_defaults();
target->store_into_slots(&_target);
_state_rs = 0;
// There might be some physical limits to the actual target
// attributes we issue. Impose them now.
_target._texture = _target._texture->filter_to_max(_max_texture_stages);
if (_target._alpha_test != _state._alpha_test) {
do_issue_alpha_test();
@ -2061,14 +2065,11 @@ set_state_and_transform(const RenderState *target,
}
if (_target._tex_gen != _state._tex_gen) {
_current_tex_gen = _target._tex_gen;
_state._texture = 0;
_state._tex_gen = _target._tex_gen;
}
if (_target._tex_matrix != _state._tex_matrix) {
_current_tex_mat = _target._tex_matrix;
_needs_tex_mat = true;
_state._tex_matrix = _target._tex_matrix;
}
@ -2339,10 +2340,11 @@ void DXGraphicsStateGuardian8::
do_issue_texture() {
DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
CPT(TextureAttrib) new_texture = _target._texture->filter_to_max(_max_texture_stages);
int num_stages = new_texture->get_num_on_stages();
int num_old_stages = _current_texture->get_num_on_stages();
int num_stages = _target._texture->get_num_on_stages();
int num_old_stages = 0;
if (_state._texture != (TextureAttrib *)NULL) {
num_old_stages = _state._texture->get_num_on_stages();
}
nassertv(num_stages <= _max_texture_stages &&
num_old_stages <= _max_texture_stages);
@ -2359,8 +2361,8 @@ do_issue_texture() {
int i;
for (i = 0; i < num_stages; i++) {
TextureStage *stage = new_texture->get_on_stage(i);
Texture *texture = new_texture->get_on_texture(stage);
TextureStage *stage = _target._texture->get_on_stage(i);
Texture *texture = _target._texture->get_on_texture(stage);
nassertv(texture != (Texture *)NULL);
const InternalName *name = stage->get_texcoord_name();
@ -2381,12 +2383,12 @@ do_issue_texture() {
bool texcoords_3d = false;
CPT(TransformState) tex_mat = TransformState::make_identity();
if (_current_tex_mat->has_stage(stage)) {
tex_mat = _current_tex_mat->get_transform(stage);
if (_state._tex_matrix->has_stage(stage)) {
tex_mat = _state._tex_matrix->get_transform(stage);
}
// Issue the texgen mode.
TexGenAttrib::Mode mode = _current_tex_gen->get_mode(stage);
TexGenAttrib::Mode mode = _state._tex_gen->get_mode(stage);
bool any_point_sprite = false;
switch (mode) {
@ -2515,8 +2517,6 @@ do_issue_texture() {
for (i = num_stages; i < num_old_stages; i++) {
_d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
}
_current_texture = new_texture;
}
////////////////////////////////////////////////////////////////////

View File

@ -1344,9 +1344,9 @@ update_standard_vertex_arrays()
// least those for which we're not generating texture coordinates
// automatically.
const Geom::ActiveTextureStages &active_stages =
_current_texture->get_on_stages();
_state._texture->get_on_stages();
const Geom::NoTexCoordStages &no_texcoords =
_current_tex_gen->get_no_texcoords();
_state._tex_gen->get_no_texcoords();
int max_stage_index = (int)active_stages.size();
int stage_index = 0;
@ -1440,9 +1440,9 @@ update_standard_vertex_arrays()
// least those for which we're not generating texture coordinates
// automatically.
const Geom::ActiveTextureStages &active_stages =
_current_texture->get_on_stages();
_state._texture->get_on_stages();
const Geom::NoTexCoordStages &no_texcoords =
_current_tex_gen->get_no_texcoords();
_state._tex_gen->get_no_texcoords();
int max_stage_index = (int)active_stages.size();
int stage_index = 0;
@ -4583,7 +4583,14 @@ set_state_and_transform(const RenderState *target,
_target.clear_to_defaults();
target->store_into_slots(&_target);
_state_rs = 0;
// There might be some physical limits to the actual target
// attributes we issue. Impose them now.
_target._texture = _target._texture->filter_to_max(_max_texture_stages);
bool needs_tex_gen = false;
bool needs_tex_mat = false;
if (_target._alpha_test != _state._alpha_test) {
do_issue_alpha_test();
_state._alpha_test = _target._alpha_test;
@ -4655,14 +4662,13 @@ set_state_and_transform(const RenderState *target,
}
if (_target._tex_gen != _state._tex_gen) {
_current_tex_gen = _target._tex_gen;
_needs_tex_gen = true;
_state._tex_gen = _target._tex_gen;
needs_tex_gen = true;
_state._tex_gen = _target._tex_gen;
}
if (_target._tex_matrix != _state._tex_matrix) {
_current_tex_mat = _target._tex_matrix;
_needs_tex_mat = true;
needs_tex_mat = true;
_state._tex_matrix = _target._tex_matrix;
}
@ -4678,6 +4684,11 @@ set_state_and_transform(const RenderState *target,
if (_target._texture != _state._texture) {
do_issue_texture();
_state._texture = _target._texture;
// Changing the set of texture stages will require us to reissue the
// texgen and texmat attribs.
needs_tex_gen = true;
needs_tex_mat = true;
}
if (_target._material != _state._material) {
@ -4693,26 +4704,23 @@ set_state_and_transform(const RenderState *target,
// If one of the previously-loaded TexGen modes modified the texture
// matrix, then if either state changed, we have to change both of
// them now.
if (_tex_gen_modifies_mat &&
(_needs_tex_mat || _needs_tex_gen)) {
_needs_tex_mat = true;
_needs_tex_gen = true;
if (_tex_gen_modifies_mat && (needs_tex_mat || needs_tex_gen)) {
needs_tex_mat = true;
needs_tex_gen = true;
}
// Apply the texture matrix, if needed.
if (_needs_tex_mat) {
_needs_tex_mat = false;
int num_stages = _current_texture->get_num_on_stages();
if (needs_tex_mat) {
int num_stages = _state._texture->get_num_on_stages();
nassertv(num_stages <= _max_texture_stages);
for (int i = 0; i < num_stages; i++) {
TextureStage *stage = _current_texture->get_on_stage(i);
TextureStage *stage = _state._texture->get_on_stage(i);
_glActiveTexture(GL_TEXTURE0 + i);
GLP(MatrixMode)(GL_TEXTURE);
if (_current_tex_mat->has_stage(stage)) {
GLP(LoadMatrixf)(_current_tex_mat->get_mat(stage).get_data());
if (_state._tex_matrix->has_stage(stage)) {
GLP(LoadMatrixf)(_state._tex_matrix->get_mat(stage).get_data());
} else {
GLP(LoadIdentity)();
@ -4728,11 +4736,10 @@ set_state_and_transform(const RenderState *target,
report_my_gl_errors();
}
if (_needs_tex_gen) {
_needs_tex_gen = false;
if (needs_tex_gen) {
bool force_normal = false;
int num_stages = _current_texture->get_num_on_stages();
int num_stages = _state._texture->get_num_on_stages();
nassertv(num_stages <= _max_texture_stages);
// These are passed in for the four OBJECT_PLANE or EYE_PLANE
@ -4750,7 +4757,7 @@ set_state_and_transform(const RenderState *target,
bool got_point_sprites = false;
for (int i = 0; i < num_stages; i++) {
TextureStage *stage = _current_texture->get_on_stage(i);
TextureStage *stage = _state._texture->get_on_stage(i);
_glActiveTexture(GL_TEXTURE0 + i);
GLP(Disable)(GL_TEXTURE_GEN_S);
GLP(Disable)(GL_TEXTURE_GEN_T);
@ -4760,7 +4767,7 @@ set_state_and_transform(const RenderState *target,
GLP(TexEnvi)(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_FALSE);
}
TexGenAttrib::Mode mode = _current_tex_gen->get_mode(stage);
TexGenAttrib::Mode mode = _state._tex_gen->get_mode(stage);
switch (mode) {
case TexGenAttrib::M_off:
case TexGenAttrib::M_light_vector:
@ -5026,10 +5033,11 @@ void CLP(GraphicsStateGuardian)::
do_issue_texture() {
DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
CPT(TextureAttrib) new_texture = _target._texture->filter_to_max(_max_texture_stages);
int num_stages = new_texture->get_num_on_stages();
int num_old_stages = _current_texture->get_num_on_stages();
int num_stages = _target._texture->get_num_on_stages();
int num_old_stages = 0;
if (_state._texture != (TextureAttrib *)NULL) {
num_old_stages = _state._texture->get_num_on_stages();
}
nassertv(num_stages <= _max_texture_stages &&
num_old_stages <= _max_texture_stages);
@ -5040,13 +5048,13 @@ do_issue_texture() {
int last_stage = -1;
int i;
for (i = 0; i < num_stages; i++) {
TextureStage *stage = new_texture->get_on_stage(i);
Texture *texture = new_texture->get_on_texture(stage);
TextureStage *stage = _target._texture->get_on_stage(i);
Texture *texture = _target._texture->get_on_texture(stage);
nassertv(texture != (Texture *)NULL);
if (i >= num_old_stages ||
stage != _current_texture->get_on_stage(i) ||
texture != _current_texture->get_on_texture(stage) ||
stage != _state._texture->get_on_stage(i) ||
texture != _state._texture->get_on_texture(stage) ||
stage->involves_color_scale()) {
// Stage i has changed. Issue the texture on this stage.
_glActiveTexture(GL_TEXTURE0 + i);
@ -5189,8 +5197,8 @@ do_issue_texture() {
}
GLP(MatrixMode)(GL_TEXTURE);
if (_current_tex_mat->has_stage(stage)) {
GLP(LoadMatrixf)(_current_tex_mat->get_mat(stage).get_data());
if (_state._tex_matrix->has_stage(stage)) {
GLP(LoadMatrixf)(_state._tex_matrix->get_mat(stage).get_data());
} else {
GLP(LoadIdentity)();
}
@ -5220,13 +5228,6 @@ do_issue_texture() {
}
}
_current_texture = new_texture;
// Changing the set of texture stages will require us to reissue the
// texgen and texmat attribs.
_needs_tex_gen = true;
_needs_tex_mat = true;
report_my_gl_errors();
}

View File

@ -284,7 +284,7 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
int texslot = _cg_varying[i].append_uv;
if (texslot >= 0) {
const Geom::ActiveTextureStages &active_stages =
gsg->_current_texture->get_on_stages();
gsg->_state._texture->get_on_stages();
if (texslot < (int)active_stages.size()) {
TextureStage *stage = active_stages[texslot];
name = name->append(stage->get_texcoord_name()->get_name());