os/graphics/m3g/m3gcore11/inc/m3g_node.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: Node interface
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
#ifndef __M3G_NODE_H__
sl@0
    19
#define __M3G_NODE_H__
sl@0
    20
sl@0
    21
/*!
sl@0
    22
 * \internal
sl@0
    23
 * \file
sl@0
    24
 * \brief Node interface
sl@0
    25
 */
sl@0
    26
sl@0
    27
#include "m3g_transformable.h"
sl@0
    28
sl@0
    29
#include "m3g_gl.h"
sl@0
    30
#include "m3g_math.h"
sl@0
    31
#include "m3g_lightmanager.h"
sl@0
    32
#include "m3g_renderqueue.h"
sl@0
    33
sl@0
    34
#define NODE_ALPHA_FACTOR_BITS  16
sl@0
    35
sl@0
    36
/* NOTE: Implementation depends on these values -- do not change! */
sl@0
    37
#define CULLMASK_OUTSIDE        0x0
sl@0
    38
#define CULLMASK_INSIDE         0x1
sl@0
    39
#define CULLMASK_INTERSECTS     0x2
sl@0
    40
#define CULLMASK_ALL            0xAAA
sl@0
    41
M3G_CT_ASSERT(CULLMASK_INSIDE == (CULLMASK_INTERSECTS >> 1));
sl@0
    42
sl@0
    43
/*
sl@0
    44
 * Estimated load metrics for VF culling
sl@0
    45
 *
sl@0
    46
 */
sl@0
    47
#define VFC_BBOX_COST           30
sl@0
    48
#define VFC_NODE_OVERHEAD       10
sl@0
    49
#define VFC_RENDERCALL_OVERHEAD 15
sl@0
    50
#define VFC_TRIANGLE_COST       1
sl@0
    51
#define VFC_VERTEX_COST         1
sl@0
    52
sl@0
    53
/*
sl@0
    54
 * Enable bit masks
sl@0
    55
 */
sl@0
    56
#define NODE_RENDER_BIT 0x1
sl@0
    57
#define NODE_PICK_BIT   0x2
sl@0
    58
sl@0
    59
/*!
sl@0
    60
 * \internal
sl@0
    61
 * \brief RayIntersection object
sl@0
    62
*/
sl@0
    63
struct M3GRayIntersectionImpl
sl@0
    64
{
sl@0
    65
    Node *root;
sl@0
    66
    Camera *camera;
sl@0
    67
    M3Gfloat x;
sl@0
    68
    M3Gfloat y;
sl@0
    69
    M3Gfloat tMin;
sl@0
    70
	M3Gfloat distance;
sl@0
    71
	M3Gint submeshIndex;
sl@0
    72
	M3Gfloat textureS[M3G_NUM_TEXTURE_UNITS];
sl@0
    73
	M3Gfloat textureT[M3G_NUM_TEXTURE_UNITS];
sl@0
    74
	M3Gfloat normal[3];
sl@0
    75
    Node *intersected;
sl@0
    76
};
sl@0
    77
sl@0
    78
/*
sl@0
    79
RayIntersection Java side result must be in this format.
sl@0
    80
sl@0
    81
Offsets Contents
sl@0
    82
-------------------------------------
sl@0
    83
0       distance
sl@0
    84
1       subMeshIndex
sl@0
    85
2-3     textureS coordinates
sl@0
    86
4-5     textureT coordinates
sl@0
    87
6-8     normal coordinates
sl@0
    88
9-14    ray coordinates and direction
sl@0
    89
sl@0
    90
*/
sl@0
    91
sl@0
    92
/*!
sl@0
    93
 * \internal
sl@0
    94
 * \brief Recursively inherited state passed to each SetupRender call
sl@0
    95
 */
sl@0
    96
typedef struct 
sl@0
    97
{
sl@0
    98
    Matrix toCamera;
sl@0
    99
    M3Gbitmask cullMask;
sl@0
   100
} SetupRenderState;
sl@0
   101
sl@0
   102
/* Function pointer prototypes */
sl@0
   103
sl@0
   104
typedef M3Gbool (*m3gAlignFuncPtr)			    (Node *self, const Node *refNode);
sl@0
   105
typedef void    (*m3gDoRenderFuncPtr)		    (Node *self, RenderContext *ctx, const Matrix *toCamera, M3Gint patchIndex);
sl@0
   106
