diff --git a/panda/src/display/graphicsStateGuardian.I b/panda/src/display/graphicsStateGuardian.I index 02d3883d50..134c086677 100644 --- a/panda/src/display/graphicsStateGuardian.I +++ b/panda/src/display/graphicsStateGuardian.I @@ -540,23 +540,6 @@ get_coordinate_system() const { return _coordinate_system; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::get_internal_coordinate_system -// Access: Public -// Description: Returns the coordinate system used internally by the -// GSG, if any one particular coordinate system is used. -// The default, CS_default, indicates that the GSG can -// use any coordinate system. -// -// If this returns other than CS_default, the -// GraphicsEngine will automatically convert all -// transforms into the indicated coordinate system. -//////////////////////////////////////////////////////////////////// -INLINE CoordinateSystem GraphicsStateGuardian:: -get_internal_coordinate_system() const { - return _coordinate_system; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::get_cs_transform // Access: Public diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 6976679571..f11022b710 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -842,6 +842,24 @@ set_coordinate_system(CoordinateSystem cs) { } } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::get_internal_coordinate_system +// Access: Public, Virtual +// Description: Returns the coordinate system used internally by the +// GSG. This may be the same as the external coordinate +// system reported by get_coordinate_system(), or it may +// be something different. +// +// In any case, vertices that have been transformed +// before being handed to the GSG (that is, vertices +// with a contents value of C_clip_point) will be +// expected to be in this coordinate system. +//////////////////////////////////////////////////////////////////// +CoordinateSystem GraphicsStateGuardian:: +get_internal_coordinate_system() const { + return _internal_coordinate_system; +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::issue_transform // Access: Public, Virtual diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index a4eedcf970..a3c7e35d18 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -184,7 +184,7 @@ public: void set_coordinate_system(CoordinateSystem cs); INLINE CoordinateSystem get_coordinate_system() const; - INLINE CoordinateSystem get_internal_coordinate_system() const; + virtual CoordinateSystem get_internal_coordinate_system() const; INLINE const TransformState *get_cs_transform() const; diff --git a/panda/src/dxgsg8/dxGeomMunger8.cxx b/panda/src/dxgsg8/dxGeomMunger8.cxx index 33bcb43c2f..a284437e1c 100644 --- a/panda/src/dxgsg8/dxGeomMunger8.cxx +++ b/panda/src/dxgsg8/dxGeomMunger8.cxx @@ -46,20 +46,18 @@ munge_format_impl(const qpGeomVertexFormat *orig, new_format->set_animation(animation); PT(qpGeomVertexArrayFormat) new_array_format = new qpGeomVertexArrayFormat; - const qpGeomVertexColumn *vertex_type = - orig->get_column(InternalName::get_vertex()); - const qpGeomVertexColumn *normal_type = - orig->get_column(InternalName::get_normal()); - const qpGeomVertexColumn *color_type = - orig->get_column(InternalName::get_color()); + const qpGeomVertexColumn *vertex_type = orig->get_vertex_column(); + const qpGeomVertexColumn *normal_type = orig->get_normal_column(); + const qpGeomVertexColumn *color_type = orig->get_color_column(); const qpGeomVertexColumn *texcoord_type = orig->get_column(InternalName::get_texcoord()); if (vertex_type != (const qpGeomVertexColumn *)NULL) { new_array_format->add_column (InternalName::get_vertex(), 3, qpGeomVertexColumn::NT_float32, - qpGeomVertexColumn::C_point); + vertex_type->get_contents()); new_format->remove_column(vertex_type->get_name()); + } else { // If we don't have a vertex type, not much we can do. return orig; diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 187b232948..735e5dcd9a 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -54,6 +54,7 @@ #include "qpgeomTriangles.h" #include "qpgeomTristrips.h" #include "qpgeomTrifans.h" +#include "qpgeomLines.h" #include "dxGeomMunger8.h" #include "config_gobj.h" #include "dxVertexBufferContext8.h" @@ -2693,13 +2694,32 @@ begin_draw_primitives(const qpGeom *geom, const qpGeomMunger *munger, _vertex_blending_enabled = false; } - if (_transform_stale) { + if (_transform_stale && !_vertex_data->is_vertex_transformed()) { const D3DMATRIX *d3d_mat = (const D3DMATRIX *)_transform->get_mat().get_data(); _pD3DDevice->SetTransform(D3DTS_WORLD, d3d_mat); _transform_stale = false; } } + if (_vertex_data->is_vertex_transformed()) { + // If the vertex data claims to be already transformed into clip + // coordinates, wipe out the current projection and modelview + // matrix (so we don't attempt to transform it again). + + // It's tempting just to use the D3DFVF_XYZRHW specification on + // these vertices, but that turns out to be a bigger hammer than + // we want: that also prevents lighting calculations and user clip + // planes. + _pD3DDevice->SetTransform(D3DTS_WORLD, &matIdentity); + static const LMatrix4f rescale_mat + (1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 0.5, 0, + 0, 0, 0.5, 1); + _transform_stale = true; + + _pD3DDevice->SetTransform(D3DTS_PROJECTION, (const D3DMATRIX *)rescale_mat.get_data()); + } return true; } @@ -2818,6 +2838,38 @@ draw_tristrips(const qpGeomTristrips *primitive) { } } +//////////////////////////////////////////////////////////////////// +// Function: DXGraphicsStateGuardian8::draw_lines +// Access: Public, Virtual +// Description: Draws a series of disconnected line segments. +//////////////////////////////////////////////////////////////////// +void DXGraphicsStateGuardian8:: +draw_lines(const qpGeomLines *primitive) { + _vertices_other_pcollector.add_level(primitive->get_num_vertices()); + if (_vbuffer_active) { + IndexBufferContext *ibc = ((qpGeomPrimitive *)primitive)->prepare_now(get_prepared_objects(), this); + nassertv(ibc != (IndexBufferContext *)NULL); + apply_index_buffer(ibc); + + _pD3DDevice->DrawIndexedPrimitive + (D3DPT_LINELIST, + primitive->get_min_vertex(), + primitive->get_max_vertex() - primitive->get_min_vertex() + 1, + 0, primitive->get_num_primitives()); + + } else { + _pD3DDevice->DrawIndexedPrimitiveUP + (D3DPT_LINELIST, + primitive->get_min_vertex(), + primitive->get_max_vertex() - primitive->get_min_vertex() + 1, + primitive->get_num_primitives(), + primitive->get_flat_first_vertices(), + D3DFMT_INDEX16, + _vertex_data->get_array(0)->get_data(), + _vertex_data->get_format()->get_array(0)->get_stride()); + } +} + //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian8::end_draw_primitives() // Access: Public, Virtual @@ -2827,8 +2879,6 @@ draw_tristrips(const qpGeomTristrips *primitive) { //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian8:: end_draw_primitives() { - GraphicsStateGuardian::end_draw_primitives(); - // Turn off vertex blending--it seems to cause problems if we leave // it on. if (_vertex_blending_enabled) { @@ -2836,6 +2886,13 @@ end_draw_primitives() { _pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE); _vertex_blending_enabled = false; } + + if (_vertex_data->is_vertex_transformed()) { + // Restore the projection matrix that we wiped out above. + prepare_lens(); + } + + GraphicsStateGuardian::end_draw_primitives(); } //////////////////////////////////////////////////////////////////// @@ -3579,7 +3636,7 @@ issue_tex_gen(const TexGenAttrib *attrib) { //enable_texturing(false); // reset the texcoordindex lookup to 0 //_pD3DDevice->SetTransform(D3DTS_TEXTURE0, (D3DMATRIX *)dm.get_data()); - _pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0); + //_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0); _pD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0); } else if (attrib->get_mode(TextureStage::get_default()) == TexGenAttrib::M_eye_sphere_map) { diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index 7b4d4b0e7e..f50b939660 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -95,6 +95,7 @@ public: const qpGeomVertexData *vertex_data); virtual void draw_triangles(const qpGeomTriangles *primitive); virtual void draw_tristrips(const qpGeomTristrips *primitive); + virtual void draw_lines(const qpGeomLines *primitive); virtual void end_draw_primitives(); virtual TextureContext *prepare_texture(Texture *tex); diff --git a/panda/src/glstuff/glGeomMunger_src.cxx b/panda/src/glstuff/glGeomMunger_src.cxx index f8292948ba..704d106981 100644 --- a/panda/src/glstuff/glGeomMunger_src.cxx +++ b/panda/src/glstuff/glGeomMunger_src.cxx @@ -49,8 +49,7 @@ munge_format_impl(const qpGeomVertexFormat *orig, PT(qpGeomVertexFormat) new_format = new qpGeomVertexFormat(*orig); new_format->set_animation(animation); - const qpGeomVertexColumn *color_type = - orig->get_column(InternalName::get_color()); + const qpGeomVertexColumn *color_type = orig->get_color_column(); if (color_type != (qpGeomVertexColumn *)NULL && color_type->get_numeric_type() == qpGeomVertexColumn::NT_packed_dabc) { // We need to convert the color format; OpenGL doesn't support the diff --git a/panda/src/gobj/qpgeomVertexArrayFormat.cxx b/panda/src/gobj/qpgeomVertexArrayFormat.cxx index 350ef27247..3a555b0969 100644 --- a/panda/src/gobj/qpgeomVertexArrayFormat.cxx +++ b/panda/src/gobj/qpgeomVertexArrayFormat.cxx @@ -417,7 +417,10 @@ write(ostream &out, int indent_level) const { for (dti = _columns.begin(); dti != _columns.end(); ++dti) { const qpGeomVertexColumn *column = (*dti); indent(out, indent_level + 2) - << *column << " start at " << column->get_start() << "\n"; + << *column + << " " << column->get_numeric_type() + << " " << column->get_contents() + << " start at " << column->get_start() << "\n"; } } diff --git a/panda/src/gobj/qpgeomVertexColumn.cxx b/panda/src/gobj/qpgeomVertexColumn.cxx index c7fd1f8d13..033956618d 100644 --- a/panda/src/gobj/qpgeomVertexColumn.cxx +++ b/panda/src/gobj/qpgeomVertexColumn.cxx @@ -68,3 +68,56 @@ void qpGeomVertexColumn:: output(ostream &out) const { out << *get_name() << "(" << get_num_components() << ")"; } + +ostream & +operator << (ostream &out, qpGeomVertexColumn::NumericType numeric_type) { + switch (numeric_type) { + case qpGeomVertexColumn::NT_uint8: + return out << "uint8"; + + case qpGeomVertexColumn::NT_uint16: + return out << "uint16"; + + case qpGeomVertexColumn::NT_packed_dcba: + return out << "packed_dcba"; + + case qpGeomVertexColumn::NT_packed_dabc: + return out << "packed_dabc"; + + case qpGeomVertexColumn::NT_float32: + return out << "float32"; + } + + return out << "**invalid numeric type (" << (int)numeric_type << ")**"; +} + +ostream & +operator << (ostream &out, qpGeomVertexColumn::Contents contents) { + switch (contents) { + case qpGeomVertexColumn::C_other: + return out << "other"; + + case qpGeomVertexColumn::C_point: + return out << "point"; + + case qpGeomVertexColumn::C_clip_point: + return out << "clip_point"; + + case qpGeomVertexColumn::C_vector: + return out << "vector"; + + case qpGeomVertexColumn::C_texcoord: + return out << "texcoord"; + + case qpGeomVertexColumn::C_color: + return out << "color"; + + case qpGeomVertexColumn::C_index: + return out << "index"; + + case qpGeomVertexColumn::C_morph_delta: + return out << "morph_delta"; + } + + return out << "**invalid contents (" << (int)contents << ")**"; +} diff --git a/panda/src/gobj/qpgeomVertexColumn.h b/panda/src/gobj/qpgeomVertexColumn.h index a15c7e8537..6d14936ad3 100644 --- a/panda/src/gobj/qpgeomVertexColumn.h +++ b/panda/src/gobj/qpgeomVertexColumn.h @@ -95,6 +95,8 @@ private: }; INLINE ostream &operator << (ostream &out, const qpGeomVertexColumn &obj); +ostream &operator << (ostream &out, qpGeomVertexColumn::NumericType numeric_type); +ostream &operator << (ostream &out, qpGeomVertexColumn::Contents contents); #include "qpgeomVertexColumn.I" diff --git a/panda/src/gobj/qpgeomVertexReader.cxx b/panda/src/gobj/qpgeomVertexReader.cxx index 705f67f6e6..0838157a39 100644 --- a/panda/src/gobj/qpgeomVertexReader.cxx +++ b/panda/src/gobj/qpgeomVertexReader.cxx @@ -83,6 +83,7 @@ qpGeomVertexReader::Reader *qpGeomVertexReader:: make_reader() const { switch (_column->get_contents()) { case qpGeomVertexColumn::C_point: + case qpGeomVertexColumn::C_clip_point: case qpGeomVertexColumn::C_texcoord: // These types are read as a 4-d homogeneous point. switch (_column->get_numeric_type()) { diff --git a/panda/src/gobj/qpgeomVertexWriter.cxx b/panda/src/gobj/qpgeomVertexWriter.cxx index 8922126e6a..869141c0af 100644 --- a/panda/src/gobj/qpgeomVertexWriter.cxx +++ b/panda/src/gobj/qpgeomVertexWriter.cxx @@ -87,6 +87,7 @@ qpGeomVertexWriter::Writer *qpGeomVertexWriter:: make_writer() const { switch (_column->get_contents()) { case qpGeomVertexColumn::C_point: + case qpGeomVertexColumn::C_clip_point: case qpGeomVertexColumn::C_texcoord: // These types are written as a 4-d homogeneous point. switch (_column->get_numeric_type()) { diff --git a/panda/src/gsgbase/graphicsStateGuardianBase.h b/panda/src/gsgbase/graphicsStateGuardianBase.h index 5113b3021a..0d7df9425f 100644 --- a/panda/src/gsgbase/graphicsStateGuardianBase.h +++ b/panda/src/gsgbase/graphicsStateGuardianBase.h @@ -209,6 +209,8 @@ public: virtual void apply_material(const Material *material)=0; + virtual CoordinateSystem get_internal_coordinate_system() const=0; + virtual void issue_transform(const TransformState *) { } virtual void issue_alpha_test(const AlphaTestAttrib *) { } virtual void issue_color_scale(const ColorScaleAttrib *) { } diff --git a/panda/src/pgraph/cullableObject.cxx b/panda/src/pgraph/cullableObject.cxx index db60123cbc..4cc8de28fc 100644 --- a/panda/src/pgraph/cullableObject.cxx +++ b/panda/src/pgraph/cullableObject.cxx @@ -215,7 +215,8 @@ munge_points_to_quads(const CullTraverser *traverser) { const Lens *lens = scene->get_lens(); const LMatrix4f &lens_mat = lens->get_projection_mat(); LMatrix4f projection = - LMatrix4f::convert_mat(CS_yup_right, lens->get_coordinate_system()) * + LMatrix4f::convert_mat(gsg->get_internal_coordinate_system(), + lens->get_coordinate_system()) * lens_mat; LMatrix4f render_transform;