*** empty log message ***

This commit is contained in:
David Rose 2001-05-11 23:18:38 +00:00
parent 379da28f75
commit 82b0ce0d37
6 changed files with 178 additions and 171 deletions

View File

@ -7,6 +7,18 @@
#include <graphicsWindow.h>
////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::LightInfo::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE GLGraphicsStateGuardian::LightInfo::
LightInfo() {
_light = (Light *)NULL;
_enabled = false;
_next_enabled = false;
}
////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::activate
// Access: Public
@ -861,14 +873,14 @@ get_clip_plane_id(int index) const {
////////////////////////////////////////////////////////////////////
INLINE void GLGraphicsStateGuardian::enable_light(int light, bool val)
{
if ( _light_enabled[light] != val )
if ( _light_info[light]._enabled != val )
{
_light_enabled[light] = val;
_light_info[light]._enabled = val;
if ( val )
{
#ifdef GSG_VERBOSE
glgsg_cat.debug()
<< "glEnable(GL_LIGHT_" << light << ")" << endl;
<< "glEnable(GL_LIGHT" << light << ")" << endl;
#endif
glEnable( get_light_id( light ) );
}
@ -876,7 +888,7 @@ INLINE void GLGraphicsStateGuardian::enable_light(int light, bool val)
{
#ifdef GSG_VERBOSE
glgsg_cat.debug()
<< "glDisable(GL_LIGHT_" << light << ")" << endl;
<< "glDisable(GL_LIGHT" << light << ")" << endl;
#endif
glDisable( get_light_id( light ) );
}

View File

@ -152,8 +152,7 @@ issue_transformed_color_gl(const Geom *geom, Geom::ColorIterator &citerator,
////////////////////////////////////////////////////////////////////
GLGraphicsStateGuardian::
GLGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) {
_light_enabled = (bool *)NULL;
_cur_light_enabled = (bool *)NULL;
_light_info = (LightInfo *)NULL;
_clip_plane_enabled = (bool *)NULL;
_cur_clip_plane_enabled = (bool *)NULL;
@ -281,21 +280,17 @@ reset() {
}
// Set up the light id map
glGetIntegerv( GL_MAX_LIGHTS, &_max_lights );
_available_light_ids = PTA(Light*)(_max_lights);
_light_enabled = new bool[_max_lights];
_cur_light_enabled = new bool[_max_lights];
int i;
for (i = 0; i < _max_lights; i++ ) {
_available_light_ids[i] = NULL;
_light_enabled[i] = false;
}
GLint max_lights;
glGetIntegerv( GL_MAX_LIGHTS, &max_lights );
_max_lights = max_lights;
_light_info = new LightInfo[_max_lights];
// Set up the clip plane id map
glGetIntegerv(GL_MAX_CLIP_PLANES, &_max_clip_planes);
_available_clip_plane_ids = PTA(PlaneNode*)(_max_clip_planes);
_clip_plane_enabled = new bool[_max_clip_planes];
_cur_clip_plane_enabled = new bool[_max_clip_planes];
int i;
for (i = 0; i < _max_clip_planes; i++) {
_available_clip_plane_ids[i] = NULL;
_clip_plane_enabled[i] = false;
@ -518,16 +513,14 @@ render_frame(const AllAttributesWrapper &initial_state) {
// Now we're done with the frame processing. Clean up.
if(_lighting_enabled) {
if (_lighting_enabled) {
// Let's turn off all the lights we had on, and clear the light
// cache--to force the lights to be reissued next frame, in case
// their parameters or positions have changed between frames.
for (int i = 0; i < _max_lights; i++) {
if (_light_enabled[i]) {
enable_light(i, false);
}
_available_light_ids[i] = NULL;
enable_light(i, false);
_light_info[i]._light = (Light *)NULL;
}
// Also force the lighting state to unlit, so that issue_light()
@ -2420,9 +2413,9 @@ void GLGraphicsStateGuardian::apply_light( Spotlight* light )
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void GLGraphicsStateGuardian::apply_light( AmbientLight* light )
void GLGraphicsStateGuardian::apply_light( AmbientLight* )
{
_cur_ambient_light = _cur_ambient_light + light->get_color();
// Ambient lights are handled as a special case in issue_light().
}
////////////////////////////////////////////////////////////////////
@ -2687,81 +2680,80 @@ void GLGraphicsStateGuardian::issue_light(const LightAttribute *attrib )
nassertv(attrib->get_properties_is_on());
// activate();
// Initialize the current ambient light total and currently enabled
// Initialize the current ambient light total and newly enabled
// light list
_cur_ambient_light.set(0, 0, 0, 1);
Colorf cur_ambient_light(0.0, 0.0, 0.0, 1.0);
int i;
for (i = 0; i < _max_lights; i++)
_cur_light_enabled[i] = false;
for (i = 0; i < _max_lights; i++) {
_light_info[i]._next_enabled = false;
}
int num_enabled = 0;
LightAttribute::const_iterator li;
for (li = attrib->begin(); li != attrib->end(); ++li) {
_cur_light_id = -1;
num_enabled++;
enable_lighting(true);
Light *light = (*li);
nassertv(light != (Light *)NULL);
// Ambient lights don't require specific light ids
// Simply add in the ambient contribution to the current total
if (light->get_light_type() == AmbientLight::get_class_type()) {
light->apply(this);
// We need to indicate that no light id is necessary because
// it's an ambient light
_cur_light_id = -2;
}
// Ambient lights don't require specific light ids; simply add
// in the ambient contribution to the current total
cur_ambient_light += light->get_color();
// Check to see if this light has already been bound to an id
for (i = 0; i < _max_lights; i++) {
if (_available_light_ids[i] == light) {
// Light has already been bound to an id, we only need
// to enable the light, not apply it
_cur_light_id = -2;
enable_light(i, true);
_cur_light_enabled[i] = true;
break;
}
}
// See if there are any unbound light ids
if (_cur_light_id == -1) {
} else {
// Check to see if this light has already been bound to an id
_cur_light_id = -1;
for (i = 0; i < _max_lights; i++) {
if (_available_light_ids[i] == NULL) {
_available_light_ids[i] = light;
_cur_light_id = i;
if (_light_info[i]._light == light) {
// Light has already been bound to an id, we only need
// to enable the light, not apply it
_cur_light_id = -2;
enable_light(i, true);
_light_info[i]._next_enabled = true;
break;
}
}
}
// If there were no unbound light ids, see if we can replace
// a currently unused but previously bound id
if (_cur_light_id == -1) {
for (i = 0; i < _max_lights; i++) {
if (attrib->is_off(_available_light_ids[i])) {
_available_light_ids[i] = light;
_cur_light_id = i;
break;
}
// See if there are any unbound light ids
if (_cur_light_id == -1) {
for (i = 0; i < _max_lights; i++) {
if (_light_info[i]._light == (Light *)NULL) {
_light_info[i]._light = light;
_cur_light_id = i;
break;
}
}
}
// If there were no unbound light ids, see if we can replace
// a currently unused but previously bound id
if (_cur_light_id == -1) {
for (i = 0; i < _max_lights; i++) {
if (attrib->is_off(_light_info[i]._light)) {
_light_info[i]._light = light;
_cur_light_id = i;
break;
}
}
}
}
if (_cur_light_id >= 0) {
enable_light(_cur_light_id, true);
_cur_light_enabled[_cur_light_id] = true;
// We need to do something different for each type of light
light->apply(this);
} else if (_cur_light_id == -1) {
glgsg_cat.error()
<< "issue_light() - failed to bind light to id" << endl;
if (_cur_light_id >= 0) {
enable_light(_cur_light_id, true);
_light_info[i]._next_enabled = true;
// We need to do something different for each type of light
light->apply(this);
} else if (_cur_light_id == -1) {
glgsg_cat.error()
<< "issue_light() - failed to bind light to id" << endl;
}
}
}
// Disable all unused lights
for (i = 0; i < _max_lights; i++) {
if (_cur_light_enabled[i] == false)
if (!_light_info[i]._next_enabled)
enable_light(i, false);
}
@ -2769,7 +2761,7 @@ void GLGraphicsStateGuardian::issue_light(const LightAttribute *attrib )
if (num_enabled == 0) {
enable_lighting(false);
} else {
call_glLightModelAmbient(_cur_ambient_light);
call_glLightModelAmbient(cur_ambient_light);
}
report_errors();
}
@ -3932,13 +3924,9 @@ print_gfx_visual() {
////////////////////////////////////////////////////////////////////
void GLGraphicsStateGuardian::
free_pointers() {
if (_light_enabled != (bool *)NULL) {
delete[] _light_enabled;
_light_enabled = (bool *)NULL;
}
if (_cur_light_enabled != (bool *)NULL) {
delete[] _cur_light_enabled;
_cur_light_enabled = (bool *)NULL;
if (_light_info != (LightInfo *)NULL) {
delete[] _light_info;
_light_info = (LightInfo *)NULL;
}
if (_clip_plane_enabled != (bool *)NULL) {
delete[] _clip_plane_enabled;
@ -4166,7 +4154,7 @@ dump_state(void)
dump << "\t\t" << "GL_LIGHTING " << _lighting_enabled << " " << (bool)glIsEnabled(GL_LIGHTING) << "\n";
for(i = 0; i < _max_lights; i++)
{
dump << "\t\t\t\t" << "GL_LIGHT" << i << " " << _light_enabled[i] << " " << (bool)glIsEnabled(GL_LIGHT0+i) << "\n";
dump << "\t\t\t\t" << "GL_LIGHT" << i << " " << _light_info[i]._enabled << " " << (bool)glIsEnabled(GL_LIGHT0+i) << "\n";
}
dump << "\t\t" << "GL_COLOR_MATERIAL " << _color_material_enabled << " " << (bool)glIsEnabled(GL_COLOR_MATERIAL) << "\n";
dump << "\t\t" << "GL_SCISSOR_TEST " << _scissor_enabled << " " << (bool)glIsEnabled(GL_SCISSOR_TEST) << "\n";

View File

@ -20,6 +20,7 @@
#include <depthTestProperty.h>
#include <stencilProperty.h>
#include <fog.h>
#include <pt_Light.h>
#ifdef WIN32_VC
// Must include windows.h before gl.h on NT
@ -295,13 +296,11 @@ protected:
bool _multisample_enabled;
bool _line_smooth_enabled;
bool _point_smooth_enabled;
bool* _light_enabled; // bool[_max_lights]
bool _scissor_enabled;
bool _lighting_enabled;
bool _texturing_enabled;
bool _dither_enabled;
bool _stencil_test_enabled;
bool* _clip_plane_enabled; // bool[_max_clip_planes]
bool _multisample_alpha_one_enabled;
bool _multisample_alpha_mask_enabled;
bool _blend_enabled;
@ -313,17 +312,25 @@ protected:
bool _alpha_transform_enabled;
int _decal_level;
PTA(Light*) _available_light_ids;
GLint _max_lights;
bool* _cur_light_enabled;
class LightInfo {
public:
INLINE LightInfo();
PT_Light _light;
bool _enabled;
bool _next_enabled;
};
int _max_lights;
LightInfo *_light_info; // LightInfo[_max_lights]
int _cur_light_id;
Colorf _cur_ambient_light;
LMatrix4f _current_projection_mat;
int _projection_mat_stack_count;
PTA(PlaneNode*) _available_clip_plane_ids;
GLint _max_clip_planes;
bool* _cur_clip_plane_enabled;
int _max_clip_planes;
PTA(PlaneNode *)_available_clip_plane_ids; // pPlaneNode[_max_clip_planes]
bool *_clip_plane_enabled; // bool[_max_clip_planes]
bool *_cur_clip_plane_enabled; // bool[_max_clip_planes]
int _cur_clip_plane_id;
CPT(DisplayRegion) _actual_display_region;

View File

@ -57,24 +57,6 @@ get_ambient() const {
return (_flags & F_ambient) != 0 ? _ambient : Colorf::zero();
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_ambient
// Access: Public
// Description: Specifies the ambient color setting of the material.
// This will be the multiplied by any ambient lights in
// effect on the material to set its base color.
//
// This is the color of the object as it appears in the
// absence of direct light.
//
// If this is not set, the object color will be used.
////////////////////////////////////////////////////////////////////
INLINE void Material::
set_ambient(const Colorf &color) {
_ambient = color;
_flags |= F_ambient;
}
////////////////////////////////////////////////////////////////////
// Function: Material::clear_ambient
// Access: Public
@ -108,26 +90,6 @@ get_diffuse() const {
return (_flags & F_diffuse) != 0 ? _diffuse : Colorf::zero();
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_diffuse
// Access: Public
// Description: Specifies the diffuse color setting of the material.
// This will be multiplied by any lights in effect on
// the material to get the color in the parts of the
// object illuminated by the lights.
//
// This is the primary color of an object; the color of
// the object as it appears in direct light, in the
// absence of highlights.
//
// If this is not set, the object color will be used.
////////////////////////////////////////////////////////////////////
INLINE void Material::
set_diffuse(const Colorf &color) {
_diffuse = color;
_flags |= F_diffuse;
}
////////////////////////////////////////////////////////////////////
// Function: Material::clear_diffuse
// Access: Public
@ -161,25 +123,6 @@ get_specular() const {
return (_flags & F_specular) != 0 ? _specular : Colorf::zero();
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_specular
// Access: Public
// Description: Specifies the diffuse color setting of the material.
// This will be multiplied by any lights in effect on
// the material to compute the color of specular
// highlights on the object.
//
// This is the highlight color of an object: the color
// of small highlight reflections.
//
// If this is not set, highlights will not appear.
////////////////////////////////////////////////////////////////////
INLINE void Material::
set_specular(const Colorf &color) {
_specular = color;
_flags |= F_specular;
}
////////////////////////////////////////////////////////////////////
// Function: Material::clear_specular
// Access: Public
@ -213,26 +156,6 @@ get_emission() const {
return (_flags & F_emission) != 0 ? _emission : Colorf::zero();
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_emission
// Access: Public
// Description: Specifies the emission color setting of the material.
// This is the color of the object as it appears in the
// absence of any light whatsover, including ambient
// light. It is as if the object is glowing by this
// color (although of course it will not illuminate
// neighboring objects).
//
// If this is not set, the object will not glow by its
// own light and will only appear visible in the
// presence of one or more lights.
////////////////////////////////////////////////////////////////////
INLINE void Material::
set_emission(const Colorf &color) {
_emission = color;
_flags |= F_emission;
}
////////////////////////////////////////////////////////////////////
// Function: Material::clear_emission
// Access: Public

View File

@ -34,6 +34,83 @@ operator = (const Material &copy) {
_flags = copy._flags;
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_ambient
// Access: Public
// Description: Specifies the ambient color setting of the material.
// This will be the multiplied by any ambient lights in
// effect on the material to set its base color.
//
// This is the color of the object as it appears in the
// absence of direct light.
//
// If this is not set, the object color will be used.
////////////////////////////////////////////////////////////////////
void Material::
set_ambient(const Colorf &color) {
_ambient = color;
_flags |= F_ambient;
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_diffuse
// Access: Public
// Description: Specifies the diffuse color setting of the material.
// This will be multiplied by any lights in effect on
// the material to get the color in the parts of the
// object illuminated by the lights.
//
// This is the primary color of an object; the color of
// the object as it appears in direct light, in the
// absence of highlights.
//
// If this is not set, the object color will be used.
////////////////////////////////////////////////////////////////////
void Material::
set_diffuse(const Colorf &color) {
_diffuse = color;
_flags |= F_diffuse;
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_specular
// Access: Public
// Description: Specifies the diffuse color setting of the material.
// This will be multiplied by any lights in effect on
// the material to compute the color of specular
// highlights on the object.
//
// This is the highlight color of an object: the color
// of small highlight reflections.
//
// If this is not set, highlights will not appear.
////////////////////////////////////////////////////////////////////
void Material::
set_specular(const Colorf &color) {
_specular = color;
_flags |= F_specular;
}
////////////////////////////////////////////////////////////////////
// Function: Material::set_emission
// Access: Public
// Description: Specifies the emission color setting of the material.
// This is the color of the object as it appears in the
// absence of any light whatsover, including ambient
// light. It is as if the object is glowing by this
// color (although of course it will not illuminate
// neighboring objects).
//
// If this is not set, the object will not glow by its
// own light and will only appear visible in the
// presence of one or more lights.
////////////////////////////////////////////////////////////////////
void Material::
set_emission(const Colorf &color) {
_emission = color;
_flags |= F_emission;
}
////////////////////////////////////////////////////////////////////
// Function: Material::compare_to
// Access: Public

View File

@ -29,22 +29,22 @@ PUBLISHED:
INLINE bool has_ambient() const;
INLINE const Colorf &get_ambient() const;
INLINE void set_ambient(const Colorf &color);
void set_ambient(const Colorf &color);
INLINE void clear_ambient();
INLINE bool has_diffuse() const;
INLINE const Colorf &get_diffuse() const;
INLINE void set_diffuse(const Colorf &color);
void set_diffuse(const Colorf &color);
INLINE void clear_diffuse();
INLINE bool has_specular() const;
INLINE const Colorf &get_specular() const;
INLINE void set_specular(const Colorf &color);
void set_specular(const Colorf &color);
INLINE void clear_specular();
INLINE bool has_emission() const;
INLINE const Colorf &get_emission() const;
INLINE void set_emission(const Colorf &color);
void set_emission(const Colorf &color);
INLINE void clear_emission();
INLINE float get_shininess() const;