typedef M3Gint  (*m3gGetBBoxFuncPtr)            (Node *self, AABB *bbox);
sl@0
   107
typedef M3Gbool (*m3gRayIntersectFuncPtr)       (Node *self, M3Gint mask, M3Gfloat *ray, RayIntersection *ri, Matrix *toGroup);
sl@0
   108
typedef M3Gbool (*m3gSetupRenderFuncPtr)	    (Node *self, const Node *caller, SetupRenderState *rs, RenderQueue *renderQueue);
sl@0
   109
typedef void    (*m3gUpdateDuplicateRefFuncPtr)	(Node *self, Object **pairs, M3Gint numPairs);
sl@0
   110
typedef M3Gbool (*m3gValidate)                  (Node *self, M3Gbitmask state, M3Gint scope);
sl@0
   111
sl@0
   112
/*!
sl@0
   113
 * \internal
sl@0
   114
 * \brief Node class virtual functions
sl@0
   115
 */
sl@0
   116
typedef struct
sl@0
   117
{
sl@0
   118
	TransformableVFTable transformable;
sl@0
   119
    
sl@0
   120
	m3gAlignFuncPtr                 align;
sl@0
   121
	m3gDoRenderFuncPtr              doRender;
sl@0
   122
    m3gGetBBoxFuncPtr               getBBox;
sl@0
   123
	m3gRayIntersectFuncPtr          rayIntersect;
sl@0
   124
	m3gSetupRenderFuncPtr           setupRender;
sl@0
   125
    m3gUpdateDuplicateRefFuncPtr    updateDuplicateReferences;
sl@0
   126
    m3gValidate                     validate;
sl@0
   127
} NodeVFTable;
sl@0
   128
sl@0
   129
/*!
sl@0
   130
 * \internal
sl@0
   131
 * \brief Node class structure
sl@0
   132
 *
sl@0
   133
 */
sl@0
   134
struct M3GNodeImpl
sl@0
   135
{
sl@0
   136
	Transformable transformable;
sl@0
   137
sl@0
   138
	/* See default values form RI implementation Node.java */
sl@0
   139
sl@0
   140
    /* These scene graph pointers are managed by the Group class */
sl@0
   141
    
sl@0
   142
	Node *parent;
sl@0
   143
	Node *left;
sl@0
   144
	Node *right;
sl@0
   145
    
sl@0
   146
	M3Gint scope;
sl@0
   147
sl@0
   148
    /* Alignment references */
sl@0
   149
    
sl@0
   150
    Node *zReference;
sl@0
   151
	Node *yReference;
sl@0
   152
sl@0
   153
    /* Various node flags and other bitfield data */
sl@0
   154
sl@0
   155
    M3Guint alphaFactor : NODE_ALPHA_FACTOR_BITS;
sl@0
   156
    
sl@0
   157
	M3Guint zTarget     : 3; /* Z alignment target */
sl@0
   158
	M3Guint yTarget     : 3; /* Y alignment target */
sl@0
   159
sl@0
   160
	M3Guint enableBits  : 2; /* Rendering/picking enable bits */
sl@0
   161
sl@0
   162
    M3Guint hasBones    : 1; /* Node is part of a SkinnedMesh skeleton */
sl@0
   163
    M3Guint hasRenderables : 1; /* Node has renderables in its subtree */
sl@0
   164
sl@0
   165
    M3Guint dirtyBits   : 2; /* BBox and transform dirty bits */
sl@0
   166
};
sl@0
   167
sl@0
   168
/*!
sl@0
   169
 * \internal \brief Node bounding box in valid/dirty bitmasks
sl@0
   170
 */
sl@0
   171
#define NODE_BBOX_BIT           0x01
sl@0
   172
/*!
sl@0
   173
 * \internal \brief Node-child transformations in valid/dirty bitmasks
sl@0
   174
 */
sl@0
   175
#define NODE_TRANSFORMS_BIT     0x02
sl@0
   176
sl@0
   177
/* Sanity check; check compiler padding settings if this assert fails */
sl@0
   178
sl@0
   179
M3G_CT_ASSERT(sizeof(Node) == sizeof(Transformable) + 28);
sl@0
   180
sl@0
   181
              
sl@0
   182
/*----------------------------------------------------------------------
sl@0
   183
 * Virtual functions
sl@0
   184
 *--------------------------------------------------------------------*/
sl@0
   185
