|
@@ -27,8 +27,10 @@
|
|
|
#include "geomVertexReader.h"
|
|
#include "geomVertexReader.h"
|
|
|
#include "geomTriangles.h"
|
|
#include "geomTriangles.h"
|
|
|
#include "light.h"
|
|
#include "light.h"
|
|
|
|
|
+#include "lightMutexHolder.h"
|
|
|
|
|
|
|
|
CullableObject::FormatMap CullableObject::_format_map;
|
|
CullableObject::FormatMap CullableObject::_format_map;
|
|
|
|
|
+LightMutex CullableObject::_format_lock;
|
|
|
|
|
|
|
|
PStatCollector CullableObject::_munge_geom_pcollector("*:Munge:Geom");
|
|
PStatCollector CullableObject::_munge_geom_pcollector("*:Munge:Geom");
|
|
|
PStatCollector CullableObject::_munge_sprites_pcollector("*:Munge:Sprites");
|
|
PStatCollector CullableObject::_munge_sprites_pcollector("*:Munge:Sprites");
|
|
@@ -83,6 +85,11 @@ munge_geom(GraphicsStateGuardianBase *gsg,
|
|
|
// supports them.
|
|
// supports them.
|
|
|
gsg_bits &= ~(Geom::GR_point_perspective | Geom::GR_point_sprite);
|
|
gsg_bits &= ~(Geom::GR_point_perspective | Geom::GR_point_sprite);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!hardware_points) {
|
|
|
|
|
+ // If hardware-points is off, we don't all any kind of point
|
|
|
|
|
+ // rendering, except plain old one-pixel points;
|
|
|
|
|
+ gsg_bits &= ~(Geom::GR_point_bits & ~Geom::GR_point);
|
|
|
|
|
+ }
|
|
|
int unsupported_bits = geom_rendering & ~gsg_bits;
|
|
int unsupported_bits = geom_rendering & ~gsg_bits;
|
|
|
|
|
|
|
|
if ((unsupported_bits & Geom::GR_point_bits) != 0) {
|
|
if ((unsupported_bits & Geom::GR_point_bits) != 0) {
|
|
@@ -205,29 +212,35 @@ output(ostream &out) const {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
bool CullableObject::
|
|
bool CullableObject::
|
|
|
munge_points_to_quads(const CullTraverser *traverser, bool force) {
|
|
munge_points_to_quads(const CullTraverser *traverser, bool force) {
|
|
|
- if (!force && !_munged_data->request_resident()) {
|
|
|
|
|
|
|
+ Thread *current_thread = traverser->get_current_thread();
|
|
|
|
|
+
|
|
|
|
|
+ // Better get the animated vertices, in case we're showing sprites
|
|
|
|
|
+ // on an animated model for some reason.
|
|
|
|
|
+ CPT(GeomVertexData) source_data =
|
|
|
|
|
+ _munged_data->animate_vertices(force, current_thread);
|
|
|
|
|
+
|
|
|
|
|
+ if (!force && !source_data->request_resident()) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Thread *current_thread = traverser->get_current_thread();
|
|
|
|
|
PStatTimer timer(_munge_sprites_pcollector, current_thread);
|
|
PStatTimer timer(_munge_sprites_pcollector, current_thread);
|
|
|
- _sw_sprites_pcollector.add_level(_munged_data->get_num_rows());
|
|
|
|
|
|
|
+ _sw_sprites_pcollector.add_level(source_data->get_num_rows());
|
|
|
|
|
|
|
|
GraphicsStateGuardianBase *gsg = traverser->get_gsg();
|
|
GraphicsStateGuardianBase *gsg = traverser->get_gsg();
|
|
|
|
|
|
|
|
- GeomVertexReader vertex(_munged_data, InternalName::get_vertex(),
|
|
|
|
|
|
|
+ GeomVertexReader vertex(source_data, InternalName::get_vertex(),
|
|
|
current_thread);
|
|
current_thread);
|
|
|
- GeomVertexReader normal(_munged_data, InternalName::get_normal(),
|
|
|
|
|
|
|
+ GeomVertexReader normal(source_data, InternalName::get_normal(),
|
|
|
current_thread);
|
|
current_thread);
|
|
|
- GeomVertexReader color(_munged_data, InternalName::get_color(),
|
|
|
|
|
|
|
+ GeomVertexReader color(source_data, InternalName::get_color(),
|
|
|
current_thread);
|
|
current_thread);
|
|
|
- GeomVertexReader texcoord(_munged_data, InternalName::get_texcoord(),
|
|
|
|
|
|
|
+ GeomVertexReader texcoord(source_data, InternalName::get_texcoord(),
|
|
|
current_thread);
|
|
current_thread);
|
|
|
- GeomVertexReader rotate(_munged_data, InternalName::get_rotate(),
|
|
|
|
|
|
|
+ GeomVertexReader rotate(source_data, InternalName::get_rotate(),
|
|
|
current_thread);
|
|
current_thread);
|
|
|
- GeomVertexReader size(_munged_data, InternalName::get_size(),
|
|
|
|
|
|
|
+ GeomVertexReader size(source_data, InternalName::get_size(),
|
|
|
current_thread);
|
|
current_thread);
|
|
|
- GeomVertexReader aspect_ratio(_munged_data, InternalName::get_aspect_ratio(),
|
|
|
|
|
|
|
+ GeomVertexReader aspect_ratio(source_data, InternalName::get_aspect_ratio(),
|
|
|
current_thread);
|
|
current_thread);
|
|
|
|
|
|
|
|
bool has_normal = (normal.has_column());
|
|
bool has_normal = (normal.has_column());
|
|
@@ -244,7 +257,7 @@ munge_points_to_quads(const CullTraverser *traverser, bool force) {
|
|
|
sprite_texcoord = true;
|
|
sprite_texcoord = true;
|
|
|
|
|
|
|
|
// Turn off the TexGenAttrib, since we don't want it now.
|
|
// Turn off the TexGenAttrib, since we don't want it now.
|
|
|
- _state = _state->add_attrib(tex_gen->remove_stage(TextureStage::get_default()));
|
|
|
|
|
|
|
+ _state = _state->set_attrib(tex_gen->remove_stage(TextureStage::get_default()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -258,61 +271,66 @@ munge_points_to_quads(const CullTraverser *traverser, bool force) {
|
|
|
if (render_mode->get_mode() != RenderModeAttrib::M_filled_flat) {
|
|
if (render_mode->get_mode() != RenderModeAttrib::M_filled_flat) {
|
|
|
// Render the new polygons with M_filled_flat, for a slight
|
|
// Render the new polygons with M_filled_flat, for a slight
|
|
|
// performance advantage when software rendering.
|
|
// performance advantage when software rendering.
|
|
|
- _state = _state->add_attrib(RenderModeAttrib::make(RenderModeAttrib::M_filled_flat));
|
|
|
|
|
|
|
+ _state = _state->set_attrib(RenderModeAttrib::make(RenderModeAttrib::M_filled_flat));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Get the vertex format of the newly created geometry.
|
|
// Get the vertex format of the newly created geometry.
|
|
|
CPT(GeomVertexFormat) new_format;
|
|
CPT(GeomVertexFormat) new_format;
|
|
|
- FormatMap::iterator fmi = _format_map.find(_munged_data->get_format());
|
|
|
|
|
- if (fmi != _format_map.end()) {
|
|
|
|
|
- new_format = (*fmi).second;
|
|
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
|
- // We have to construct the format now.
|
|
|
|
|
- PT(GeomVertexArrayFormat) new_array_format;
|
|
|
|
|
- if (retransform_sprites) {
|
|
|
|
|
- // With retransform_sprites in effect, we will be sending ordinary
|
|
|
|
|
- // 3-D points to the graphics API.
|
|
|
|
|
- new_array_format =
|
|
|
|
|
- new GeomVertexArrayFormat(InternalName::get_vertex(), 3,
|
|
|
|
|
- Geom::NT_float32,
|
|
|
|
|
- Geom::C_point);
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ LightMutexHolder holder(_format_lock);
|
|
|
|
|
+ SourceFormat sformat(source_data->get_format(), sprite_texcoord);
|
|
|
|
|
+ FormatMap::iterator fmi = _format_map.find(sformat);
|
|
|
|
|
+ if (fmi != _format_map.end()) {
|
|
|
|
|
+ new_format = (*fmi).second;
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
- // Without retransform_sprites, we will be sending 4-component
|
|
|
|
|
- // clip-space points.
|
|
|
|
|
- new_array_format =
|
|
|
|
|
- new GeomVertexArrayFormat(InternalName::get_vertex(), 4,
|
|
|
|
|
- Geom::NT_float32,
|
|
|
|
|
- Geom::C_clip_point);
|
|
|
|
|
- }
|
|
|
|
|
- if (has_normal) {
|
|
|
|
|
- const GeomVertexColumn *c = normal.get_column();
|
|
|
|
|
- new_array_format->add_column
|
|
|
|
|
- (InternalName::get_normal(), c->get_num_components(),
|
|
|
|
|
- c->get_numeric_type(), c->get_contents());
|
|
|
|
|
- }
|
|
|
|
|
- if (has_color) {
|
|
|
|
|
- const GeomVertexColumn *c = color.get_column();
|
|
|
|
|
- new_array_format->add_column
|
|
|
|
|
- (InternalName::get_color(), c->get_num_components(),
|
|
|
|
|
- c->get_numeric_type(), c->get_contents());
|
|
|
|
|
- }
|
|
|
|
|
- if (sprite_texcoord) {
|
|
|
|
|
- new_array_format->add_column
|
|
|
|
|
- (InternalName::get_texcoord(), 2,
|
|
|
|
|
- Geom::NT_float32,
|
|
|
|
|
- Geom::C_texcoord);
|
|
|
|
|
-
|
|
|
|
|
- } else if (has_texcoord) {
|
|
|
|
|
- const GeomVertexColumn *c = texcoord.get_column();
|
|
|
|
|
- new_array_format->add_column
|
|
|
|
|
- (InternalName::get_texcoord(), c->get_num_components(),
|
|
|
|
|
- c->get_numeric_type(), c->get_contents());
|
|
|
|
|
|
|
+ // We have to construct the format now.
|
|
|
|
|
+ PT(GeomVertexArrayFormat) new_array_format;
|
|
|
|
|
+ if (sformat._retransform_sprites) {
|
|
|
|
|
+ // With retransform_sprites in effect, we will be sending ordinary
|
|
|
|
|
+ // 3-D points to the graphics API.
|
|
|
|
|
+ new_array_format =
|
|
|
|
|
+ new GeomVertexArrayFormat(InternalName::get_vertex(), 3,
|
|
|
|
|
+ Geom::NT_float32,
|
|
|
|
|
+ Geom::C_point);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Without retransform_sprites, we will be sending 4-component
|
|
|
|
|
+ // clip-space points.
|
|
|
|
|
+ new_array_format =
|
|
|
|
|
+ new GeomVertexArrayFormat(InternalName::get_vertex(), 4,
|
|
|
|
|
+ Geom::NT_float32,
|
|
|
|
|
+ Geom::C_clip_point);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (has_normal) {
|
|
|
|
|
+ const GeomVertexColumn *c = normal.get_column();
|
|
|
|
|
+ new_array_format->add_column
|
|
|
|
|
+ (InternalName::get_normal(), c->get_num_components(),
|
|
|
|
|
+ c->get_numeric_type(), c->get_contents());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (has_color) {
|
|
|
|
|
+ const GeomVertexColumn *c = color.get_column();
|
|
|
|
|
+ new_array_format->add_column
|
|
|
|
|
+ (InternalName::get_color(), c->get_num_components(),
|
|
|
|
|
+ c->get_numeric_type(), c->get_contents());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sprite_texcoord) {
|
|
|
|
|
+ new_array_format->add_column
|
|
|
|
|
+ (InternalName::get_texcoord(), 2,
|
|
|
|
|
+ Geom::NT_float32,
|
|
|
|
|
+ Geom::C_texcoord);
|
|
|
|
|
+
|
|
|
|
|
+ } else if (has_texcoord) {
|
|
|
|
|
+ const GeomVertexColumn *c = texcoord.get_column();
|
|
|
|
|
+ new_array_format->add_column
|
|
|
|
|
+ (InternalName::get_texcoord(), c->get_num_components(),
|
|
|
|
|
+ c->get_numeric_type(), c->get_contents());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ new_format = GeomVertexFormat::register_format(new_array_format);
|
|
|
|
|
+ _format_map[sformat] = new_format;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- new_format = GeomVertexFormat::register_format(new_array_format);
|
|
|
|
|
- _format_map[_munged_data->get_format()] = new_format;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const LMatrix4f &modelview = _modelview_transform->get_mat();
|
|
const LMatrix4f &modelview = _modelview_transform->get_mat();
|
|
@@ -341,11 +359,11 @@ munge_points_to_quads(const CullTraverser *traverser, bool force) {
|
|
|
// We always convert all the vertices, assuming all the vertices
|
|
// We always convert all the vertices, assuming all the vertices
|
|
|
// will referenced by GeomPrimitives, because we want to optimize
|
|
// will referenced by GeomPrimitives, because we want to optimize
|
|
|
// for the most common case.
|
|
// for the most common case.
|
|
|
- int orig_verts = _munged_data->get_num_rows();
|
|
|
|
|
|
|
+ int orig_verts = source_data->get_num_rows();
|
|
|
int new_verts = 4 * orig_verts; // each vertex becomes four.
|
|
int new_verts = 4 * orig_verts; // each vertex becomes four.
|
|
|
|
|
|
|
|
PT(GeomVertexData) new_data = new GeomVertexData
|
|
PT(GeomVertexData) new_data = new GeomVertexData
|
|
|
- (_munged_data->get_name(), new_format, Geom::UH_stream);
|
|
|
|
|
|
|
+ (source_data->get_name(), new_format, Geom::UH_stream);
|
|
|
new_data->unclean_set_num_rows(new_verts);
|
|
new_data->unclean_set_num_rows(new_verts);
|
|
|
|
|
|
|
|
GeomVertexWriter new_vertex(new_data, InternalName::get_vertex());
|
|
GeomVertexWriter new_vertex(new_data, InternalName::get_vertex());
|
|
@@ -730,3 +748,16 @@ get_flash_hardware_state() {
|
|
|
|
|
|
|
|
return flash_hardware_state;
|
|
return flash_hardware_state;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function: CullableObject::SourceFormat::Constructor
|
|
|
|
|
+// Access: Public
|
|
|
|
|
+// Description:
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+CullableObject::SourceFormat::
|
|
|
|
|
+SourceFormat(const GeomVertexFormat *format, bool sprite_texcoord) :
|
|
|
|
|
+ _format(format),
|
|
|
|
|
+ _sprite_texcoord(sprite_texcoord)
|
|
|
|
|
+{
|
|
|
|
|
+ _retransform_sprites = retransform_sprites;
|
|
|
|
|
+}
|