new pgraph CullFaceAttrib

This commit is contained in:
David Rose 2002-02-27 18:43:06 +00:00
parent e5187e3668
commit bb8dc8cdfe
14 changed files with 424 additions and 27 deletions

View File

@ -150,6 +150,18 @@ done_geom(Geom *geom) {
return geom;
}
////////////////////////////////////////////////////////////////////
// Function: BuilderBucket::add_attrib
// Access: Public
// Description: A convenience function to add the indicated render
// attribute to the bucket's state.
////////////////////////////////////////////////////////////////////
void BuilderBucket::
add_attrib(const RenderAttrib *attrib) {
_state = _state->add_attrib(attrib);
}
////////////////////////////////////////////////////////////////////
// Function: BuilderBucket::Ordering operator

View File

@ -42,7 +42,6 @@ class GeomNode;
class PandaNode;
class qpGeomNode;
///////////////////////////////////////////////////////////////////
// Class : BuilderBucket
// Description : The main grouping tool for BuilderPrims. See the
@ -72,6 +71,7 @@ public:
virtual GeomNode *make_geom_node();
virtual qpGeomNode *qpmake_geom_node();
virtual Geom *done_geom(Geom *geom);
void add_attrib(const RenderAttrib *attrib);
virtual bool operator < (const BuilderBucket &other) const;

View File

@ -25,6 +25,7 @@
#include "textureAttrib.h"
#include "texturePool.h"
#include "billboardAttrib.h"
#include "cullFaceAttrib.h"
#include "qpgeomNode.h"
#include "string_utils.h"
#include "eggPrimitive.h"
@ -986,13 +987,13 @@ setup_bucket(BuilderBucket &bucket, PandaNode *parent,
bin = render_mode->get_bin();
}
bucket._state = bucket._state->add_attrib(TextureAttrib::make_off());
bucket.add_attrib(TextureAttrib::make_off());
if (egg_prim->has_texture()) {
PT(EggTexture) egg_tex = egg_prim->get_texture();
const TextureDef &def = _textures[egg_tex];
if (def._texture != (const RenderAttrib *)NULL) {
bucket._state = bucket._state->add_attrib(def._texture);
bucket.add_attrib(def._texture);
// bucket._trans.set_transition(def._apply);
// If neither the primitive nor the texture specified an alpha
@ -1108,16 +1109,14 @@ setup_bucket(BuilderBucket &bucket, PandaNode *parent,
}
*/
/*
if (egg_prim->get_bface_flag()) {
// The primitive is marked with backface culling disabled--we want
// to see both sides.
bucket._trans.set_transition(new CullFaceTransition(CullFaceProperty::M_cull_none));
bucket.add_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_none));
} else {
bucket._trans.set_transition(new CullFaceTransition(CullFaceProperty::M_cull_clockwise));
bucket.add_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise));
}
*/
}

View File

@ -66,6 +66,7 @@
#include "pointShapeTransition.h"
#include "polygonOffsetTransition.h"
#include "textureAttrib.h"
#include "cullFaceAttrib.h"
#include "clockObject.h"
#include "string_utils.h"
#include "dcast.h"
@ -3451,6 +3452,39 @@ issue_texture(const TextureAttrib *attrib) {
report_errors();
}
////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::issue_cull_face
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void GLGraphicsStateGuardian::
issue_cull_face(const CullFaceAttrib *attrib) {
CullFaceAttrib::Mode mode = attrib->get_mode();
switch (mode) {
case CullFaceAttrib::M_cull_none:
glDisable(GL_CULL_FACE);
break;
case CullFaceAttrib::M_cull_clockwise:
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
break;
case CullFaceAttrib::M_cull_counter_clockwise:
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
break;
case CullFaceAttrib::M_cull_all:
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT_AND_BACK);
break;
default:
glgsg_cat.error()
<< "invalid cull face mode " << (int)mode << endl;
break;
}
report_errors();
}
////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::wants_normals
// Access: Public, Virtual

View File

@ -158,6 +158,7 @@ public:
virtual void issue_transform(const TransformState *transform);
virtual void issue_texture(const TextureAttrib *attrib);
virtual void issue_cull_face(const CullFaceAttrib *attrib);
virtual bool wants_normals(void) const;
virtual bool wants_texcoords(void) const;

View File