sl@0
   186
static void m3gDestroyNode(Object *obj);
sl@0
   187
static M3Gbool m3gNodeAlign(Node *self, const Node *refNode);
sl@0
   188
static M3Gbool m3gNodeDuplicate(const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
sl@0
   189
static M3Gint m3gNodeGetBBox(Node *self, AABB *bbox);
sl@0
   190
static M3Gbool m3gNodeIsCompatible(M3Gint property);
sl@0
   191
static M3Gbool m3gNodeRayIntersect(Node *self, M3Gint mask, M3Gfloat *ray, RayIntersection *ri, Matrix *toGroup);
sl@0
   192
static void m3gNodeUpdateProperty(Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
sl@0
   193
static void m3gNodeUpdateDuplicateReferences(Node *self, Object **pairs, M3Gint numPairs);
sl@0
   194
static M3Gbool m3gNodeValidate(Node *self, M3Gbitmask stateBits, M3Gint scope);
sl@0
   195
sl@0
   196
sl@0
   197
static M3G_INLINE M3Gint m3gGetNodeBBox(Node *node, AABB *bbox)
sl@0
   198
{
sl@0
   199
    return M3G_VFUNC(Node, node, getBBox)(node, bbox);
sl@0
   200
}
sl@0
   201
sl@0
   202
static M3G_INLINE M3Gbool m3gValidateNode(Node *node, M3Gbitmask stateBits, M3Gint scope) 
sl@0
   203
{
sl@0
   204
    return M3G_VFUNC(Node, node, validate)(node, stateBits, scope);
sl@0
   205
}
sl@0
   206
sl@0
   207
/*----------------------------------------------------------------------
sl@0
   208
 * Internal functions
sl@0
   209
 *--------------------------------------------------------------------*/
sl@0
   210
sl@0
   211
static void m3gInitNode(Interface *m3g, Node *node, M3GClass classID);
sl@0
   212
static M3Guint m3gGetTotalAlphaFactor(Node *node, const Node *root);
sl@0
   213
static M3Gbool m3gHasEnabledPath(const Node *node, const Node *root);
sl@0
   214
static M3Gbool m3gHasPickablePath(const Node *node, const Node *root);
sl@0
   215
static M3Gbool m3gIsChildOf(const Node *parent, const Node *child);
sl@0
   216
static Node *m3gGetRoot(const Node *node);
sl@0
   217
sl@0
   218
static void m3gInvalidateNode(Node *node, M3Gbitmask flags);
sl@0
   219
sl@0
   220
typedef void    (*NodeFuncPtr)  (Node *node, void *params);
sl@0
   221
static void     m3gForSubtree   (Node *node, NodeFuncPtr func, void *params);
sl@0
   222
sl@0
   223
static void     m3gSetParent    (Node *node, Node *parent);
sl@0
   224
static Node *m3gGetDuplicatedInstance(Node *self, Object **references, M3Gint numRef);
sl@0
   225
sl@0
   226
#if defined(M3G_ENABLE_VF_CULLING)           
sl@0
   227
static void m3gUpdateCullingMask(SetupRenderState *s, const Camera *cam, const AABB *bbox);
sl@0
   228
#endif
sl@0
   229
sl@0
   230
/*!
sl@0
   231
 * \internal
sl@0
   232
 * \brief Type-safe helper function
sl@0
   233
 */
sl@0
   234
static M3G_INLINE void m3gGetCompositeNodeTransform(const Node *node, Matrix *mtx)
sl@0
   235
{
sl@0
   236
    m3gGetCompositeTransform((Transformable*) node, mtx);
sl@0
   237
    M3G_ASSERT(m3gIsWUnity(mtx));
sl@0
   238
}
sl@0
   239
sl@0
   240
/*!
sl@0
   241
 * \internal
sl@0
   242
 * \brief Type-safe helper function
sl@0
   243
 */
sl@0
   244
static M3G_INLINE M3Gbool m3gGetInverseNodeTransform(const Node *node, Matrix *mtx)
sl@0
   245
{
sl@0
   246
    M3Gbool ok = m3gGetInverseCompositeTransform((Transformable*) node, mtx);
sl@0
   247
    M3G_ASSERT(m3gIsWUnity(mtx));
sl@0
   248
    return ok;
sl@0
   249
}
sl@0
   250
sl@0
   251
#endif /*__M3G_NODE_H__*/