os/graphics/m3g/m3gcore11/inc/m3g_vertexbuffer.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/m3g/m3gcore11/inc/m3g_vertexbuffer.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,142 @@
     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: VertexBuffer interface
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#ifndef __M3G_VERTEXBUFFER_H__
    1.22 +#define __M3G_VERTEXBUFFER_H__
    1.23 +
    1.24 +/*!
    1.25 + * \internal
    1.26 + * \file
    1.27 + * \brief VertexBuffer interface
    1.28 + */
    1.29 +
    1.30 +#include "m3g_object.h"
    1.31 +#include "m3g_vertexarray.h"
    1.32 +
    1.33 +/*!
    1.34 + * \internal
    1.35 + * \brief \c VertexBuffer object instance
    1.36 + */
    1.37 +struct M3GVertexBufferImpl
    1.38 +{
    1.39 +    Object object;
    1.40 +
    1.41 +    /*@dependent@*/
    1.42 +    VertexArray *colors;
    1.43 +    /*@dependent@*/
    1.44 +    VertexArray *normals;
    1.45 +    VertexArray *texCoords[M3G_NUM_TEXTURE_UNITS];
    1.46 +    /*@dependent@*/
    1.47 +    VertexArray *vertices;
    1.48 +
    1.49 +    GLfloat texCoordScale[M3G_NUM_TEXTURE_UNITS];
    1.50 +    GLfloat texCoordBias[M3G_NUM_TEXTURE_UNITS][3];
    1.51 +
    1.52 +    GLfloat vertexScale;
    1.53 +    GLfloat vertexBias[3];
    1.54 +
    1.55 +    /*! \internal \brief Default vertex color */
    1.56 +    struct { GLubyte r, g, b, a; } defaultColor;
    1.57 +    
    1.58 +    M3Gbool locked;
    1.59 +    M3Gint vertexCount;
    1.60 +    M3Gint arrayCount;
    1.61 +    M3Gbitmask arrayMask;
    1.62 +    M3Gint timestamp;
    1.63 +    M3Gint verticesTimestamp;
    1.64 +    
    1.65 +    AABB bbox;
    1.66 +};
    1.67 +
    1.68 +/*! \brief vertex component mask bits */
    1.69 +#define M3G_POSITION_BIT        0x01u
    1.70 +#define M3G_COLOR_BIT           0x02u
    1.71 +#define M3G_NORMAL_BIT          0x04u
    1.72 +
    1.73 +#define M3G_TEXCOORD0_BIT       0x10u
    1.74 +#define M3G_TEXCOORD1_BIT       0x20u
    1.75 +#define M3G_TEXCOORD2_BIT       0x40u
    1.76 +#define M3G_TEXCOORD3_BIT       0x80u
    1.77 +
    1.78 +/*----------------------------------------------------------------------
    1.79 + * Internal functions
    1.80 + *--------------------------------------------------------------------*/
    1.81 +
    1.82 +static void m3gApplyScaleAndBias(const VertexBuffer *buffer);
    1.83 +static void m3gLockVertexBuffer(const VertexBuffer *buffer, M3Gint alphaFactor);
    1.84 +static void m3gReleaseVertexBuffer(const VertexBuffer *buffer);
    1.85 +
    1.86 +static M3Gbool m3gGetVertex(const VertexBuffer *buffer, M3Gint idx, Vec3 *v);
    1.87 +static M3Gbool m3gGetNormal(const VertexBuffer *buffer, M3Gint idx, Vec3 *v);
    1.88 +static M3Gbool m3gGetTexCoord(const VertexBuffer *buffer, M3Gint idx, int unit, Vec3 *v);
    1.89 +
    1.90 +static M3Gint m3gGetTimestamp(const VertexBuffer *buffer);
    1.91 +static M3Gint m3gGetNumVertices(const VertexBuffer *buffer);
    1.92 +static M3Gbitmask m3gGetArrayMask(const VertexBuffer *buffer);
    1.93 +
    1.94 +static M3Gbool m3gValidateVertexBuffer(const VertexBuffer *vb,
    1.95 +                                       const Appearance *app,
    1.96 +                                       M3Gsizei maxIndex);
    1.97 +static void m3gGetBoundingBox(VertexBuffer *buffer, AABB *boundingBox);
    1.98 +
    1.99 +static M3Gbool m3gMakeModifiedVertexBuffer(VertexBuffer *buffer,
   1.100 +                                           const VertexBuffer *srcBuffer,
   1.101 +                                           M3Gbitmask arrayMask,
   1.102 +                                           M3Gbool createArrays);
   1.103 +
   1.104 +
   1.105 +/* -------- Inline functions -------- */
   1.106 +
   1.107 +/*!
   1.108 + * \internal
   1.109 + * \brief Queries whether a vertex buffer can be (safely) bound with
   1.110 + * memory locking in effect
   1.111 + */
   1.112 +static M3G_INLINE M3Gbool m3gValidateAlphaCache(const VertexBuffer *buffer) 
   1.113 +{
   1.114 +    const VertexArray *colArray = buffer->colors;
   1.115 +    return colArray ? (colArray->cachedColors != 0) : M3G_TRUE;
   1.116 +}
   1.117 +
   1.118 +/*!
   1.119 + * \internal
   1.120 + * \brief Type-safe helper function
   1.121 + */
   1.122 +static M3G_INLINE void m3gDeleteVertexBuffer(VertexBuffer *buffer)
   1.123 +{
   1.124 +    m3gDeleteObject((Object *) buffer);
   1.125 +}
   1.126 +
   1.127 +/*!
   1.128 + * \internal
   1.129 + * \brief Gets number of vertices in this buffer.
   1.130 + */
   1.131 +static M3G_INLINE M3Gint m3gGetNumVertices(const VertexBuffer *buffer)
   1.132 +{
   1.133 +    return buffer->vertexCount;
   1.134 +}
   1.135 +
   1.136 +/*!
   1.137 + * \internal
   1.138 + * \brief Returns the current array mask for this buffer
   1.139 + */
   1.140 +static M3G_INLINE M3Gbitmask m3gGetArrayMask(const VertexBuffer *buffer)
   1.141 +{
   1.142 +    return buffer->arrayMask;
   1.143 +}
   1.144 +
   1.145 +#endif /*__M3G_VERTEXBUFFER_H__*/