Skip to content

Commit 366bcf8

Browse files
committed
pgraph decals
1 parent 1979607 commit 366bcf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1898
-258
lines changed

panda/src/display/Sources.pp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
config_display.h displayRegion.I displayRegion.h \
1414
displayRegionStack.I \
1515
displayRegionStack.h \
16-
drawCullHandler.h drawCullHandler.I \
1716
frameBufferStack.I frameBufferStack.h \
1817
geomContext.I geomContext.h geomNodeContext.I geomNodeContext.h \
1918
graphicsChannel.I graphicsChannel.h \
@@ -33,7 +32,6 @@
3332

3433
#define INCLUDED_SOURCES \
3534
config_display.cxx displayRegion.cxx \
36-
drawCullHandler.cxx \
3735
geomContext.cxx geomNodeContext.cxx graphicsChannel.cxx \
3836
graphicsEngine.cxx \
3937
graphicsLayer.cxx graphicsPipe.cxx graphicsStateGuardian.cxx \
@@ -46,7 +44,6 @@
4644
config_display.h \
4745
displayRegion.I displayRegion.h displayRegionStack.I \
4846
displayRegionStack.h \
49-
drawCullHandler.h drawCullHandler.I \
5047
frameBufferStack.I frameBufferStack.h \
5148
geomContext.I geomContext.h geomNodeContext.I geomNodeContext.h \
5249
graphicsChannel.I graphicsChannel.h \

panda/src/display/display_composite1.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
#include "displayRegion.cxx"
3-
#include "drawCullHandler.cxx"
43
#include "geomContext.cxx"
54
#include "geomNodeContext.cxx"
65
#include "graphicsChannel.cxx"

panda/src/display/graphicsStateGuardian.cxx

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "textureContext.h"
2323
#include "renderBuffer.h"
2424
#include "colorAttrib.h"
25+
#include "renderState.h"
26+
#include "depthWriteAttrib.h"
27+
#include "colorWriteAttrib.h"
2528

2629
#include "clockObject.h"
2730
#include "geomNode.h"
@@ -892,6 +895,101 @@ void GraphicsStateGuardian::
892895
end_decal(GeomNode *) {
893896
}
894897

898+
////////////////////////////////////////////////////////////////////
899+
// Function: GraphicsStateGuardian::polygon_offset_decals
900+
// Access: Public, Virtual
901+
// Description: Returns true if this GSG can implement decals using a
902+
// PolygonOffsetAttrib, or false if that is unreliable
903+
// and the three-step rendering process should be used
904+
// instead.
905+
////////////////////////////////////////////////////////////////////
906+
bool GraphicsStateGuardian::
907+
polygon_offset_decals() {
908+
return false;
909+
}
910+
911+
////////////////////////////////////////////////////////////////////
912+
// Function: GraphicsStateGuardian::begin_decal_base_first
913+
// Access: Public, Virtual
914+
// Description: Called during draw to begin a three-step rendering
915+
// phase to draw decals. The first step,
916+
// begin_decal_base_first(), is called prior to drawing the
917+
// base geometry. It should set up whatever internal
918+
// state is appropriate, as well as returning a
919+
// RenderState object that should be applied to the base
920+
// geometry for rendering.
921+
////////////////////////////////////////////////////////////////////
922+
CPT(RenderState) GraphicsStateGuardian::
923+
begin_decal_base_first() {
924+
// Turn off writing the depth buffer to render the base geometry.
925+
static CPT(RenderState) decal_base_first;
926+
if (decal_base_first == (const RenderState *)NULL) {
927+
decal_base_first = RenderState::make
928+
(DepthWriteAttrib::make(DepthWriteAttrib::M_off));
929+
}
930+
return decal_base_first;
931+
}
932+
933+
////////////////////////////////////////////////////////////////////
934+
// Function: GraphicsStateGuardian::begin_decal_nested
935+
// Access: Public, Virtual
936+
// Description: Called during draw to begin a three-step rendering
937+
// phase to draw decals. The second step,
938+
// begin_decal_nested(), is called after drawing the
939+
// base geometry and prior to drawing any of the nested
940+
// decal geometry that is to be applied to the base
941+
// geometry.
942+
////////////////////////////////////////////////////////////////////
943+
CPT(RenderState) GraphicsStateGuardian::
944+
begin_decal_nested() {
945+
// We keep the depth buffer off during this operation, although
946+
// perhaps it doesn't matter so much here.
947+
static CPT(RenderState) decal_nested;
948+
if (decal_nested == (const RenderState *)NULL) {
949+
decal_nested = RenderState::make
950+
(DepthWriteAttrib::make(DepthWriteAttrib::M_off));
951+
}
952+
return decal_nested;
953+
}
954+
955+
////////////////////////////////////////////////////////////////////
956+
// Function: GraphicsStateGuardian::begin_decal_base_second
957+
// Access: Public, Virtual
958+
// Description: Called during draw to begin a three-step rendering
959+
// phase to draw decals. The third step,
960+
// begin_decal_base_second(), is called after drawing the
961+
// base geometry and the nested decal geometry, and
962+
// prior to drawing the base geometry one more time (if
963+
// needed).
964+
//
965+
// It should return a RenderState object appropriate for
966+
// rendering the base geometry the second time, or NULL
967+
// if it is not necessary to re-render the base
968+
// geometry.
969+
////////////////////////////////////////////////////////////////////
970+
CPT(RenderState) GraphicsStateGuardian::
971+
begin_decal_base_second() {
972+
// Now let the depth buffer go back on, but turn off writing the
973+
// color buffer to render the base geometry after the second pass.
974+
static CPT(RenderState) decal_base_second;
975+
if (decal_base_second == (const RenderState *)NULL) {
976+
decal_base_second = RenderState::make
977+
(ColorWriteAttrib::make(ColorWriteAttrib::M_off));
978+
}
979+
return decal_base_second;
980+
}
981+
982+
////////////////////////////////////////////////////////////////////
983+
// Function: GraphicsStateGuardian::finish_decal
984+
// Access: Public, Virtual
985+
// Description: Called during draw to clean up after decals are
986+
// finished.
987+
////////////////////////////////////////////////////////////////////
988+
void GraphicsStateGuardian::
989+
finish_decal() {
990+
// No need to do anything special here.
991+
}
992+
895993
////////////////////////////////////////////////////////////////////
896994
// Function: GraphicsStateGuardian::get_internal_coordinate_system
897995
// Access: Public, Virtual