@ -75,8 +75,29 @@ class LinesmoothTransition;
class PointShapeTransition;
class PolygonOffsetTransition;
class TextureAttrib;
class TransformAttrib;
class ColorMatrixAttrib;
class AlphaTransformAttrib;
class TexMatrixAttrib;
class ColorAttrib;
class TextureAttrib;
class LightAttrib;
class MaterialAttrib;
class RenderModeAttrib;
class ColorBlendAttrib;
class TextureApplyAttrib;
class ColorMaskAttrib;
class DepthTestAttrib;
class DepthWriteAttrib;
class TexGenAttrib;
class CullFaceAttrib;
class StencilAttrib;
class ClipPlaneAttrib;
class TransparencyAttrib;
class FogAttrib;
class LinesmoothAttrib;
class PointShapeAttrib;
class PolygonOffsetAttrib;
class Node;
class GeomNode;
@ -191,8 +212,29 @@ public:
virtual void issue_point_shape(const PointShapeTransition *) { }
virtual void issue_polygon_offset(const PolygonOffsetTransition *) { }
virtual void issue_texture(const TextureAttrib *) { }
virtual void issue_transform(const TransformAttrib *) { }
virtual void issue_color_transform(const ColorMatrixAttrib *) { }
virtual void issue_alpha_transform(const AlphaTransformAttrib *) { }
virtual void issue_tex_matrix(const TexMatrixAttrib *) { }
virtual void issue_color(const ColorAttrib *) { }
virtual void issue_texture(const TextureAttrib *) { }
virtual void issue_light(const LightAttrib *) { }
virtual void issue_material(const MaterialAttrib *) { }
virtual void issue_render_mode(const RenderModeAttrib *) { }
virtual void issue_color_blend(const ColorBlendAttrib *) { }
virtual void issue_texture_apply(const TextureApplyAttrib *) { }
virtual void issue_color_mask(const ColorMaskAttrib *) { }
virtual void issue_depth_test(const DepthTestAttrib *) { }
virtual void issue_depth_write(const DepthWriteAttrib *) { }
virtual void issue_tex_gen(const TexGenAttrib *) { }
virtual void issue_cull_face(const CullFaceAttrib *) { }
virtual void issue_stencil(const StencilAttrib *) { }
virtual void issue_clip_plane(const ClipPlaneAttrib *) { }
virtual void issue_transparency(const TransparencyAttrib *) { }
virtual void issue_fog(const FogAttrib *) { }
virtual void issue_linesmooth(const LinesmoothAttrib *) { }
virtual void issue_point_shape(const PointShapeAttrib *) { }
virtual void issue_polygon_offset(const PolygonOffsetAttrib *) { }
PUBLISHED:
static TypeHandle get_class_type() {

View File

@ -10,6 +10,7 @@
qpcamera.h qpcamera.I \
colorAttrib.h colorAttrib.I \
config_pgraph.h \
cullFaceAttrib.h cullFaceAttrib.I \
cullHandler.h \
qpcullTraverser.h qpcullTraverser.I \
cycleData.h cycleData.I \
@ -34,6 +35,7 @@
qpcamera.cxx \
colorAttrib.cxx \
config_pgraph.cxx \
cullFaceAttrib.cxx \
cullHandler.cxx \
qpcullTraverser.cxx \
cycleData.cxx \
@ -63,6 +65,7 @@
qpcamera.h qpcamera.I \
colorAttrib.h colorAttrib.I \
config_pgraph.h \
cullFaceAttrib.h cullFaceAttrib.I \
cullHandler.h \
qpcullTraverser.h qpcullTraverser.I \
cycleData.h cycleData.I \

View File

@ -21,6 +21,7 @@
#include "billboardAttrib.h"
#include "qpcamera.h"
#include "colorAttrib.h"
#include "cullFaceAttrib.h"
#include "qpgeomNode.h"
#include "qplensNode.h"
#include "nodeChain.h"
@ -61,6 +62,7 @@ init_libpgraph() {
BillboardAttrib::init_type();
qpCamera::init_type();
ColorAttrib::init_type();
CullFaceAttrib::init_type();
qpGeomNode::init_type();
qpLensNode::init_type();
NodeChain::init_type();
@ -74,6 +76,7 @@ init_libpgraph() {
BillboardAttrib::register_with_read_factory();
ColorAttrib::register_with_read_factory();
CullFaceAttrib::register_with_read_factory();
qpGeomNode::register_with_read_factory();
PandaNode::register_with_read_factory();
RenderState::register_with_read_factory();

View File

@ -0,0 +1,40 @@
// Filename: cullFaceAttrib.I
// Created by: drose (27Feb02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::Constructor
// Access: Private
// Description: Use CullFaceAttrib::make() to construct a new
// CullFaceAttrib object.
////////////////////////////////////////////////////////////////////
INLINE CullFaceAttrib::
CullFaceAttrib(CullFaceAttrib::Mode mode) :
_mode(mode)
{
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::get_mode
// Access: Published
// Description: Returns the culling mode.
////////////////////////////////////////////////////////////////////
INLINE CullFaceAttrib::Mode CullFaceAttrib::
get_mode() const {
return _mode;
}

View File

@ -0,0 +1,172 @@
// Filename: cullFaceAttrib.cxx
// Created by: drose (27Feb02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "cullFaceAttrib.h"
#include "graphicsStateGuardianBase.h"
#include "dcast.h"
#include "bamReader.h"
#include "bamWriter.h"
#include "datagram.h"
#include "datagramIterator.h"
TypeHandle CullFaceAttrib::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::make
// Access: Published, Static
// Description: Constructs a new CullFaceAttrib object that specifies
// how to cull geometry. By Panda convention, vertices
// are ordered counterclockwise when seen from the
// front, so the M_cull_clockwise will cull backfacing
// polygons.
////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) CullFaceAttrib::
make(CullFaceAttrib::Mode mode) {
CullFaceAttrib *attrib = new CullFaceAttrib(mode);
return return_new(attrib);
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::issue
// Access: Public, Virtual
// Description: Calls the appropriate method on the indicated GSG
// to issue the graphics commands appropriate to the
// given attribute. This is normally called
// (indirectly) only from
// GraphicsStateGuardian::set_state() or modify_state().
////////////////////////////////////////////////////////////////////
void CullFaceAttrib::
issue(GraphicsStateGuardianBase *gsg) const {
gsg->issue_cull_face(this);
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::output
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void CullFaceAttrib::
output(ostream &out) const {
out << get_type() << ":";
switch (get_mode()) {
case M_cull_none:
out << "cull_none";
break;
case M_cull_clockwise:
out << "cull_clockwise";
break;
case M_cull_counter_clockwise:
out << "cull_counter_clockwise";
break;
case M_cull_all:
out << "cull_all";
break;
}
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::compare_to_impl
// Access: Protected, Virtual
// Description: Intended to be overridden by derived CullFaceAttrib
// types to return a unique number indicating whether
// this CullFaceAttrib is equivalent to the other one.
//
// This should return 0 if the two CullFaceAttrib objects
// are equivalent, a number less than zero if this one
// should be sorted before the other one, and a number
// greater than zero otherwise.
//
// This will only be called with two CullFaceAttrib
// objects whose get_type() functions return the same.
////////////////////////////////////////////////////////////////////
int CullFaceAttrib::
compare_to_impl(const RenderAttrib *other) const {
const CullFaceAttrib *ta;
DCAST_INTO_R(ta, other, 0);
return (int)_mode - (int)ta->_mode;
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::make_default_impl
// Access: Protected, Virtual
// Description: Intended to be overridden by derived CullFaceAttrib
// types to specify what the default property for a
// CullFaceAttrib of this type should be.
//
// This should return a newly-allocated CullFaceAttrib of
// the same type that corresponds to whatever the
// standard default for this kind of CullFaceAttrib is.
////////////////////////////////////////////////////////////////////
RenderAttrib *CullFaceAttrib::
make_default_impl() const {
return new CullFaceAttrib;
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::register_with_read_factory
// Access: Public, Static
// Description: Tells the BamReader how to create objects of type
// CullFaceAttrib.
////////////////////////////////////////////////////////////////////
void CullFaceAttrib::
register_with_read_factory() {
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::write_datagram
// Access: Public, Virtual
// Description: Writes the contents of this object to the datagram
// for shipping out to a Bam file.
////////////////////////////////////////////////////////////////////
void CullFaceAttrib::
write_datagram(BamWriter *manager, Datagram &dg) {
RenderAttrib::write_datagram(manager, dg);
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::make_from_bam
// Access: Protected, Static
// Description: This function is called by the BamReader's factory
// when a new object of type CullFaceAttrib is encountered
// in the Bam file. It should create the CullFaceAttrib
// and extract its information from the file.
////////////////////////////////////////////////////////////////////
TypedWritable *CullFaceAttrib::
make_from_bam(const FactoryParams &params) {
CullFaceAttrib *attrib = new CullFaceAttrib;
DatagramIterator scan;
BamReader *manager;
parse_params(params, scan, manager);
attrib->fillin(scan, manager);
return new_from_bam(attrib, manager);
}
////////////////////////////////////////////////////////////////////
// Function: CullFaceAttrib::fillin
// Access: Protected
// Description: This internal function is called by make_from_bam to
// read in all of the relevant data from the BamFile for
// the new CullFaceAttrib.
////////////////////////////////////////////////////////////////////
void CullFaceAttrib::
fillin(DatagramIterator &scan, BamReader *manager) {
RenderAttrib::fillin(scan, manager);
}

View File

@ -0,0 +1,88 @@
// Filename: cullFaceAttrib.h
// Created by: drose (27Feb02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef CULLFACEATTRIB_H
#define CULLFACEATTRIB_H
#include "pandabase.h"
#include "renderAttrib.h"
////////////////////////////////////////////////////////////////////
// Class : CullFaceAttrib
// Description : Indicates which faces should be culled based on their
// vertex ordering.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA CullFaceAttrib : public RenderAttrib {
PUBLISHED:
enum Mode {
M_cull_none, // Cull no polygons
M_cull_clockwise, // Cull clockwise-oriented polygons
M_cull_counter_clockwise, // Cull counter-clockwise-oriented polygons
M_cull_all, // Cull all polygons (other primitives are still drawn)
};
private:
INLINE CullFaceAttrib(Mode mode = M_cull_none);
PUBLISHED:
static CPT(RenderAttrib) make(Mode mode);
INLINE Mode get_mode() const;
public:
virtual void issue(GraphicsStateGuardianBase *gsg) const;
virtual void output(ostream &out) const;
protected:
virtual int compare_to_impl(const RenderAttrib *other) const;
virtual RenderAttrib *make_default_impl() const;
private:
Mode _mode;
public:
static void register_with_read_factory();
virtual void write_datagram(BamWriter *manager, Datagram &dg);
protected:
static TypedWritable *make_from_bam(const FactoryParams &params);
void fillin(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
RenderAttrib::init_type();
register_type(_type_handle, "CullFaceAttrib",
RenderAttrib::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "cullFaceAttrib.I"
#endif

View File

@ -1,12 +1,12 @@
#include "qpcamera.cxx"
#include "colorAttrib.cxx"
#include "config_pgraph.cxx"
#include "cullHandler.cxx"
#include "qpcullTraverser.cxx"
#include "cycleData.cxx"
#include "cycleDataReader.cxx"
#include "cycleDataWriter.cxx"
#include "qpgeomNode.cxx"
#include "qplensNode.cxx"
#include "nodeChain.cxx"
#include "nodeChainComponent.cxx"
#include "billboardAttrib.cxx"
#include "qpcamera.cxx"
#include "colorAttrib.cxx"
#include "config_pgraph.cxx"
#include "cullFaceAttrib.cxx"
#include "cullHandler.cxx"
#include "qpcullTraverser.cxx"
#include "cycleData.cxx"
#include "cycleDataReader.cxx"
#include "cycleDataWriter.cxx"
#include "qpgeomNode.cxx"
#include "qplensNode.cxx"

View File

@ -1,3 +1,5 @@
#include "nodeChain.cxx"
#include "nodeChainComponent.cxx"
#include "pandaNode.cxx"
#include "pipeline.cxx"
#include "pipelineCycler.cxx"

View File

@ -177,17 +177,18 @@ make_default_geometry(PandaNode *parent) {
geom->set_texcoords(uvs, G_PER_VERTEX);
geom->set_normals(norms, G_PER_PRIM);
geom->set_colors(colors, G_PER_VERTEX, cindex);
qpGeomNode *geomnode = new qpGeomNode("tri");
parent->add_child(geomnode);
geomnode->add_geom(geom, RenderState::make_empty());
CPT(RenderState) state = RenderState::make_empty();
Texture *tex = TexturePool::load_texture("rock-floor.rgb");
if (tex != (Texture *)NULL) {
tex->set_minfilter(Texture::FT_linear);
tex->set_magfilter(Texture::FT_linear);
geomnode->set_attrib(TextureAttrib::make(tex));
state->add_attrib(TextureAttrib::make(tex));
}
qpGeomNode *geomnode = new qpGeomNode("tri");
parent->add_child(geomnode);
geomnode->add_geom(geom, state);
}
void