os/graphics/m3g/m3gcore11/inc/m3g_vertexbuffer.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: VertexBuffer interface
    15 *
    16 */
    17 
    18 #ifndef __M3G_VERTEXBUFFER_H__
    19 #define __M3G_VERTEXBUFFER_H__
    20 
    21 /*!
    22  * \internal
    23  * \file
    24  * \brief VertexBuffer interface
    25  */
    26 
    27 #include "m3g_object.h"
    28 #include "m3g_vertexarray.h"
    29 
    30 /*!
    31  * \internal
    32  * \brief \c VertexBuffer object instance
    33  */
    34 struct M3GVertexBufferImpl
    35 {
    36     Object object;
    37 
    38     /*@dependent@*/
    39     VertexArray *colors;
    40     /*@dependent@*/
    41     VertexArray *normals;
    42     VertexArray *texCoords[M3G_NUM_TEXTURE_UNITS];
    43     /*@dependent@*/
    44     VertexArray *vertices;
    45 
    46     GLfloat texCoordScale[M3G_NUM_TEXTURE_UNITS];
    47     GLfloat texCoordBias[M3G_NUM_TEXTURE_UNITS][3];
    48 
    49     GLfloat vertexScale;
    50     GLfloat vertexBias[3];
    51 
    52     /*! \internal \brief Default vertex color */
    53     struct { GLubyte r, g, b, a; } defaultColor;
    54     
    55     M3Gbool locked;
    56     M3Gint vertexCount;
    57     M3Gint arrayCount;
    58     M3Gbitmask arrayMask;
    59     M3Gint timestamp;
    60     M3Gint verticesTimestamp;
    61     
    62     AABB bbox;
    63 };
    64 
    65 /*! \brief vertex component mask bits */
    66 #define M3G_POSITION_BIT        0x01u
    67 #define M3G_COLOR_BIT           0x02u
    68 #define M3G_NORMAL_BIT          0x04u
    69 
    70 #define M3G_TEXCOORD0_BIT       0x10u
    71 #define M3G_TEXCOORD1_BIT       0x20u
    72 #define M3G_TEXCOORD2_BIT       0x40u
    73 #define M3G_TEXCOORD3_BIT       0x80u
    74 
    75 /*----------------------------------------------------------------------
    76  * Internal functions
    77  *--------------------------------------------------------------------*/
    78 
    79 static void m3gApplyScaleAndBias(const VertexBuffer *buffer);
    80 static void m3gLockVertexBuffer(const VertexBuffer *buffer, M3Gint alphaFactor);
    81 static void m3gReleaseVertexBuffer(const VertexBuffer *buffer);
    82 
    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);
    86 
    87 static M3Gint m3gGetTimestamp(const VertexBuffer *buffer);
    88 static M3Gint m3gGetNumVertices(const VertexBuffer *buffer);
    89 static M3Gbitmask m3gGetArrayMask(const VertexBuffer *buffer);
    90 
    91 static M3Gbool m3gValidateVertexBuffer(const VertexBuffer *vb,
    92                                        const Appearance *app,
    93                                        M3Gsizei maxIndex);
    94 static void m3gGetBoundingBox(VertexBuffer *buffer, AABB *boundingBox);
    95 
    96 static M3Gbool m3gMakeModifiedVertexBuffer(VertexBuffer *buffer,
    97                                            const VertexBuffer *srcBuffer,
    98                                            M3Gbitmask arrayMask,
    99                                            M3Gbool createArrays);
   100 
   101 
   102 /* -------- Inline functions -------- */
   103 
   104 /*!
   105  * \internal
   106  * \brief Queries whether a vertex buffer can be (safely) bound with
   107  * memory locking in effect
   108  */
   109 static M3G_INLINE M3Gbool m3gValidateAlphaCache(const VertexBuffer *buffer) 
   110 {
   111     const VertexArray *colArray = buffer->colors;
   112     return colArray ? (colArray->cachedColors != 0) : M3G_TRUE;
   113 }
   114 
   115 /*!
   116  * \internal
   117  * \brief Type-safe helper function
   118  */
   119 static M3G_INLINE void m3gDeleteVertexBuffer(VertexBuffer *buffer)
   120 {
   121     m3gDeleteObject((Object *) buffer);
   122 }
   123 
   124 /*!
   125  * \internal
   126  * \brief Gets number of vertices in this buffer.
   127  */
   128 static M3G_INLINE M3Gint m3gGetNumVertices(const VertexBuffer *buffer)
   129 {
   130     return buffer->vertexCount;
   131 }
   132 
   133 /*!
   134  * \internal
   135  * \brief Returns the current array mask for this buffer
   136  */
   137 static M3G_INLINE M3Gbitmask m3gGetArrayMask(const VertexBuffer *buffer)
   138 {
   139     return buffer->arrayMask;
   140 }
   141 
   142 #endif /*__M3G_VERTEXBUFFER_H__*/