panda/src/display/graphicsStateGuardian.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ class EXPCL_PANDA GraphicsStateGuardian : public GraphicsStateGuardianBase {
135135
virtual void begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib);
136136
virtual void end_decal(GeomNode *base_geom);
137137

138+
virtual bool polygon_offset_decals();
139+
virtual CPT(RenderState) begin_decal_base_first();
140+
virtual CPT(RenderState) begin_decal_nested();
141+
virtual CPT(RenderState) begin_decal_base_second();
142+
virtual void finish_decal();
143+
138144
virtual void reset();
139145

140146
// *** QP

panda/src/egg2pg/qpeggLoader.cxx

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "cullFaceAttrib.h"
2929
#include "cullBinAttrib.h"
3030
#include "transparencyAttrib.h"
31+
#include "decalAttrib.h"
3132
#include "qpgeomNode.h"
3233
#include "string_utils.h"
3334
#include "eggPrimitive.h"
@@ -39,6 +40,7 @@
3940
#include "eggPolygon.h"
4041
#include "eggBin.h"
4142
#include "eggTable.h"
43+
#include "nodeChain.h"
4244

4345
#include <ctype.h>
4446
#include <algorithm>
@@ -123,16 +125,13 @@ build_graph() {
123125
make_node(&_data, _root);
124126
_builder.qpbuild();
125127

126-
/*
127-
reset_directs();
128+
// reset_directs();
128129
reparent_decals();
129130

130-
apply_deferred_arcs(_root);
131-
*/
131+
// apply_deferred_arcs(_root);
132132
}
133133

134134

