Update contrib.
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Node interface
18 #ifndef __M3G_NODE_H__
19 #define __M3G_NODE_H__
24 * \brief Node interface
27 #include "m3g_transformable.h"
31 #include "m3g_lightmanager.h"
32 #include "m3g_renderqueue.h"
34 #define NODE_ALPHA_FACTOR_BITS 16
36 /* NOTE: Implementation depends on these values -- do not change! */
37 #define CULLMASK_OUTSIDE 0x0
38 #define CULLMASK_INSIDE 0x1
39 #define CULLMASK_INTERSECTS 0x2
40 #define CULLMASK_ALL 0xAAA
41 M3G_CT_ASSERT(CULLMASK_INSIDE == (CULLMASK_INTERSECTS >> 1));
44 * Estimated load metrics for VF culling
47 #define VFC_BBOX_COST 30
48 #define VFC_NODE_OVERHEAD 10
49 #define VFC_RENDERCALL_OVERHEAD 15
50 #define VFC_TRIANGLE_COST 1
51 #define VFC_VERTEX_COST 1
56 #define NODE_RENDER_BIT 0x1
57 #define NODE_PICK_BIT 0x2
61 * \brief RayIntersection object
63 struct M3GRayIntersectionImpl
72 M3Gfloat textureS[M3G_NUM_TEXTURE_UNITS];
73 M3Gfloat textureT[M3G_NUM_TEXTURE_UNITS];
79 RayIntersection Java side result must be in this format.
82 -------------------------------------
85 2-3 textureS coordinates
86 4-5 textureT coordinates
87 6-8 normal coordinates
88 9-14 ray coordinates and direction
94 * \brief Recursively inherited state passed to each SetupRender call
102 /* Function pointer prototypes */
104 typedef M3Gbool (*m3gAlignFuncPtr) (Node *self, const Node *refNode);
105 typedef void (*m3gDoRenderFuncPtr) (Node *self, RenderContext *ctx, const Matrix *toCamera, M3Gint patchIndex);
106 typedef M3Gint (*m3gGetBBoxFuncPtr) (Node *self, AABB *bbox);
107 typedef M3Gbool (*m3gRayIntersectFuncPtr) (Node *self, M3Gint mask, M3Gfloat *ray, RayIntersection *ri, Matrix *toGroup);
108 typedef M3Gbool (*m3gSetupRenderFuncPtr) (Node *self, const Node *caller, SetupRenderState *rs, RenderQueue *renderQueue);
109 typedef void (*m3gUpdateDuplicateRefFuncPtr) (Node *self, Object **pairs, M3Gint numPairs);
110 typedef M3Gbool (*m3gValidate) (Node *self, M3Gbitmask state, M3Gint scope);
114 * \brief Node class virtual functions
118 TransformableVFTable transformable;
120 m3gAlignFuncPtr align;
121 m3gDoRenderFuncPtr doRender;
122 m3gGetBBoxFuncPtr getBBox;
123 m3gRayIntersectFuncPtr rayIntersect;
124 m3gSetupRenderFuncPtr setupRender;
125 m3gUpdateDuplicateRefFuncPtr updateDuplicateReferences;
126 m3gValidate validate;
131 * \brief Node class structure
136 Transformable transformable;
138 /* See default values form RI implementation Node.java */
140 /* These scene graph pointers are managed by the Group class */
148 /* Alignment references */
153 /* Various node flags and other bitfield data */
155 M3Guint alphaFactor : NODE_ALPHA_FACTOR_BITS;
157 M3Guint zTarget : 3; /* Z alignment target */
158 M3Guint yTarget : 3; /* Y alignment target */
160 M3Guint enableBits : 2; /* Rendering/picking enable bits */
162 M3Guint hasBones : 1; /* Node is part of a SkinnedMesh skeleton */
163 M3Guint hasRenderables : 1; /* Node has renderables in its subtree */
165 M3Guint dirtyBits : 2; /* BBox and transform dirty bits */
169 * \internal \brief Node bounding box in valid/dirty bitmasks
171 #define NODE_BBOX_BIT 0x01
173 * \internal \brief Node-child transformations in valid/dirty bitmasks
175 #define NODE_TRANSFORMS_BIT 0x02
177 /* Sanity check; check compiler padding settings if this assert fails */
179 M3G_CT_ASSERT(sizeof(Node) == sizeof(Transformable) + 28);
182 /*----------------------------------------------------------------------
184 *--------------------------------------------------------------------*/
186 static void m3gDestroyNode(Object *obj);
187 static M3Gbool m3gNodeAlign(Node *self, const Node *refNode);
188 static M3Gbool m3gNodeDuplicate(const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
189 static M3Gint m3gNodeGetBBox(Node *self, AABB *bbox);
190 static M3Gbool m3gNodeIsCompatible(M3Gint property);
191 static M3Gbool m3gNodeRayIntersect(Node *self, M3Gint mask, M3Gfloat *ray, RayIntersection *ri, Matrix *toGroup);
192 static void m3gNodeUpdateProperty(Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
193 static void m3gNodeUpdateDuplicateReferences(Node *self, Object **pairs, M3Gint numPairs);
194 static M3Gbool m3gNodeValidate(Node *self, M3Gbitmask stateBits, M3Gint scope);
197 static M3G_INLINE M3Gint m3gGetNodeBBox(Node *node, AABB *bbox)
199 return M3G_VFUNC(Node, node, getBBox)(node, bbox);
202 static M3G_INLINE M3Gbool m3gValidateNode(Node *node, M3Gbitmask stateBits, M3Gint scope)
204 return M3G_VFUNC(Node, node, validate)(node, stateBits, scope);
207 /*----------------------------------------------------------------------
209 *--------------------------------------------------------------------*/
211 static void m3gInitNode(Interface *m3g, Node *node, M3GClass classID);
212 static M3Guint m3gGetTotalAlphaFactor(Node *node, const Node *root);
213 static M3Gbool m3gHasEnabledPath(const Node *node, const Node *root);
214 static M3Gbool m3gHasPickablePath(const Node *node, const Node *root);
215 static M3Gbool m3gIsChildOf(const Node *parent, const Node *child);
216 static Node *m3gGetRoot(const Node *node);
218 static void m3gInvalidateNode(Node *node, M3Gbitmask flags);
220 typedef void (*NodeFuncPtr) (Node *node, void *params);
221 static void m3gForSubtree (Node *node, NodeFuncPtr func, void *params);
223 static void m3gSetParent (Node *node, Node *parent);
224 static Node *m3gGetDuplicatedInstance(Node *self, Object **references, M3Gint numRef);
226 #if defined(M3G_ENABLE_VF_CULLING)
227 static void m3gUpdateCullingMask(SetupRenderState *s, const Camera *cam, const AABB *bbox);
232 * \brief Type-safe helper function
234 static M3G_INLINE void m3gGetCompositeNodeTransform(const Node *node, Matrix *mtx)
236 m3gGetCompositeTransform((Transformable*) node, mtx);
237 M3G_ASSERT(m3gIsWUnity(mtx));
242 * \brief Type-safe helper function
244 static M3G_INLINE M3Gbool m3gGetInverseNodeTransform(const Node *node, Matrix *mtx)
246 M3Gbool ok = m3gGetInverseCompositeTransform((Transformable*) node, mtx);
247 M3G_ASSERT(m3gIsWUnity(mtx));
251 #endif /*__M3G_NODE_H__*/