From 4db24ae39a6ad981c39a71b8af4aa56ac8179b08 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 1 Apr 2013 17:38:46 -0400 Subject: [PATCH] update all uses of VertexBuffer, IndexBuffer and VERTEX_ATTRIBS to compile and run under the new changes --- .../assets/animation/keyframemesh.cpp | 17 ++++--- .../assets/animation/skeletalmeshfile.cpp | 17 ++++--- .../assets/animation/skeletalmeshsubset.cpp | 3 +- .../assets/static/staticmeshsubset.cpp | 13 +++-- .../graphics/billboardspritebatch.cpp | 13 +++-- src/framework/graphics/debugshader.cpp | 4 +- .../graphics/geometrydebugrenderer.cpp | 11 +++-- src/framework/graphics/graphicsdevice.cpp | 2 +- src/framework/graphics/shader.cpp | 2 +- src/framework/graphics/shader.h | 6 +-- src/framework/graphics/shaderstructs.h | 2 +- src/framework/graphics/simplecolorshader.cpp | 4 +- .../graphics/simplecolortextureshader.cpp | 6 +-- .../graphics/simpletextureshader.cpp | 4 +- .../simpletexturevertexlerpshader.cpp | 2 +- .../simpletexturevertexskinningshader.cpp | 4 +- src/framework/graphics/sprite2dshader.cpp | 6 +-- src/framework/graphics/sprite3dshader.cpp | 6 +-- src/framework/graphics/spritebatch.cpp | 13 +++-- src/framework/support/grid.cpp | 47 ++++--------------- src/tilemap/cubetilemesh.cpp | 15 +++--- src/tilemap/statictilemesh.cpp | 15 ++++-- src/tilemap/tilechunk.cpp | 30 +++++++----- 23 files changed, 124 insertions(+), 118 deletions(-) diff --git a/src/framework/assets/animation/keyframemesh.cpp b/src/framework/assets/animation/keyframemesh.cpp index 32db08b..55909cd 100644 --- a/src/framework/assets/animation/keyframemesh.cpp +++ b/src/framework/assets/animation/keyframemesh.cpp @@ -53,14 +53,17 @@ KeyframeMesh::KeyframeMesh(const KeyframeMeshFile *file) m_numVerticesPerFrame = file->GetNumVerticesPerFrame(); - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STREAM); + VERTEX_ATTRIBS attribs[] = { + VERTEX_V3, // position for frame 1 + VERTEX_V3, // position for frame 2 + VERTEX_V3, // normal for frame 1 + VERTEX_V3, // normal for frame 2 + VERTEX_TEXCOORD + }; + + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->AddAttribute(ATTRIB_SIZE_VEC3); // position for frame 1 - m_vertices->AddAttribute(ATTRIB_SIZE_VEC3); // position for frame 2 - m_vertices->AddAttribute(ATTRIB_SIZE_VEC3); // normal for frame 1 - m_vertices->AddAttribute(ATTRIB_SIZE_VEC3); // normal for frame 2 - m_vertices->AddAttribute(VERTEX_TEXCOORD); - m_vertices->Create(m_numVerticesPerFrame); + m_vertices->Initialize(attribs, 5, m_numVerticesPerFrame, BUFFEROBJECT_USAGE_STREAM); } KeyframeMesh::~KeyframeMesh() diff --git a/src/framework/assets/animation/skeletalmeshfile.cpp b/src/framework/assets/animation/skeletalmeshfile.cpp index 130e368..2be359e 100644 --- a/src/framework/assets/animation/skeletalmeshfile.cpp +++ b/src/framework/assets/animation/skeletalmeshfile.cpp @@ -15,6 +15,7 @@ #include "../../math/vector3.h" #include "../../support/animationsequence.h" #include +#include SkeletalMeshFile::SkeletalMeshFile(File *file) : MeshFile(file) @@ -56,14 +57,18 @@ SkeletalMesh* SkeletalMeshFile::CreateMesh() file->Seek(verticesDesc->start, FILESEEK_BEGINNING); mesh->m_numVertices = file->ReadUnsignedInt(); - mesh->m_vertexBuffer = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); - mesh->m_vertexBuffer->AddAttribute(ATTRIB_SIZE_1F); - mesh->m_vertexBuffer->AddAttribute(VERTEX_POS_3D); + // lol, lazy way out + stl::vector attribs; + attribs.reserve(4); + attribs.push_back(VERTEX_F1); + attribs.push_back(VERTEX_POS_3D); if (hasNormals) - mesh->m_vertexBuffer->AddAttribute(VERTEX_NORMAL); + attribs.push_back(VERTEX_NORMAL); if (hasTexCoords) - mesh->m_vertexBuffer->AddAttribute(VERTEX_TEXCOORD); - mesh->m_vertexBuffer->Create(mesh->m_numVertices); + attribs.push_back(VERTEX_TEXCOORD); + + mesh->m_vertexBuffer = new VertexBuffer(); + mesh->m_vertexBuffer->Initialize(&attribs[0], attribs.size(), mesh->m_numVertices, BUFFEROBJECT_USAGE_STATIC); // read vertices mesh->m_vertices = new Vector3[mesh->m_numVertices]; diff --git a/src/framework/assets/animation/skeletalmeshsubset.cpp b/src/framework/assets/animation/skeletalmeshsubset.cpp index 01fa1c5..1d16841 100644 --- a/src/framework/assets/animation/skeletalmeshsubset.cpp +++ b/src/framework/assets/animation/skeletalmeshsubset.cpp @@ -24,6 +24,7 @@ void SkeletalMeshSubset::Create(const stl::string &name, uint32_t numTriangles, ASSERT(m_indices == NULL); ASSERT(numTriangles > 0); m_name = name; - m_indices = new IndexBuffer(numTriangles * 3, TRUE); + m_indices = new IndexBuffer(); + m_indices->Initialize(numTriangles * 3, BUFFEROBJECT_USAGE_STATIC); m_alpha = alpha; } diff --git a/src/framework/assets/static/staticmeshsubset.cpp b/src/framework/assets/static/staticmeshsubset.cpp index fb0ceb8..2e1c19a 100644 --- a/src/framework/assets/static/staticmeshsubset.cpp +++ b/src/framework/assets/static/staticmeshsubset.cpp @@ -8,12 +8,15 @@ StaticMeshSubset::StaticMeshSubset(uint32_t numTriangles, Texture *texture) { STACK_TRACE; - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_3D, + VERTEX_NORMAL, + VERTEX_TEXCOORD + }; + + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->AddAttribute(VERTEX_POS_3D); - m_vertices->AddAttribute(VERTEX_NORMAL); - m_vertices->AddAttribute(VERTEX_TEXCOORD); - m_vertices->Create(numTriangles * 3); + m_vertices->Initialize(attribs, 3, numTriangles * 3, BUFFEROBJECT_USAGE_STATIC); m_texture = texture; } diff --git a/src/framework/graphics/billboardspritebatch.cpp b/src/framework/graphics/billboardspritebatch.cpp index 66c7d37..920cbdb 100644 --- a/src/framework/graphics/billboardspritebatch.cpp +++ b/src/framework/graphics/billboardspritebatch.cpp @@ -35,14 +35,17 @@ BillboardSpriteBatch::BillboardSpriteBatch(GraphicsDevice *graphicsDevice) // TODO: default size of 1 is best? m_currentSpriteCapacity = 1; m_currentSpritePointer = 0; + + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_3D, + VERTEX_COLOR, + VERTEX_TEXCOORD + }; // size vertices and texture storage to match m_currentSpriteCapacity - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STREAM); + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->AddAttribute(VERTEX_POS_3D); - m_vertices->AddAttribute(VERTEX_COLOR); - m_vertices->AddAttribute(VERTEX_TEXCOORD); - m_vertices->Create(m_currentSpriteCapacity * VERTICES_PER_SPRITE); + m_vertices->Initialize(attribs, 3, m_currentSpriteCapacity * VERTICES_PER_SPRITE, BUFFEROBJECT_USAGE_STREAM); m_textures.resize(m_currentSpriteCapacity); diff --git a/src/framework/graphics/debugshader.cpp b/src/framework/graphics/debugshader.cpp index cbd1a53..475d0ff 100644 --- a/src/framework/graphics/debugshader.cpp +++ b/src/framework/graphics/debugshader.cpp @@ -37,8 +37,8 @@ DebugShader::DebugShader() BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); ASSERT(result == TRUE); - MapAttributeToStandardAttribType("a_position", VERTEX_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_COLOR); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); } DebugShader::~DebugShader() diff --git a/src/framework/graphics/geometrydebugrenderer.cpp b/src/framework/graphics/geometrydebugrenderer.cpp index 3462b58..7393772 100644 --- a/src/framework/graphics/geometrydebugrenderer.cpp +++ b/src/framework/graphics/geometrydebugrenderer.cpp @@ -27,12 +27,15 @@ GeometryDebugRenderer::GeometryDebugRenderer(GraphicsDevice *graphicsDevice, BOO ASSERT(m_renderState != NULL); m_renderState->SetDepthTesting(depthTesting); m_renderState->SetLineWidth(2.0f); + + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_3D, + VERTEX_COLOR + }; - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STREAM); + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->AddAttribute(VERTEX_POS_3D); - m_vertices->AddAttribute(VERTEX_COLOR); - m_vertices->Create(16384); + m_vertices->Initialize(attribs, 2, 16384, BUFFEROBJECT_USAGE_STREAM); m_currentVertex = 0; m_begunRendering = FALSE; diff --git a/src/framework/graphics/graphicsdevice.cpp b/src/framework/graphics/graphicsdevice.cpp index 5a802b7..81bcd77 100644 --- a/src/framework/graphics/graphicsdevice.cpp +++ b/src/framework/graphics/graphicsdevice.cpp @@ -492,7 +492,7 @@ void GraphicsDevice::SetShaderVertexAttributes() int32_t bufferAttribIndex = 0; if (m_boundShader->IsAttributeMappedToStandardType(i)) { - VERTEX_ATTRIBS standardType = m_boundShader->GetAttributeMappedStandardType(i); + VERTEX_STANDARD_ATTRIBS standardType = m_boundShader->GetAttributeMappedStandardType(i); bufferAttribIndex = m_boundVertexBuffer->GetIndexOfStandardAttrib(standardType); ASSERT(bufferAttribIndex != -1); if (bufferAttribIndex == -1) diff --git a/src/framework/graphics/shader.cpp b/src/framework/graphics/shader.cpp index c0dfb73..f970e0e 100644 --- a/src/framework/graphics/shader.cpp +++ b/src/framework/graphics/shader.cpp @@ -1053,7 +1053,7 @@ void Shader::MapAttributeToVboAttribIndex(const stl::string &name, uint32_t vboA attribute->isTypeBound = TRUE; } -void Shader::MapAttributeToStandardAttribType(const stl::string &name, VERTEX_ATTRIBS standardAttribType) +void Shader::MapAttributeToStandardAttribType(const stl::string &name, VERTEX_STANDARD_ATTRIBS standardAttribType) { STACK_TRACE; ShaderAttribute *attribute = GetAttribute(name); diff --git a/src/framework/graphics/shader.h b/src/framework/graphics/shader.h index 4ebae91..6b06767 100644 --- a/src/framework/graphics/shader.h +++ b/src/framework/graphics/shader.h @@ -237,7 +237,7 @@ public: * @return the standard attribute type mapping associated with this * shader attribute */ - VERTEX_ATTRIBS GetAttributeMappedStandardType(uint32_t attribIndex) const; + VERTEX_STANDARD_ATTRIBS GetAttributeMappedStandardType(uint32_t attribIndex) const; /** * Maps the given shader attribute to an index that will be used to refer @@ -260,7 +260,7 @@ public: * @param standardAttribType the standard type to map this shader attribute * to in bound vertex buffer objects */ - void MapAttributeToStandardAttribType(const stl::string &name, VERTEX_ATTRIBS standardAttribType); + void MapAttributeToStandardAttribType(const stl::string &name, VERTEX_STANDARD_ATTRIBS standardAttribType); /** * New OpenGL graphics context creation callback. @@ -388,7 +388,7 @@ inline uint32_t Shader::GetAttributeMappedBufferIndex(uint32_t attribIndex) cons return m_attributeMapping[attribIndex].attribIndex; } -inline VERTEX_ATTRIBS Shader::GetAttributeMappedStandardType(uint32_t attribIndex) const +inline VERTEX_STANDARD_ATTRIBS Shader::GetAttributeMappedStandardType(uint32_t attribIndex) const { return m_attributeMapping[attribIndex].standardType; } diff --git a/src/framework/graphics/shaderstructs.h b/src/framework/graphics/shaderstructs.h index 2c3cfb3..9fafc58 100644 --- a/src/framework/graphics/shaderstructs.h +++ b/src/framework/graphics/shaderstructs.h @@ -34,7 +34,7 @@ struct ShaderAttribute struct ShaderAttributeMapInfo { BOOL usesStandardType; - VERTEX_ATTRIBS standardType; + VERTEX_STANDARD_ATTRIBS standardType; uint32_t attribIndex; }; diff --git a/src/framework/graphics/simplecolorshader.cpp b/src/framework/graphics/simplecolorshader.cpp index d37cb18..984b1d8 100644 --- a/src/framework/graphics/simplecolorshader.cpp +++ b/src/framework/graphics/simplecolorshader.cpp @@ -36,8 +36,8 @@ SimpleColorShader::SimpleColorShader() BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); ASSERT(result == TRUE); - MapAttributeToStandardAttribType("a_position", VERTEX_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_COLOR); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); } SimpleColorShader::~SimpleColorShader() diff --git a/src/framework/graphics/simplecolortextureshader.cpp b/src/framework/graphics/simplecolortextureshader.cpp index 512ef38..581bf27 100644 --- a/src/framework/graphics/simplecolortextureshader.cpp +++ b/src/framework/graphics/simplecolortextureshader.cpp @@ -41,9 +41,9 @@ SimpleColorTextureShader::SimpleColorTextureShader() BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); ASSERT(result == TRUE); - MapAttributeToStandardAttribType("a_position", VERTEX_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_COLOR); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_TEXCOORD); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleColorTextureShader::~SimpleColorTextureShader() diff --git a/src/framework/graphics/simpletextureshader.cpp b/src/framework/graphics/simpletextureshader.cpp index c85bfe4..9389077 100644 --- a/src/framework/graphics/simpletextureshader.cpp +++ b/src/framework/graphics/simpletextureshader.cpp @@ -35,8 +35,8 @@ SimpleTextureShader::SimpleTextureShader() BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); ASSERT(result == TRUE); - MapAttributeToStandardAttribType("a_position", VERTEX_POS_3D); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_TEXCOORD); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleTextureShader::~SimpleTextureShader() diff --git a/src/framework/graphics/simpletexturevertexlerpshader.cpp b/src/framework/graphics/simpletexturevertexlerpshader.cpp index a64ebcf..79d9930 100644 --- a/src/framework/graphics/simpletexturevertexlerpshader.cpp +++ b/src/framework/graphics/simpletexturevertexlerpshader.cpp @@ -39,7 +39,7 @@ SimpleTextureVertexLerpShader::SimpleTextureVertexLerpShader() MapAttributeToVboAttribIndex("a_position1", 0); MapAttributeToVboAttribIndex("a_position2", 1); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_TEXCOORD); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleTextureVertexLerpShader::~SimpleTextureVertexLerpShader() diff --git a/src/framework/graphics/simpletexturevertexskinningshader.cpp b/src/framework/graphics/simpletexturevertexskinningshader.cpp index 20a07fc..ca3a4d0 100644 --- a/src/framework/graphics/simpletexturevertexskinningshader.cpp +++ b/src/framework/graphics/simpletexturevertexskinningshader.cpp @@ -56,8 +56,8 @@ SimpleTextureVertexSkinningShader::SimpleTextureVertexSkinningShader() ASSERT(result == TRUE); MapAttributeToVboAttribIndex("a_jointIndex", 0); - MapAttributeToStandardAttribType("a_position", VERTEX_POS_3D); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_TEXCOORD); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } SimpleTextureVertexSkinningShader::~SimpleTextureVertexSkinningShader() diff --git a/src/framework/graphics/sprite2dshader.cpp b/src/framework/graphics/sprite2dshader.cpp index 2794391..bfb439f 100644 --- a/src/framework/graphics/sprite2dshader.cpp +++ b/src/framework/graphics/sprite2dshader.cpp @@ -47,9 +47,9 @@ Sprite2DShader::Sprite2DShader() BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); ASSERT(result == TRUE); - MapAttributeToStandardAttribType("a_position", VERTEX_POS_2D); - MapAttributeToStandardAttribType("a_color", VERTEX_COLOR); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_TEXCOORD); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_2D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } Sprite2DShader::~Sprite2DShader() diff --git a/src/framework/graphics/sprite3dshader.cpp b/src/framework/graphics/sprite3dshader.cpp index 2daed25..c383cca 100644 --- a/src/framework/graphics/sprite3dshader.cpp +++ b/src/framework/graphics/sprite3dshader.cpp @@ -53,9 +53,9 @@ Sprite3DShader::Sprite3DShader() BOOL result = LoadCompileAndLinkInlineSources(m_vertexShaderSource, m_fragmentShaderSource); ASSERT(result == TRUE); - MapAttributeToStandardAttribType("a_position", VERTEX_POS_3D); - MapAttributeToStandardAttribType("a_color", VERTEX_COLOR); - MapAttributeToStandardAttribType("a_texcoord0", VERTEX_TEXCOORD); + MapAttributeToStandardAttribType("a_position", VERTEX_STD_POS_3D); + MapAttributeToStandardAttribType("a_color", VERTEX_STD_COLOR); + MapAttributeToStandardAttribType("a_texcoord0", VERTEX_STD_TEXCOORD); } Sprite3DShader::~Sprite3DShader() diff --git a/src/framework/graphics/spritebatch.cpp b/src/framework/graphics/spritebatch.cpp index 0df5256..bf28cc4 100644 --- a/src/framework/graphics/spritebatch.cpp +++ b/src/framework/graphics/spritebatch.cpp @@ -34,16 +34,19 @@ SpriteBatch::SpriteBatch(GraphicsDevice *graphicsDevice) // TODO: default size of 1 is best? m_currentSpritePointer = 0; + + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_2D, + VERTEX_COLOR, + VERTEX_TEXCOORD + }; // size vertices and texture storage to match m_currentSpriteCapacity // HACK: we initialize the buffer to have a size of "1" simply because we // can't use a size of 0 with the current VertexBuffer implementation - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STREAM); + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->AddAttribute(VERTEX_POS_2D); - m_vertices->AddAttribute(VERTEX_COLOR); - m_vertices->AddAttribute(VERTEX_TEXCOORD); - m_vertices->Create(1); + m_vertices->Initialize(attribs, 3, 1, BUFFEROBJECT_USAGE_STREAM); m_entities.reserve(1); diff --git a/src/framework/support/grid.cpp b/src/framework/support/grid.cpp index 780dc1a..fa1fdf4 100644 --- a/src/framework/support/grid.cpp +++ b/src/framework/support/grid.cpp @@ -13,22 +13,19 @@ Grid::Grid(GraphicsDevice *graphicsDevice, uint16_t width, uint16_t height) m_renderState = new RENDERSTATE_DEFAULT; ASSERT(m_renderState != NULL); + + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_3D, + VERTEX_COLOR, + }; - m_horizontalPoints = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + m_horizontalPoints = new VertexBuffer(); ASSERT(m_horizontalPoints != NULL); - m_horizontalPoints->AddAttribute(VERTEX_POS_3D); - m_horizontalPoints->AddAttribute(VERTEX_COLOR); - m_horizontalPoints->AddAttribute(ATTRIB_SIZE_1F); - m_horizontalPoints->AddAttribute(ATTRIB_SIZE_1F); - m_horizontalPoints->Create(width * 2 + 2); + m_horizontalPoints->Initialize(attribs, 2, width * 2 + 2, BUFFEROBJECT_USAGE_STATIC); - m_verticalPoints = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + m_verticalPoints = new VertexBuffer(); ASSERT(m_verticalPoints != NULL); - m_verticalPoints->AddAttribute(VERTEX_POS_3D); - m_verticalPoints->AddAttribute(VERTEX_COLOR); - m_verticalPoints->AddAttribute(ATTRIB_SIZE_1F); - m_verticalPoints->AddAttribute(ATTRIB_SIZE_1F); - m_verticalPoints->Create(height * 2 + 2); + m_verticalPoints->Initialize(attribs, 2, height * 2 + 2, BUFFEROBJECT_USAGE_STATIC); for (uint16_t i = 0; i < height + 1; ++i) { @@ -36,19 +33,6 @@ Grid::Grid(GraphicsDevice *graphicsDevice, uint16_t width, uint16_t height) m_horizontalPoints->SetColor((i * 2), 1.0f, 1.0f, 1.0f); m_horizontalPoints->SetPosition3((i * 2) + 1, width / 2.0f, 0.0f, i - (height / 2.0f)); m_horizontalPoints->SetColor((i * 2) + 1, 1.0f, 1.0f, 1.0f); - - if (i == 8) - { - m_horizontalPoints->Set1f(3, (i * 2), 1.0f); - m_horizontalPoints->Set1f(3, (i * 2) + 1, 1.0f); - } - else - { - m_horizontalPoints->Set1f(3, (i * 2), 0.0f); - m_horizontalPoints->Set1f(3, (i * 2) + 1, 0.0f); - } - m_horizontalPoints->Set1f(2, (i * 2), 2.0f); - m_horizontalPoints->Set1f(2, (i * 2) + 1, 3.0f); } for (uint16_t i = 0; i < width + 1; ++i) @@ -57,19 +41,6 @@ Grid::Grid(GraphicsDevice *graphicsDevice, uint16_t width, uint16_t height) m_verticalPoints->SetColor((i * 2), 1.0f, 1.0f, 1.0f); m_verticalPoints->SetPosition3((i * 2) + 1, i - (width / 2.0f), 0.0f, height / 2.0f); m_verticalPoints->SetColor((i * 2) + 1, 1.0f, 1.0f, 1.0f); - - if (i == 1) - { - m_verticalPoints->Set1f(3, (i * 2), 1.0f); - m_verticalPoints->Set1f(3, (i * 2) + 1, 1.0f); - } - else - { - m_verticalPoints->Set1f(3, (i * 2), 0.0f); - m_verticalPoints->Set1f(3, (i * 2) + 1, 0.0f); - } - m_verticalPoints->Set1f(2, (i * 2), 0.0f); - m_verticalPoints->Set1f(2, (i * 2) + 1, 0.0f); } } diff --git a/src/tilemap/cubetilemesh.cpp b/src/tilemap/cubetilemesh.cpp index 6177890..69f0de6 100644 --- a/src/tilemap/cubetilemesh.cpp +++ b/src/tilemap/cubetilemesh.cpp @@ -59,14 +59,17 @@ CubeTileMesh::CubeTileMesh(CUBE_FACES faces, const RectF *textureAtlasTileBounda m_rightFaceVertexOffset = numVertices; numVertices += CUBE_VERTICES_PER_FACE; } + + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_3D, + VERTEX_NORMAL, + VERTEX_COLOR, + VERTEX_TEXCOORD + }; - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->AddAttribute(VERTEX_POS_3D); - m_vertices->AddAttribute(VERTEX_NORMAL); - m_vertices->AddAttribute(VERTEX_COLOR); - m_vertices->AddAttribute(VERTEX_TEXCOORD); - m_vertices->Create(numVertices); + m_vertices->Initialize(attribs, 4, numVertices, BUFFEROBJECT_USAGE_STATIC); SetupFaceVertices(textureAtlasTileBoundaries); SetupCollisionVertices(); diff --git a/src/tilemap/statictilemesh.cpp b/src/tilemap/statictilemesh.cpp index 3220113..66704de 100644 --- a/src/tilemap/statictilemesh.cpp +++ b/src/tilemap/statictilemesh.cpp @@ -14,9 +14,9 @@ StaticTileMesh::StaticTileMesh(const StaticMesh *mesh, const RectF *textureAtlas StaticMeshSubset *subset = mesh->GetSubset(0); // copy the source buffer - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->CreateCopyOf(subset->GetVertices()); + m_vertices->Initialize(subset->GetVertices()); SetOpaque(opaqueSides); SetAlpha(alpha); @@ -48,12 +48,17 @@ StaticTileMesh::StaticTileMesh(const StaticMesh *mesh, const RectF *textureAtlas for (uint32_t i = 0; i < numTiles; ++i) numVertices += mesh->GetSubset(i)->GetVertices()->GetNumElements(); + // create a copy of the mesh's vertex attributes as an array + const VertexBuffer *meshVertices = mesh->GetSubset(0)->GetVertices(); + VERTEX_ATTRIBS *attribs = new VERTEX_ATTRIBS[meshVertices->GetNumAttributes()]; + for (uint32_t i = 0; i < meshVertices->GetNumAttributes(); ++i) + attribs[i] = meshVertices->GetAttributeInfo(i)->standardType; + // create the vertex buffer using the same attribs as the source mesh // (assuming all subsets have the same attribs in the mesh) - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->CopyAttributesFrom(mesh->GetSubset(0)->GetVertices()); - m_vertices->Create(numVertices); + m_vertices->Initialize(attribs, meshVertices->GetNumAttributes(), numVertices, BUFFEROBJECT_USAGE_STATIC); SetOpaque(opaqueSides); SetAlpha(alpha); diff --git a/src/tilemap/tilechunk.cpp b/src/tilemap/tilechunk.cpp index ab54ae5..344bca0 100644 --- a/src/tilemap/tilechunk.cpp +++ b/src/tilemap/tilechunk.cpp @@ -38,15 +38,18 @@ TileChunk::TileChunk(uint32_t x, uint32_t y, uint32_t z, uint32_t width, uint32_ m_data = new Tile[width * height * depth]; ASSERT(m_data != NULL); + + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_3D, + VERTEX_NORMAL, + VERTEX_TEXCOORD, + VERTEX_COLOR + }; // TODO: is 16 a good starting default size? - m_vertices = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + m_vertices = new VertexBuffer(); ASSERT(m_vertices != NULL); - m_vertices->AddAttribute(VERTEX_POS_3D); - m_vertices->AddAttribute(VERTEX_NORMAL); - m_vertices->AddAttribute(VERTEX_TEXCOORD); - m_vertices->AddAttribute(VERTEX_COLOR); - m_vertices->Create(16); + m_vertices->Initialize(attribs, 4, 16, BUFFEROBJECT_USAGE_STATIC); m_numVertices = 0; // start off assuming we don't have any alpha vertices @@ -377,17 +380,20 @@ void TileChunk::EnableAlphaVertices(BOOL enable) { if (m_alphaVertices != NULL) return; + + VERTEX_ATTRIBS attribs[] = { + VERTEX_POS_3D, + VERTEX_NORMAL, + VERTEX_TEXCOORD, + VERTEX_COLOR + }; // need to create the vertex buffer // TODO: is '16' a good default size? it probably isn't likely that // chunks will have a lot of these. has to be non-zero anyway... - m_alphaVertices = new VertexBuffer(BUFFEROBJECT_USAGE_STATIC); + m_alphaVertices = new VertexBuffer(); ASSERT(m_alphaVertices != NULL); - m_alphaVertices->AddAttribute(VERTEX_POS_3D); - m_alphaVertices->AddAttribute(VERTEX_NORMAL); - m_alphaVertices->AddAttribute(VERTEX_TEXCOORD); - m_alphaVertices->AddAttribute(VERTEX_COLOR); - m_alphaVertices->Create(16); + m_alphaVertices->Initialize(attribs, 4, 16, BUFFEROBJECT_USAGE_STATIC); m_numAlphaVertices = 0; } else