michael@0: // michael@0: // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // VertexBuffer9.h: Defines the D3D9 VertexBuffer implementation. michael@0: michael@0: #ifndef LIBGLESV2_RENDERER_VERTEXBUFFER9_H_ michael@0: #define LIBGLESV2_RENDERER_VERTEXBUFFER9_H_ michael@0: michael@0: #include "libGLESv2/renderer/VertexBuffer.h" michael@0: michael@0: namespace rx michael@0: { michael@0: class Renderer9; michael@0: michael@0: class VertexBuffer9 : public VertexBuffer michael@0: { michael@0: public: michael@0: explicit VertexBuffer9(rx::Renderer9 *const renderer); michael@0: virtual ~VertexBuffer9(); michael@0: michael@0: virtual bool initialize(unsigned int size, bool dynamicUsage); michael@0: michael@0: static VertexBuffer9 *makeVertexBuffer9(VertexBuffer *vertexBuffer); michael@0: michael@0: virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances, michael@0: unsigned int offset); michael@0: virtual bool storeRawData(const void* data, unsigned int size, unsigned int offset); michael@0: michael@0: virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, unsigned int *outSpaceRequired) const; michael@0: michael@0: virtual bool requiresConversion(const gl::VertexAttribute &attrib) const; michael@0: michael@0: unsigned int getVertexSize(const gl::VertexAttribute &attrib) const; michael@0: D3DDECLTYPE getDeclType(const gl::VertexAttribute &attrib) const; michael@0: michael@0: virtual unsigned int getBufferSize() const; michael@0: virtual bool setBufferSize(unsigned int size); michael@0: virtual bool discard(); michael@0: michael@0: IDirect3DVertexBuffer9 *getBuffer() const; michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(VertexBuffer9); michael@0: michael@0: rx::Renderer9 *const mRenderer; michael@0: michael@0: IDirect3DVertexBuffer9 *mVertexBuffer; michael@0: unsigned int mBufferSize; michael@0: bool mDynamicUsage; michael@0: michael@0: // Attribute format conversion michael@0: enum { NUM_GL_VERTEX_ATTRIB_TYPES = 6 }; michael@0: michael@0: struct FormatConverter michael@0: { michael@0: bool identity; michael@0: std::size_t outputElementSize; michael@0: void (*convertArray)(const void *in, std::size_t stride, std::size_t n, void *out); michael@0: D3DDECLTYPE d3dDeclType; michael@0: }; michael@0: michael@0: static bool mTranslationsInitialized; michael@0: static void initializeTranslations(DWORD declTypes); michael@0: michael@0: // [GL types as enumerated by typeIndex()][normalized][size - 1] michael@0: static FormatConverter mFormatConverters[NUM_GL_VERTEX_ATTRIB_TYPES][2][4]; michael@0: michael@0: struct TranslationDescription michael@0: { michael@0: DWORD capsFlag; michael@0: FormatConverter preferredConversion; michael@0: FormatConverter fallbackConversion; michael@0: }; michael@0: michael@0: // This table is used to generate mFormatConverters. michael@0: // [GL types as enumerated by typeIndex()][normalized][size - 1] michael@0: static const TranslationDescription mPossibleTranslations[NUM_GL_VERTEX_ATTRIB_TYPES][2][4]; michael@0: michael@0: static unsigned int typeIndex(GLenum type); michael@0: static const FormatConverter &formatConverter(const gl::VertexAttribute &attribute); michael@0: michael@0: static bool spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances, michael@0: unsigned int *outSpaceRequired); michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif // LIBGLESV2_RENDERER_VERTEXBUFFER9_H_