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: VertexBuffer interface
18 #ifndef __M3G_VERTEXBUFFER_H__
19 #define __M3G_VERTEXBUFFER_H__
24 * \brief VertexBuffer interface
27 #include "m3g_object.h"
28 #include "m3g_vertexarray.h"
32 * \brief \c VertexBuffer object instance
34 struct M3GVertexBufferImpl
42 VertexArray *texCoords[M3G_NUM_TEXTURE_UNITS];
44 VertexArray *vertices;
46 GLfloat texCoordScale[M3G_NUM_TEXTURE_UNITS];
47 GLfloat texCoordBias[M3G_NUM_TEXTURE_UNITS][3];
50 GLfloat vertexBias[3];
52 /*! \internal \brief Default vertex color */
53 struct { GLubyte r, g, b, a; } defaultColor;
60 M3Gint verticesTimestamp;
65 /*! \brief vertex component mask bits */
66 #define M3G_POSITION_BIT 0x01u
67 #define M3G_COLOR_BIT 0x02u
68 #define M3G_NORMAL_BIT 0x04u
70 #define M3G_TEXCOORD0_BIT 0x10u
71 #define M3G_TEXCOORD1_BIT 0x20u
72 #define M3G_TEXCOORD2_BIT 0x40u
73 #define M3G_TEXCOORD3_BIT 0x80u
75 /*----------------------------------------------------------------------
77 *--------------------------------------------------------------------*/
79 static void m3gApplyScaleAndBias(const VertexBuffer *buffer);
80 static void m3gLockVertexBuffer(const VertexBuffer *buffer, M3Gint alphaFactor);
81 static void m3gReleaseVertexBuffer(const VertexBuffer *buffer);
83 static M3Gbool m3gGetVertex(const VertexBuffer *buffer, M3Gint idx, Vec3 *v);
84 static M3Gbool m3gGetNormal(const VertexBuffer *buffer, M3Gint idx, Vec3 *v);
85 static M3Gbool m3gGetTexCoord(const VertexBuffer *buffer, M3Gint idx, int unit, Vec3 *v);
87 static M3Gint m3gGetTimestamp(const VertexBuffer *buffer);
88 static M3Gint m3gGetNumVertices(const VertexBuffer *buffer);
89 static M3Gbitmask m3gGetArrayMask(const VertexBuffer *buffer);
91 static M3Gbool m3gValidateVertexBuffer(const VertexBuffer *vb,
92 const Appearance *app,
94 static void m3gGetBoundingBox(VertexBuffer *buffer, AABB *boundingBox);
96 static M3Gbool m3gMakeModifiedVertexBuffer(VertexBuffer *buffer,
97 const VertexBuffer *srcBuffer,
99 M3Gbool createArrays);
102 /* -------- Inline functions -------- */
106 * \brief Queries whether a vertex buffer can be (safely) bound with
107 * memory locking in effect
109 static M3G_INLINE M3Gbool m3gValidateAlphaCache(const VertexBuffer *buffer)
111 const VertexArray *colArray = buffer->colors;
112 return colArray ? (colArray->cachedColors != 0) : M3G_TRUE;
117 * \brief Type-safe helper function
119 static M3G_INLINE void m3gDeleteVertexBuffer(VertexBuffer *buffer)
121 m3gDeleteObject((Object *) buffer);
126 * \brief Gets number of vertices in this buffer.
128 static M3G_INLINE M3Gint m3gGetNumVertices(const VertexBuffer *buffer)
130 return buffer->vertexCount;
135 * \brief Returns the current array mask for this buffer
137 static M3G_INLINE M3Gbitmask m3gGetArrayMask(const VertexBuffer *buffer)
139 return buffer->arrayMask;
142 #endif /*__M3G_VERTEXBUFFER_H__*/