1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/m3g/m3gcore11/inc/m3g_node.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,251 @@
1.4 +/*
1.5 +* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Node interface
1.18 +*
1.19 +*/
1.20 +
1.21 +#ifndef __M3G_NODE_H__
1.22 +#define __M3G_NODE_H__
1.23 +
1.24 +/*!
1.25 + * \internal
1.26 + * \file
1.27 + * \brief Node interface
1.28 + */
1.29 +
1.30 +#include "m3g_transformable.h"
1.31 +
1.32 +#include "m3g_gl.h"
1.33 +#include "m3g_math.h"
1.34 +#include "m3g_lightmanager.h"
1.35 +#include "m3g_renderqueue.h"
1.36 +
1.37 +#define NODE_ALPHA_FACTOR_BITS 16
1.38 +
1.39 +/* NOTE: Implementation depends on these values -- do not change! */
1.40 +#define CULLMASK_OUTSIDE 0x0
1.41 +#define CULLMASK_INSIDE 0x1
1.42 +#define CULLMASK_INTERSECTS 0x2
1.43 +#define CULLMASK_ALL 0xAAA
1.44 +M3G_CT_ASSERT(CULLMASK_INSIDE == (CULLMASK_INTERSECTS >> 1));
1.45 +
1.46 +/*
1.47 + * Estimated load metrics for VF culling
1.48 + *
1.49 + */
1.50 +#define VFC_BBOX_COST 30
1.51 +#define VFC_NODE_OVERHEAD 10
1.52 +#define VFC_RENDERCALL_OVERHEAD 15
1.53 +#define VFC_TRIANGLE_COST 1
1.54 +#define VFC_VERTEX_COST 1
1.55 +
1.56 +/*
1.57 + * Enable bit masks
1.58 + */
1.59 +#define NODE_RENDER_BIT 0x1
1.60 +#define NODE_PICK_BIT 0x2
1.61 +
1.62 +/*!
1.63 + * \internal
1.64 + * \brief RayIntersection object
1.65 +*/
1.66 +struct M3GRayIntersectionImpl
1.67 +{
1.68 + Node *root;
1.69 + Camera *camera;
1.70 + M3Gfloat x;
1.71 + M3Gfloat y;
1.72 + M3Gfloat tMin;
1.73 + M3Gfloat distance;
1.74 + M3Gint submeshIndex;
1.75 + M3Gfloat textureS[M3G_NUM_TEXTURE_UNITS];
1.76 + M3Gfloat textureT[M3G_NUM_TEXTURE_UNITS];
1.77 + M3Gfloat normal[3];
1.78 + Node *intersected;
1.79 +};
1.80 +
1.81 +/*
1.82 +RayIntersection Java side result must be in this format.
1.83 +
1.84 +Offsets Contents
1.85 +-------------------------------------
1.86 +0 distance
1.87 +1 subMeshIndex
1.88 +2-3 textureS coordinates
1.89 +4-5 textureT coordinates
1.90 +6-8 normal coordinates
1.91 +9-14 ray coordinates and direction
1.92 +
1.93 +*/
1.94 +
1.95 +/*!
1.96 + * \internal
1.97 + * \brief Recursively inherited state passed to each SetupRender call
1.98 + */
1.99 +typedef struct
1.100 +{
1.101 + Matrix toCamera;
1.102 + M3Gbitmask cullMask;
1.103 +} SetupRenderState;
1.104 +
1.105 +/* Function pointer prototypes */
1.106 +
1.107 +typedef M3Gbool (*m3gAlignFuncPtr) (Node *self, const Node *refNode);
1.108 +typedef void (*m3gDoRenderFuncPtr) (Node *self, RenderContext *ctx, const Matrix *toCamera, M3Gint patchIndex);
1.109 +typedef M3Gint (*m3gGetBBoxFuncPtr) (Node *self, AABB *bbox);
1.110 +typedef M3Gbool (*m3gRayIntersectFuncPtr) (Node *self, M3Gint mask, M3Gfloat *ray, RayIntersection *ri, Matrix *toGroup);
1.111 +typedef M3Gbool (*m3gSetupRenderFuncPtr) (Node *self, const Node *caller, SetupRenderState *rs, RenderQueue *renderQueue);
1.112 +typedef void (*m3gUpdateDuplicateRefFuncPtr) (Node *self, Object **pairs, M3Gint numPairs);
1.113 +typedef M3Gbool (*m3gValidate) (Node *self, M3Gbitmask state, M3Gint scope);
1.114 +
1.115 +/*!
1.116 + * \internal
1.117 + * \brief Node class virtual functions
1.118 + */
1.119 +typedef struct
1.120 +{
1.121 + TransformableVFTable transformable;
1.122 +
1.123 + m3gAlignFuncPtr align;
1.124 + m3gDoRenderFuncPtr doRender;
1.125 + m3gGetBBoxFuncPtr getBBox;
1.126 + m3gRayIntersectFuncPtr rayIntersect;
1.127 + m3gSetupRenderFuncPtr setupRender;
1.128 + m3gUpdateDuplicateRefFuncPtr updateDuplicateReferences;
1.129 + m3gValidate validate;
1.130 +} NodeVFTable;
1.131 +
1.132 +/*!
1.133 + * \internal
1.134 + * \brief Node class structure
1.135 + *
1.136 + */
1.137 +struct M3GNodeImpl
1.138 +{
1.139 + Transformable transformable;
1.140 +
1.141 + /* See default values form RI implementation Node.java */
1.142 +
1.143 + /* These scene graph pointers are managed by the Group class */
1.144 +
1.145 + Node *parent;
1.146 + Node *left;
1.147 + Node *right;
1.148 +
1.149 + M3Gint scope;
1.150 +
1.151 + /* Alignment references */
1.152 +
1.153 + Node *zReference;
1.154 + Node *yReference;
1.155 +
1.156 + /* Various node flags and other bitfield data */
1.157 +
1.158 + M3Guint alphaFactor : NODE_ALPHA_FACTOR_BITS;
1.159 +
1.160 + M3Guint zTarget : 3; /* Z alignment target */
1.161 + M3Guint yTarget : 3; /* Y alignment target */
1.162 +
1.163 + M3Guint enableBits : 2; /* Rendering/picking enable bits */
1.164 +
1.165 + M3Guint hasBones : 1; /* Node is part of a SkinnedMesh skeleton */
1.166 + M3Guint hasRenderables : 1; /* Node has renderables in its subtree */
1.167 +
1.168 + M3Guint dirtyBits : 2; /* BBox and transform dirty bits */
1.169 +};
1.170 +
1.171 +/*!
1.172 + * \internal \brief Node bounding box in valid/dirty bitmasks
1.173 + */
1.174 +#define NODE_BBOX_BIT 0x01
1.175 +/*!
1.176 + * \internal \brief Node-child transformations in valid/dirty bitmasks
1.177 + */
1.178 +#define NODE_TRANSFORMS_BIT 0x02
1.179 +
1.180 +/* Sanity check; check compiler padding settings if this assert fails */
1.181 +
1.182 +M3G_CT_ASSERT(sizeof(Node) == sizeof(Transformable) + 28);
1.183 +
1.184 +
1.185 +/*----------------------------------------------------------------------
1.186 + * Virtual functions
1.187 + *--------------------------------------------------------------------*/
1.188 +
1.189 +static void m3gDestroyNode(Object *obj);
1.190 +static M3Gbool m3gNodeAlign(Node *self, const Node *refNode);
1.191 +static M3Gbool m3gNodeDuplicate(const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
1.192 +static M3Gint m3gNodeGetBBox(Node *self, AABB *bbox);
1.193 +static M3Gbool m3gNodeIsCompatible(M3Gint property);
1.194 +static M3Gbool m3gNodeRayIntersect(Node *self, M3Gint mask, M3Gfloat *ray, RayIntersection *ri, Matrix *toGroup);
1.195 +static void m3gNodeUpdateProperty(Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
1.196 +static void m3gNodeUpdateDuplicateReferences(Node *self, Object **pairs, M3Gint numPairs);
1.197 +static M3Gbool m3gNodeValidate(Node *self, M3Gbitmask stateBits, M3Gint scope);
1.198 +
1.199 +
1.200 +static M3G_INLINE M3Gint m3gGetNodeBBox(Node *node, AABB *bbox)
1.201 +{
1.202 + return M3G_VFUNC(Node, node, getBBox)(node, bbox);
1.203 +}
1.204 +
1.205 +static M3G_INLINE M3Gbool m3gValidateNode(Node *node, M3Gbitmask stateBits, M3Gint scope)
1.206 +{
1.207 + return M3G_VFUNC(Node, node, validate)(node, stateBits, scope);
1.208 +}
1.209 +
1.210 +/*----------------------------------------------------------------------
1.211 + * Internal functions
1.212 + *--------------------------------------------------------------------*/
1.213 +
1.214 +static void m3gInitNode(Interface *m3g, Node *node, M3GClass classID);
1.215 +static M3Guint m3gGetTotalAlphaFactor(Node *node, const Node *root);
1.216 +static M3Gbool m3gHasEnabledPath(const Node *node, const Node *root);
1.217 +static M3Gbool m3gHasPickablePath(const Node *node, const Node *root);
1.218 +static M3Gbool m3gIsChildOf(const Node *parent, const Node *child);
1.219 +static Node *m3gGetRoot(const Node *node);
1.220 +
1.221 +static void m3gInvalidateNode(Node *node, M3Gbitmask flags);
1.222 +
1.223 +typedef void (*NodeFuncPtr) (Node *node, void *params);
1.224 +static void m3gForSubtree (Node *node, NodeFuncPtr func, void *params);
1.225 +
1.226 +static void m3gSetParent (Node *node, Node *parent);
1.227 +static Node *m3gGetDuplicatedInstance(Node *self, Object **references, M3Gint numRef);
1.228 +
1.229 +#if defined(M3G_ENABLE_VF_CULLING)
1.230 +static void m3gUpdateCullingMask(SetupRenderState *s, const Camera *cam, const AABB *bbox);
1.231 +#endif
1.232 +
1.233 +/*!
1.234 + * \internal
1.235 + * \brief Type-safe helper function
1.236 + */
1.237 +static M3G_INLINE void m3gGetCompositeNodeTransform(const Node *node, Matrix *mtx)
1.238 +{
1.239 + m3gGetCompositeTransform((Transformable*) node, mtx);
1.240 + M3G_ASSERT(m3gIsWUnity(mtx));
1.241 +}
1.242 +
1.243 +/*!
1.244 + * \internal
1.245 + * \brief Type-safe helper function
1.246 + */
1.247 +static M3G_INLINE M3Gbool m3gGetInverseNodeTransform(const Node *node, Matrix *mtx)
1.248 +{
1.249 + M3Gbool ok = m3gGetInverseCompositeTransform((Transformable*) node, mtx);
1.250 + M3G_ASSERT(m3gIsWUnity(mtx));
1.251 + return ok;
1.252 +}
1.253 +
1.254 +#endif /*__M3G_NODE_H__*/