51 EggRenderMode::AlphaMode am = EggRenderMode::AM_unspecified;
52 EggRenderMode::DepthWriteMode dwm = EggRenderMode::DWM_unspecified;
53 EggRenderMode::DepthTestMode dtm = EggRenderMode::DTM_unspecified;
54 EggRenderMode::VisibilityMode vm = EggRenderMode::VM_unspecified;
55 bool implicit_alpha =
false;
56 bool binary_alpha_only =
true;
57 bool has_draw_order =
false;
59 bool has_depth_offset =
false;
66 if (render_mode !=
nullptr) {
70 if (render_mode !=
nullptr) {
74 if (render_mode !=
nullptr) {
78 if (render_mode !=
nullptr) {
82 if (render_mode !=
nullptr) {
83 has_draw_order =
true;
87 if (render_mode !=
nullptr) {
88 has_depth_offset =
true;
92 if (render_mode !=
nullptr) {
104 for (
int i = 0; i < num_textures; i++) {
107 const TextureDef &def = _loader._textures[egg_tex];
108 if (def._texture !=
nullptr) {
109 if (texture_attrib ==
nullptr) {
110 texture_attrib = def._texture;
112 texture_attrib = texture_attrib->compose(def._texture);
115 if (egg_tex->affects_polygon_alpha()) {
118 nassertv(tex !=
nullptr);
123 binary_alpha_only =
false;
126 if (am == EggRenderMode::AM_unspecified) {
132 if (egg_tex->has_alpha_channel(num_components)) {
133 implicit_alpha =
true;
139 bool has_tex_gen =
false;
140 if (egg_tex->get_tex_gen() != EggTexture::TG_unspecified) {
142 if (tex_gen_attrib ==
nullptr) {
143 tex_gen_attrib = TexGenAttrib::make();
146 add_stage(def._stage, get_tex_gen(egg_tex));
154 if (egg_tex->has_uv_name() && egg_tex->get_uv_name() != std::string(
"default")) {
155 uv_name = InternalName::get_texcoord_name(egg_tex->get_uv_name());
157 uv_name = InternalName::get_texcoord();
164 tex_mat_attrib = apply_tex_mat(tex_mat_attrib, def._stage, egg_tex);
177 tex_mats[uv_name][egg_tex->get_transform3d()].push_back(&def);
186 bool needs_tex_mat = (egg_prim->
is_of_type(EggCurve::get_class_type()) ||
187 egg_prim->
is_of_type(EggSurface::get_class_type()));
191 TexMats::const_iterator tmi;
192 for (tmi = tex_mats.begin(); tmi != tex_mats.end(); ++tmi) {
196 if (tmt.size() == 1 && !needs_tex_mat) {
203 nassertv(!tmtex.empty());
204 TexMatTextures::const_iterator tmtexi = tmtex.begin();
205 const EggTexture *egg_tex = (*tmtexi)->_egg_tex;
210 _bake_in_uvs[uv_name] = egg_tex;
217 TexMatTransforms::const_iterator tmti;
218 for (tmti = tmt.begin(); tmti != tmt.end(); ++tmti) {
220 TexMatTextures::const_iterator tmtexi;
221 for (tmtexi = tmtex.begin(); tmtexi != tmtex.end(); ++tmtexi) {
222 const EggTexture *egg_tex = (*tmtexi)->_egg_tex;
225 tex_mat_attrib = apply_tex_mat(tex_mat_attrib, stage, egg_tex);
231 if (texture_attrib !=
nullptr) {
235 if (tex_gen_attrib !=
nullptr) {
239 if (tex_mat_attrib !=
nullptr) {
249 if (material->has_diff() && material->get_diff()[3] != 1.0) {
250 implicit_alpha =
true;
251 binary_alpha_only =
false;
258 if (am == EggRenderMode::AM_unspecified) {
259 if (egg_prim->has_color()) {
261 implicit_alpha =
true;
262 binary_alpha_only =
false;
265 EggPrimitive::const_iterator vi;
266 for (vi = egg_prim->begin();
267 !implicit_alpha && vi != egg_prim->end();
269 if ((*vi)->has_color()) {
270 if ((*vi)->get_color()[3] != 1.0) {
271 implicit_alpha =
true;
272 binary_alpha_only =
false;
277 if (implicit_alpha) {
278 am = EggRenderMode::AM_on;
283 case EggRenderMode::AM_on:
285 if (binary_alpha_only) {
286 am = EggRenderMode::AM_binary;
287 }
else if (egg_alpha_mode != EggRenderMode::AM_unspecified) {
292 case EggRenderMode::AM_blend:
293 case EggRenderMode::AM_ms:
294 case EggRenderMode::AM_ms_mask:
295 case EggRenderMode::AM_dual:
296 if (egg_implicit_alpha_binary) {
299 if (binary_alpha_only) {
300 am = EggRenderMode::AM_binary;
310 case EggRenderMode::AM_on:
311 case EggRenderMode::AM_blend:
312 add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_alpha));
315 case EggRenderMode::AM_blend_no_occlude:
316 add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_alpha));
317 add_attrib(DepthWriteAttrib::make(DepthWriteAttrib::M_off));
320 case EggRenderMode::AM_ms:
321 add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_multisample));
324 case EggRenderMode::AM_ms_mask:
325 add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_multisample_mask));
328 case EggRenderMode::AM_binary:
329 add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_binary));
332 case EggRenderMode::AM_dual:
333 add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_dual));
336 case EggRenderMode::AM_premultiplied:
337 add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_premultiplied_alpha));
345 case EggRenderMode::DWM_on:
346 add_attrib(DepthWriteAttrib::make(DepthWriteAttrib::M_on));
349 case EggRenderMode::DWM_off:
350 add_attrib(DepthWriteAttrib::make(DepthWriteAttrib::M_off));
358 case EggRenderMode::DTM_on:
359 add_attrib(DepthTestAttrib::make(DepthTestAttrib::M_less));
362 case EggRenderMode::DTM_off:
363 add_attrib(DepthTestAttrib::make(DepthTestAttrib::M_none));
371 case EggRenderMode::VM_hidden:
375 case EggRenderMode::VM_normal:
385 add_attrib(ShadeModelAttrib::make(ShadeModelAttrib::M_flat));
388 if (egg_prim->
is_of_type(EggLine::get_class_type())) {
389 _primitive_type = Geom::PT_lines;
392 add_attrib(RenderModeAttrib::make(RenderModeAttrib::M_unchanged,
395 }
else if (egg_prim->
is_of_type(EggPoint::get_class_type())) {
396 _primitive_type = Geom::PT_points;
399 add_attrib(RenderModeAttrib::make(RenderModeAttrib::M_unchanged,
404 _primitive_type = Geom::PT_polygons;
408 add_attrib(CullBinAttrib::make(bin, draw_order));
410 }
else if (has_draw_order) {
411 add_attrib(CullBinAttrib::make(
"fixed", draw_order));
413 if (has_depth_offset) {
414 add_attrib(DepthOffsetAttrib::make(depth_offset));
421 add_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_none));
431 if (_state != other._state) {
432 int c = _state->compare_to(*other._state);
437 if (_hidden != other._hidden) {
438 return (
int)_hidden - (int)other._hidden;
440 if (_flat_shaded != other._flat_shaded) {
441 return (
int)_flat_shaded - (int)other._flat_shaded;
443 if (_primitive_type != other._primitive_type) {
444 return (
int)_primitive_type - (int)other._primitive_type;
447 if (_bake_in_uvs.size() != other._bake_in_uvs.size()) {
448 return (
int)_bake_in_uvs.size() - (int)other._bake_in_uvs.size();
451 BakeInUVs::const_iterator ai, bi;
452 ai = _bake_in_uvs.begin();
453 bi = other._bake_in_uvs.begin();
454 while (ai != _bake_in_uvs.end()) {
455 nassertr(bi != other._bake_in_uvs.end(),
false);
456 if ((*ai).first != (*bi).first) {
457 return (*ai).first < (*bi).first ? -1 : 1;
459 if ((*ai).second != (*bi).second) {
460 return (*ai).second < (*bi).second ? -1 : 1;
465 nassertr(bi == other._bake_in_uvs.end(),
false);
475 get_material_attrib(
const EggMaterial *egg_mat,
bool bface) {
476 Materials &materials =
477 bface ? _loader._materials_bface : _loader._materials;
480 Materials::const_iterator mi;
481 mi = materials.find(egg_mat);
482 if (mi != materials.end()) {
490 mat->set_base_color(egg_mat->
get_base());
492 if (egg_mat->has_diff()) {
493 mat->set_diffuse(egg_mat->
get_diff());
496 mat->set_ambient(egg_mat->
get_diff());
498 if (egg_mat->has_amb()) {
499 mat->set_ambient(egg_mat->
get_amb());
501 if (egg_mat->has_emit()) {
502 mat->set_emission(egg_mat->
get_emit());
504 if (egg_mat->has_spec()) {
505 mat->set_specular(egg_mat->
get_spec());
507 if (egg_mat->has_shininess()) {
508 mat->set_shininess(egg_mat->get_shininess());
517 mat->set_refractive_index(egg_mat->
get_ior());
519 if (egg_mat->has_local()) {
520 mat->set_local(egg_mat->get_local());
523 mat->set_twoside(bface);
529 CPT(
RenderAttrib) mt = MaterialAttrib::make(shared_mat);
530 materials.insert(Materials::value_type(egg_mat, mt));
539 TexGenAttrib::Mode EggRenderState::
541 switch (egg_tex->get_tex_gen()) {
542 case EggTexture::TG_unspecified:
543 return TexGenAttrib::M_off;
545 case EggTexture::TG_eye_sphere_map:
546 return TexGenAttrib::M_eye_sphere_map;
548 case EggTexture::TG_world_cube_map:
549 return TexGenAttrib::M_world_cube_map;
551 case EggTexture::TG_eye_cube_map:
552 return TexGenAttrib::M_eye_cube_map;
554 case EggTexture::TG_world_normal:
555 return TexGenAttrib::M_world_normal;
557 case EggTexture::TG_eye_normal:
558 return TexGenAttrib::M_eye_normal;
560 case EggTexture::TG_world_position:
561 return TexGenAttrib::M_world_position;
563 case EggTexture::TG_eye_position:
564 return TexGenAttrib::M_eye_position;
566 case EggTexture::TG_point_sprite:
567 return TexGenAttrib::M_point_sprite;
570 return TexGenAttrib::M_off;
583 if (tex_mat_attrib ==
nullptr) {
584 tex_mat_attrib = TexMatrixAttrib::make();
587 add_stage(stage, transform);
590 return tex_mat_attrib;
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_material
Returns a pointer to the applied material, or NULL if there is no material applied.
AlphaMode get_alpha_mode() const
Returns the alpha mode that was set, or AM_unspecified if nothing was set.
VisibilityMode get_visibility_mode() const
Returns the visibility mode that was set, or VM_unspecified if nothing was set.
static Material * get_material(Material *temp)
Returns a Material pointer that represents the same material described by temp, except that it is a s...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual EggRenderMode * determine_bin()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A line segment, or a series of connected line segments, defined by a <Line> entry.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_bin() const
Returns the bin name that has been set for this particular object, if any.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_draw_order() const
Returns the "draw-order" flag as set for this particular object.
Defines a texture map that may be applied to geometry.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
double get_thick() const
Returns the thickness set on this particular point.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual EggRenderMode * determine_alpha_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LColor get_color() const
Returns the color set on this particular attribute.
A single point, or a collection of points as defined by a single <PointLight> entry.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DepthWriteMode get_depth_write_mode() const
Returns the depth_write mode that was set, or DWM_unspecified if nothing was set.
void fill_state(EggPrimitive *egg_prim)
Sets up the state as appropriate for the indicated primitive.
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
get_connected_shading
Determines what sort of shading properties this primitive's connected neighbors have.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
This class is used within this package only to record the render state that should be assigned to eac...
get_format
Returns the format of the texture, which represents both the semantic meaning of the texels and,...
This class stores miscellaneous rendering properties that is associated with geometry,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual EggRenderMode * determine_depth_test_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CPT(RenderAttrib) EggRenderState
Returns a RenderAttrib suitable for enabling the material indicated by the given EggMaterial,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static bool has_alpha(Format format)
Returns true if the indicated format includes alpha, false otherwise.
void add_attrib(const RenderAttrib *attrib)
A convenience function to add the indicated render attribute to the aggregate state.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool get_perspective() const
Returns the perspective flag set on this particular point.
get_num_components
Returns the number of color components for each texel of the texture image.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Texture * get_texture() const
If the TextureAttrib is not an 'off' TextureAttrib, returns the base-level texture that is associated...
virtual EggRenderMode * determine_depth_offset()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_spec
It is legal to call this even if has_spec() returns false.
Defines the way an object appears in the presence of lighting.
Encodes a string name in a hash table, mapping it to a pointer.
get_num_textures
Returns the number of textures applied to the primitive.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual EggRenderMode * determine_draw_order()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Applies a transform matrix to UV's before they are rendered.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_emit
It is legal to call this even if has_emit() returns false.
get_texture
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double get_thick() const
Returns the thickness set on this particular line.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
virtual EggRenderMode * determine_visibility_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
get_bface_flag
Retrieves the backfacing flag of the polygon.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_base
It is legal to call this even if has_base() returns false.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines the properties of a named stage of the multitexture pipeline.
static bool has_binary_alpha(Format format)
Returns true if the indicated format includes a binary alpha only, false otherwise.
Computes texture coordinates for geometry automatically based on vertex position and/or normal.
int get_depth_offset() const
Returns the "depth-offset" flag as set for this particular object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_diff
It is legal to call this even if has_diff() returns false.
DepthTestMode get_depth_test_mode() const
Returns the depth_test mode that was set, or DTM_unspecified if nothing was set.
virtual EggRenderMode * determine_depth_write_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
get_amb
It is legal to call this even if has_amb() returns false.
has_material
Returns true if the primitive is materiald (and get_material() will return a real pointer),...
int compare_to(const EggRenderState &other) const
Provides a unique ordering for different EggRenderState objects, so that primitives of similar state ...