135-
/*
136135
////////////////////////////////////////////////////////////////////
137136
// Function: qpEggLoader::reparent_decals
138137
// Access: Public
@@ -145,38 +144,34 @@ void qpEggLoader::
145144
reparent_decals() {
146145
Decals::const_iterator di;
147146
for (di = _decals.begin(); di != _decals.end(); ++di) {
148-
RenderRelation *arc = (*di);
149-
nassertv(arc != (RenderRelation *)NULL);
150-
PandaNode *node = DCAST(PandaNode, arc->get_child());
147+
PandaNode *node = (*di);
151148
nassertv(node != (PandaNode *)NULL);
152149

150+
// The NodeChain interface is best for this.
151+
NodeChain parent(node);
152+
153153
// First, search for the GeomNode.
154-
GeomNode *geom = NULL;
155-
int num_children =
156-
node->get_num_children(RenderRelation::get_class_type());
154+
NodeChain geom_parent;
155+
int num_children = parent.get_num_children();
157156
for (int i = 0; i < num_children; i++) {
158-
NodeRelation *child_arc =
159-
node->get_child(RenderRelation::get_class_type(), i);
160-
nassertv(child_arc != (NodeRelation *)NULL);
161-
Node *child = child_arc->get_child();
162-
nassertv(child != (Node *)NULL);
157+
NodeChain child = parent.get_child(i);
163158

164-
if (child->is_of_type(GeomNode::get_class_type())) {
165-
if (geom != (GeomNode *)NULL) {
159+
if (child.node()->is_of_type(qpGeomNode::get_class_type())) {
160+
if (!geom_parent.is_empty()) {
166161
// Oops, too many GeomNodes.
167162
egg2pg_cat.error()
168-
<< "Decal onto " << node->get_name()
169-
<< " uses base geometry with multiple states.\n";
163+
<< "Decal onto " << parent.node()->get_name()
164+
<< " uses base geometry with multiple GeomNodes.\n";
170165
_error = true;
171166
}
172-
DCAST_INTO_V(geom, child);
167+
geom_parent = child;
173168
}
174169
}
175170

176-
if (geom == (GeomNode *)NULL) {
171+
if (geom_parent.is_empty()) {
177172
// No children were GeomNodes.
178173
egg2pg_cat.error()
179-
<< "Ignoring decal onto " << node->get_name()
174+
<< "Ignoring decal onto " << parent.node()->get_name()
180175
<< "; no geometry within group.\n";
181176
_error = true;
182177
} else {
@@ -185,23 +180,21 @@ reparent_decals() {
185180
// list.
186181
int i = 0;
187182
while (i < num_children) {
188-
NodeRelation *child_arc =
189-
node->get_child(RenderRelation::get_class_type(), i);
190-
nassertv(child_arc != (NodeRelation *)NULL);
191-
Node *child = child_arc->get_child();
192-
nassertv(child != (Node *)NULL);
183+
NodeChain child = parent.get_child(i);
193184

194-
if (child->is_of_type(GeomNode::get_class_type())) {
185+
if (child.node()->is_of_type(qpGeomNode::get_class_type())) {
195186
i++;
196187
} else {
197-
child_arc->change_parent(geom);
188+
child.reparent_to(geom_parent);
198189
num_children--;
199190
}
200191
}
192+
193+
// Finally, set the DecalAttrib on the base geometry.
194+
geom_parent.node()->set_attrib(DecalAttrib::make());
201195
}
202196
}
203197
}
204-
*/
205198

206199
/*
207200
////////////////////////////////////////////////////////////////////
@@ -1516,7 +1509,6 @@ create_group_arc(EggGroup *egg_group, PandaNode *parent, PandaNode *node) {
15161509
break;
15171510
}
15181511

1519-
/*
15201512
if (egg_group->get_decal_flag()) {
15211513
if (egg_ignore_decals) {
15221514
egg2pg_cat.error()
@@ -1528,12 +1520,8 @@ create_group_arc(EggGroup *egg_group, PandaNode *parent, PandaNode *node) {
15281520
// descendant groups will be decaled onto the geometry within
15291521
// this group. This means we'll need to reparent things a bit
15301522
// afterward.
1531-
_decals.insert(arc);
1532-
1533-
// We'll also set up the DecalTransition now.
1534-
arc->set_transition(new DecalTransition);
1523+
_decals.insert(node);
15351524
}
1536-
*/
15371525

15381526
/*
15391527
if (egg_group->get_direct_flag()) {

panda/src/egg2pg/qpeggLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ class qpEggLoader {
139139
Materials _materials_bface;
140140
*/
141141

142-
/*
143142
typedef pset<PandaNode *> Decals;
144143
Decals _decals;
145144

145+
/*
146146
typedef pset<PandaNode *> Directs;
147147
Directs _directs;
148148

panda/src/glgsg/glGraphicsStateGuardian.I

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -473,23 +473,6 @@ call_glBlendFunc(GLenum sfunc, GLenum dfunc) {
473473
}
474474
}
475475

476-
////////////////////////////////////////////////////////////////////
477-
// Function: GLGraphicsStateGuardian::call_glDepthMask
478-
// Access:
479-
// Description:
480-
////////////////////////////////////////////////////////////////////
481-
INLINE void GLGraphicsStateGuardian::
482-
call_glDepthMask(GLboolean mask) {
483-
if (_depth_mask != mask) {
484-
_depth_mask = mask;
485-
#ifdef GSG_VERBOSE
486-
glgsg_cat.debug()
487-
<< "glDepthMask(" << (int)mask << ")" << endl;
488-
#endif
489-
glDepthMask(mask);
490-
}
491-
}
492-
493476
////////////////////////////////////////////////////////////////////
494477
// Function: GLGraphicsStateGuardian::call_glFogMode
495478
// Access:

0 commit comments

Comments
 (0)