From 23e43fc04e0f9c44e2a66ed37f9b26bb87b02fa8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 22 Apr 2005 18:48:26 +0000 Subject: [PATCH] hardware-point-sprites, GR_point_sprite_tex_matrix --- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 7 +++--- panda/src/gobj/config_gobj.cxx | 8 +++++++ panda/src/gobj/config_gobj.h | 1 + panda/src/gobj/qpgeomEnums.h | 20 ++++++++++------- panda/src/pgraph/cullableObject.cxx | 9 +++++++- panda/src/pgraph/renderState.I | 22 +++++++++++++++++++ panda/src/pgraph/renderState.cxx | 15 +++++++++++++ panda/src/pgraph/renderState.h | 9 +++++--- panda/src/pgraph/texGenAttrib.h | 10 +++++++-- panda/src/pgraph/texMatrixAttrib.I | 19 ++++++++++++++++ panda/src/pgraph/texMatrixAttrib.h | 3 +++ 11 files changed, 105 insertions(+), 18 deletions(-) diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 8e6e67cf6e..932aca0d1d 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -226,12 +226,11 @@ DXGraphicsStateGuardian8(const FrameBufferProperties &properties) : _copy_texture_inverted = true; // D3DRS_POINTSPRITEENABLE doesn't seem to support remapping the - // texture coordinates via a texture matrix, a fatal flaw. Without - // that support, we don't advertise this capability, and fall back - // to always generating quads for textured sprites. + // texture coordinates via a texture matrix, so we don't advertise + // GR_point_sprite_tex_matrix. _supported_geom_rendering = qpGeom::GR_point | qpGeom::GR_point_uniform_size | - qpGeom::GR_point_perspective | /* qpGeom::GR_point_sprite |*/ + qpGeom::GR_point_perspective | qpGeom::GR_point_sprite | qpGeom::GR_triangle_strip | qpGeom::GR_triangle_fan | qpGeom::GR_flat_first_vertex; } diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index 3a0040c0d9..d155dbca43 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -130,6 +130,14 @@ ConfigVariableBool hardware_animated_vertices "necessary on your computer's bus. However, in some cases it " "may actually reduce performance.")); +ConfigVariableBool hardware_point_sprites +("hardware-point-sprites", true, + PRC_DESC("Set this true to allow the use of hardware extensions when " + "rendering perspective-scaled points and point sprites. When " + "false, these large points are always simulated via quads " + "computed in software, even if the hardware claims it can " + "support them directly.")); + ConfigVariableBool matrix_palette ("matrix-palette", false, PRC_DESC("Set this true to allow the use of the matrix palette when " diff --git a/panda/src/gobj/config_gobj.h b/panda/src/gobj/config_gobj.h index 6fe930acb1..2a0ea2b581 100644 --- a/panda/src/gobj/config_gobj.h +++ b/panda/src/gobj/config_gobj.h @@ -54,6 +54,7 @@ extern EXPCL_PANDA ConfigVariableBool retained_mode; extern EXPCL_PANDA ConfigVariableBool vertex_buffers; extern EXPCL_PANDA ConfigVariableBool display_lists; extern EXPCL_PANDA ConfigVariableBool hardware_animated_vertices; +extern EXPCL_PANDA ConfigVariableBool hardware_point_sprites; extern EXPCL_PANDA ConfigVariableBool matrix_palette; extern EXPCL_PANDA ConfigVariableBool display_list_animation; extern EXPCL_PANDA ConfigVariableBool connect_triangle_strips; diff --git a/panda/src/gobj/qpgeomEnums.h b/panda/src/gobj/qpgeomEnums.h index b841ec3531..793fb387f7 100644 --- a/panda/src/gobj/qpgeomEnums.h +++ b/panda/src/gobj/qpgeomEnums.h @@ -116,23 +116,27 @@ PUBLISHED: // their face, to render textures as sprites. GR_point_sprite = 0x0080, + // If there is a texture matrix applied to the sprite's generated + // texture coordinates. + GR_point_sprite_tex_matrix = 0x0100, + // The union of all the above point attributes, except GR_indexed_point. - GR_point_bits = 0x00f3, + GR_point_bits = 0x01f3, // If there are any of these composite types. - GR_triangle_strip = 0x0100, - GR_triangle_fan = 0x0200, - GR_line_strip = 0x0400, + GR_triangle_strip = 0x0200, + GR_triangle_fan = 0x0400, + GR_line_strip = 0x0800, // The union of all of the above composite types. - GR_composite_bits = 0x0700, + GR_composite_bits = 0x0e00, // If the shade model requires a particular vertex for flat shading. - GR_flat_first_vertex = 0x0800, - GR_flat_last_vertex = 0x1000, + GR_flat_first_vertex = 0x1000, + GR_flat_last_vertex = 0x2000, // The union of the above shade model types. - GR_shade_model_bits = 0x1800, + GR_shade_model_bits = 0x3000, }; // The shade model specifies whether the per-vertex colors and diff --git a/panda/src/pgraph/cullableObject.cxx b/panda/src/pgraph/cullableObject.cxx index 346122622d..13ca1e9a9e 100644 --- a/panda/src/pgraph/cullableObject.cxx +++ b/panda/src/pgraph/cullableObject.cxx @@ -54,7 +54,14 @@ munge_geom(GraphicsStateGuardianBase *gsg, int geom_rendering = _state->get_geom_rendering(qpgeom->get_geom_rendering()); GraphicsStateGuardianBase *gsg = traverser->get_gsg(); - int unsupported_bits = geom_rendering & ~gsg->get_supported_geom_rendering(); + int gsg_bits = gsg->get_supported_geom_rendering(); + if (!hardware_point_sprites) { + // If support for hardware point sprites or perspective-scaled + // points is disabled, we don't allow the GSG to tell us it + // supports them. + gsg_bits &= ~(qpGeom::GR_point_perspective | qpGeom::GR_point_sprite); + } + int unsupported_bits = geom_rendering & ~gsg_bits; if ((unsupported_bits & qpGeom::GR_point_bits) != 0) { // The GSG doesn't support rendering these fancy points // directly; we have to render them in software instead. diff --git a/panda/src/pgraph/renderState.I b/panda/src/pgraph/renderState.I index fe5bdfe6e2..6e069d429d 100644 --- a/panda/src/pgraph/renderState.I +++ b/panda/src/pgraph/renderState.I @@ -230,6 +230,25 @@ get_tex_gen() const { return _tex_gen; } +//////////////////////////////////////////////////////////////////// +// Function: RenderState::get_tex_matrix +// Access: Published +// Description: This function is provided as an optimization, to +// speed up the render-time checking for the existance +// of a TexMatrixAttrib on this state. It returns a +// pointer to the TexMatrixAttrib, if there is one, or +// NULL if there is not. +//////////////////////////////////////////////////////////////////// +INLINE const TexMatrixAttrib *RenderState:: +get_tex_matrix() const { + if ((_flags & F_checked_tex_matrix) == 0) { + // We pretend this function is const, even though it transparently + // modifies the internal tex_matrix cache. + ((RenderState *)this)->determine_tex_matrix(); + } + return _tex_matrix; +} + //////////////////////////////////////////////////////////////////// // Function: RenderState::get_render_mode // Access: Published @@ -265,6 +284,9 @@ get_geom_rendering(int geom_rendering) const { if (get_tex_gen() != (const TexGenAttrib *)NULL) { geom_rendering = _tex_gen->get_geom_rendering(geom_rendering); } + if (get_tex_matrix() != (const TexMatrixAttrib *)NULL) { + geom_rendering = _tex_matrix->get_geom_rendering(geom_rendering); + } return geom_rendering; } diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index f751322c4e..3c6d18138b 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -1575,6 +1575,21 @@ determine_tex_gen() { _flags |= F_checked_tex_gen; } +//////////////////////////////////////////////////////////////////// +// Function: RenderState::determine_tex_matrix +// Access: Private +// Description: This is the private implementation of get_tex_matrix(). +//////////////////////////////////////////////////////////////////// +void RenderState:: +determine_tex_matrix() { + const RenderAttrib *attrib = get_attrib(TexMatrixAttrib::get_class_type()); + _tex_matrix = (const TexMatrixAttrib *)NULL; + if (attrib != (const RenderAttrib *)NULL) { + _tex_matrix = DCAST(TexMatrixAttrib, attrib); + } + _flags |= F_checked_tex_matrix; +} + //////////////////////////////////////////////////////////////////// // Function: RenderState::determine_render_mode // Access: Private diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index 83cec1b842..6e14aea960 100644 --- a/panda/src/pgraph/renderState.h +++ b/panda/src/pgraph/renderState.h @@ -29,6 +29,7 @@ #include "pStatCollector.h" #include "renderModeAttrib.h" #include "texGenAttrib.h" +#include "texMatrixAttrib.h" class GraphicsStateGuardianBase; class FogAttrib; @@ -37,8 +38,6 @@ class TransparencyAttrib; class ColorAttrib; class ColorScaleAttrib; class TextureAttrib; -class TexGenAttrib; -class RenderModeAttrib; class FactoryParams; //////////////////////////////////////////////////////////////////// @@ -125,6 +124,7 @@ PUBLISHED: INLINE const ColorScaleAttrib *get_color_scale() const; INLINE const TextureAttrib *get_texture() const; INLINE const TexGenAttrib *get_tex_gen() const; + INLINE const TexMatrixAttrib *get_tex_matrix() const; INLINE const RenderModeAttrib *get_render_mode() const; INLINE int get_geom_rendering(int geom_rendering) const; @@ -168,6 +168,7 @@ private: void determine_color_scale(); void determine_texture(); void determine_tex_gen(); + void determine_tex_matrix(); void determine_render_mode(); INLINE void set_destructing(); @@ -246,6 +247,7 @@ private: const ColorScaleAttrib *_color_scale; const TextureAttrib *_texture; const TexGenAttrib *_tex_gen; + const TexMatrixAttrib *_tex_matrix; const RenderModeAttrib *_render_mode; enum Flags { @@ -257,7 +259,8 @@ private: F_checked_color_scale = 0x0020, F_checked_texture = 0x0040, F_checked_tex_gen = 0x0080, - F_checked_render_mode = 0x0100, + F_checked_tex_matrix = 0x0100, + F_checked_render_mode = 0x0200, F_is_destructing = 0x8000, }; unsigned short _flags; diff --git a/panda/src/pgraph/texGenAttrib.h b/panda/src/pgraph/texGenAttrib.h index 15d4d94afd..8b2fab5dd4 100755 --- a/panda/src/pgraph/texGenAttrib.h +++ b/panda/src/pgraph/texGenAttrib.h @@ -21,12 +21,11 @@ #include "pandabase.h" -#include "geom.h" +#include "qpgeom.h" #include "renderAttrib.h" #include "textureStage.h" #include "texture.h" #include "pointerTo.h" -#include "qpgeom.h" //////////////////////////////////////////////////////////////////// // Class : TexGenAttrib @@ -83,6 +82,13 @@ PUBLISHED: // lower-right across the point's face. Without this, each point // will have just a single uniform texture coordinate value across // its face. + + // Unfortunately, the generated texture coordinates are inverted + // (upside-down) from Panda's usual convention, but this is what + // the graphics card manufacturers decided to use. You could use + // a texture matrix to re-invert the texture, but that will + // probably force software rendering. You'll have to paint your + // textures upside-down if you want true hardware sprites. M_point_sprite, }; diff --git a/panda/src/pgraph/texMatrixAttrib.I b/panda/src/pgraph/texMatrixAttrib.I index 5618dda7bc..a7af061e1e 100644 --- a/panda/src/pgraph/texMatrixAttrib.I +++ b/panda/src/pgraph/texMatrixAttrib.I @@ -40,6 +40,25 @@ TexMatrixAttrib(const TexMatrixAttrib ©) : { } +//////////////////////////////////////////////////////////////////// +// Function: TexMatrixAttrib::get_geom_rendering +// Access: Published +// Description: Returns the union of the Geom::GeomRendering bits +// that will be required once this TexMatrixAttrib is +// applied to a geom which includes the indicated +// geom_rendering bits. +//////////////////////////////////////////////////////////////////// +INLINE int TexMatrixAttrib:: +get_geom_rendering(int geom_rendering) const { + if ((geom_rendering & qpGeom::GR_point_sprite) != 0) { + if (!is_empty()) { + return geom_rendering |= qpGeom::GR_point_sprite_tex_matrix; + } + } + + return geom_rendering; +} + //////////////////////////////////////////////////////////////////// // Function: TexMatrixAttrib::check_stage_list // Access: Private diff --git a/panda/src/pgraph/texMatrixAttrib.h b/panda/src/pgraph/texMatrixAttrib.h index 48058ef185..853554105e 100644 --- a/panda/src/pgraph/texMatrixAttrib.h +++ b/panda/src/pgraph/texMatrixAttrib.h @@ -21,6 +21,7 @@ #include "pandabase.h" +#include "qpgeom.h" #include "renderAttrib.h" #include "textureStage.h" #include "transformState.h" @@ -61,6 +62,8 @@ PUBLISHED: CPT(TransformState) get_transform(TextureStage *stage) const; + INLINE int get_geom_rendering(int geom_rendering) const; + public: virtual void issue(GraphicsStateGuardianBase *gsg) const; virtual void output(ostream &out) const;