Support translating indices.

TRAC #11393 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Author: Andrew Lewycky git-svn-id: https://angleproject.googlecode.com/svn/trunk@72 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d989add5
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "utilities.h" #include "utilities.h"
#include "geometry/backend.h" #include "geometry/backend.h"
#include "geometry/VertexDataManager.h" #include "geometry/VertexDataManager.h"
#include "geometry/IndexDataManager.h"
#include "geometry/dx9.h" #include "geometry/dx9.h"
#undef near #undef near
...@@ -138,6 +139,7 @@ Context::Context(const egl::Config *config) ...@@ -138,6 +139,7 @@ Context::Context(const egl::Config *config)
mBufferBackEnd = NULL; mBufferBackEnd = NULL;
mVertexDataManager = NULL; mVertexDataManager = NULL;
mIndexDataManager = NULL;
mInvalidEnum = false; mInvalidEnum = false;
mInvalidValue = false; mInvalidValue = false;
...@@ -166,6 +168,7 @@ Context::~Context() ...@@ -166,6 +168,7 @@ Context::~Context()
delete mBufferBackEnd; delete mBufferBackEnd;
delete mVertexDataManager; delete mVertexDataManager;
delete mIndexDataManager;
while (!mBufferMap.empty()) while (!mBufferMap.empty())
{ {
...@@ -206,6 +209,7 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -206,6 +209,7 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
{ {
mBufferBackEnd = new Dx9BackEnd(device); mBufferBackEnd = new Dx9BackEnd(device);
mVertexDataManager = new VertexDataManager(this, mBufferBackEnd); mVertexDataManager = new VertexDataManager(this, mBufferBackEnd);
mIndexDataManager = new IndexDataManager(this, mBufferBackEnd);
} }
// Wrap the existing Direct3D 9 resources into GL objects and assign them to the '0' names // Wrap the existing Direct3D 9 resources into GL objects and assign them to the '0' names
...@@ -1020,50 +1024,26 @@ void Context::applyVertexBuffer(GLint first, GLsizei count) ...@@ -1020,50 +1024,26 @@ void Context::applyVertexBuffer(GLint first, GLsizei count)
lookupAttributeMapping(translated); lookupAttributeMapping(translated);
mBufferBackEnd->preDraw(translated); mBufferBackEnd->setupAttributesPreDraw(translated);
} }
void Context::applyVertexBuffer(GLsizei count, const void *indices, GLenum indexType) void Context::applyVertexBuffer(const TranslatedIndexData &indexInfo)
{ {
TranslatedAttribute translated[MAX_VERTEX_ATTRIBS]; TranslatedAttribute translated[MAX_VERTEX_ATTRIBS];
mVertexDataManager->preRenderValidate(adjustIndexPointer(indices), count, translated); mVertexDataManager->preRenderValidate(indexInfo, translated);
lookupAttributeMapping(translated); lookupAttributeMapping(translated);
mBufferBackEnd->preDraw(translated); mBufferBackEnd->setupAttributesPreDraw(translated);
} }
// Applies the indices and element array bindings to the Direct3D 9 device // Applies the indices and element array bindings to the Direct3D 9 device
void Context::applyIndexBuffer(const void *indices, GLsizei count) TranslatedIndexData Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type)
{ {
GLsizei length = count * sizeof(Index); TranslatedIndexData indexInfo = mIndexDataManager->preRenderValidate(mode, type, count, getBuffer(elementArrayBuffer), indices);
mBufferBackEnd->setupIndicesPreDraw(indexInfo);
IDirect3DDevice9 *device = getDevice(); return indexInfo;
IDirect3DIndexBuffer9 *indexBuffer = NULL;
void *data;
HRESULT result = device->CreateIndexBuffer(length, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &indexBuffer, NULL);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
return error(GL_OUT_OF_MEMORY);
}
ASSERT(SUCCEEDED(result));
if (indexBuffer)
{
indexBuffer->Lock(0, length, &data, 0);
memcpy(data, adjustIndexPointer(indices), length);
indexBuffer->Unlock();
device->SetIndices(indexBuffer);
indexBuffer->Release(); // Will only effectively be deleted when no longer in use
}
startIndex = 0;
} }
// Applies the shaders and shader constants to the Direct3D 9 device // Applies the shaders and shader constants to the Direct3D 9 device
...@@ -1480,7 +1460,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -1480,7 +1460,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
if (!cullSkipsDraw(mode)) if (!cullSkipsDraw(mode))
{ {
device->BeginScene(); device->BeginScene();
device->DrawPrimitive(primitiveType, first, primitiveCount); device->DrawPrimitive(primitiveType, 0, primitiveCount);
device->EndScene(); device->EndScene();
} }
} }
...@@ -1515,15 +1495,15 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void* ...@@ -1515,15 +1495,15 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void*
} }
applyState(); applyState();
applyVertexBuffer(count, indices, type); TranslatedIndexData indexInfo = applyIndexBuffer(indices, count, mode, type);
applyIndexBuffer(indices, count); applyVertexBuffer(indexInfo);
applyShaders(); applyShaders();
applyTextures(); applyTextures();
if (!cullSkipsDraw(mode)) if (!cullSkipsDraw(mode))
{ {
device->BeginScene(); device->BeginScene();
device->DrawIndexedPrimitive(primitiveType, 0, 0, count, startIndex, primitiveCount); device->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, indexInfo.maxIndex-indexInfo.minIndex+1, indexInfo.offset/sizeof(Index), primitiveCount);
device->EndScene(); device->EndScene();
} }
} }
......
...@@ -30,6 +30,7 @@ class Config; ...@@ -30,6 +30,7 @@ class Config;
namespace gl namespace gl
{ {
struct TranslatedAttribute; struct TranslatedAttribute;
struct TranslatedIndexData;
class Buffer; class Buffer;
class Shader; class Shader;
...@@ -43,6 +44,7 @@ class Colorbuffer; ...@@ -43,6 +44,7 @@ class Colorbuffer;
class Depthbuffer; class Depthbuffer;
class Stencilbuffer; class Stencilbuffer;
class VertexDataManager; class VertexDataManager;
class IndexDataManager;
class BufferBackEnd; class BufferBackEnd;
enum enum
...@@ -189,8 +191,6 @@ struct State ...@@ -189,8 +191,6 @@ struct State
AttributeState vertexAttribute[MAX_VERTEX_ATTRIBS]; AttributeState vertexAttribute[MAX_VERTEX_ATTRIBS];
GLuint samplerTexture[SAMPLER_TYPE_COUNT][MAX_TEXTURE_IMAGE_UNITS]; GLuint samplerTexture[SAMPLER_TYPE_COUNT][MAX_TEXTURE_IMAGE_UNITS];
unsigned int startIndex;
GLint unpackAlignment; GLint unpackAlignment;
GLint packAlignment; GLint packAlignment;
}; };
...@@ -257,8 +257,8 @@ class Context : public State ...@@ -257,8 +257,8 @@ class Context : public State
bool applyRenderTarget(bool ignoreViewport); bool applyRenderTarget(bool ignoreViewport);
void applyState(); void applyState();
void applyVertexBuffer(GLint first, GLsizei count); void applyVertexBuffer(GLint first, GLsizei count);
void applyVertexBuffer(GLsizei count, const void *indices, GLenum indexType); void applyVertexBuffer(const TranslatedIndexData &indexInfo);
void applyIndexBuffer(const void *indices, GLsizei count); TranslatedIndexData applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type);
void applyShaders(); void applyShaders();
void applyTextures(); void applyTextures();
...@@ -321,6 +321,7 @@ class Context : public State ...@@ -321,6 +321,7 @@ class Context : public State
BufferBackEnd *mBufferBackEnd; BufferBackEnd *mBufferBackEnd;
VertexDataManager *mVertexDataManager; VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
Texture *mIncompleteTextures[SAMPLER_TYPE_COUNT]; Texture *mIncompleteTextures[SAMPLER_TYPE_COUNT];
......
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// geometry/IndexDataManager.cpp: Defines the IndexDataManager, a class that
// runs the Buffer translation process for index buffers.
#include "geometry/IndexDataManager.h"
#include "common/debug.h"
#include "Buffer.h"
#include "geometry/backend.h"
namespace
{
enum { INITIAL_INDEX_BUFFER_SIZE = sizeof(gl::Index) * 8192 };
}
namespace gl
{
IndexDataManager::IndexDataManager(Context *context, BufferBackEnd *backend)
: mContext(context), mBackend(backend)
{
mStreamBuffer = mBackend->createIndexBuffer(INITIAL_INDEX_BUFFER_SIZE);
}
IndexDataManager::~IndexDataManager()
{
delete mStreamBuffer;
}
namespace
{
template <class InputIndexType>
void copyIndices(const InputIndexType *in, GLsizei count, Index *out, GLuint *minIndex, GLuint *maxIndex)
{
GLuint minIndexSoFar = *in;
GLuint maxIndexSoFar = *in;
for (GLsizei i = 0; i < count; i++)
{
if (minIndexSoFar > *in) minIndexSoFar = *in;
if (maxIndexSoFar < *in) maxIndexSoFar = *in;
*out++ = *in++;
}
*minIndex = minIndexSoFar;
*maxIndex = maxIndexSoFar;
}
}
TranslatedIndexData IndexDataManager::preRenderValidate(GLenum mode, GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices)
{
ASSERT(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_BYTE);
ASSERT(count > 0);
TranslatedIndexData translated;
translated.count = count;
std::size_t requiredSpace = spaceRequired(mode, type, count);
if (requiredSpace > mStreamBuffer->size())
{
std::size_t newSize = std::max(requiredSpace, 2 * mStreamBuffer->size());
TranslatedIndexBuffer *newStreamBuffer = mBackend->createIndexBuffer(newSize);
delete mStreamBuffer;
mStreamBuffer = newStreamBuffer;
}
mStreamBuffer->reserveSpace(requiredSpace);
size_t offset;
void *output = mStreamBuffer->map(requiredSpace, &offset);
translated.buffer = mStreamBuffer;
translated.offset = offset;
translated.indices = static_cast<const Index*>(output);
if (arrayElementBuffer != NULL)
{
indices = static_cast<const GLubyte*>(arrayElementBuffer->data()) + reinterpret_cast<GLsizei>(indices);
}
Index *out = static_cast<Index*>(output);
if (type == GL_UNSIGNED_SHORT)
{
const GLushort *in = static_cast<const GLushort*>(indices);
copyIndices(in, count, out, &translated.minIndex, &translated.maxIndex);
}
else
{
const GLubyte *in = static_cast<const GLubyte*>(indices);
copyIndices(in, count, out, &translated.minIndex, &translated.maxIndex);
}
mStreamBuffer->unmap();
return translated;
}
std::size_t IndexDataManager::spaceRequired(GLenum mode, GLenum type, GLsizei count)
{
return count * sizeof(Index);
}
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// geometry/IndexDataManager.h: Defines the IndexDataManager, a class that
// runs the Buffer translation process for index buffers.
#ifndef LIBGLESV2_GEOMETRY_INDEXDATAMANAGER_H_
#define LIBGLESV2_GEOMETRY_INDEXDATAMANAGER_H_
#include <bitset>
#include <cstddef>
#define GL_APICALL
#include <GLES2/gl2.h>
#include "Context.h"
namespace gl
{
class Buffer;
class BufferBackEnd;
class TranslatedIndexBuffer;
struct FormatConverter;
struct TranslatedIndexData
{
GLuint minIndex;
GLuint maxIndex;
GLuint count;
const Index *indices;
TranslatedIndexBuffer *buffer;
GLsizei offset;
};
class IndexDataManager
{
public:
IndexDataManager(Context *context, BufferBackEnd *backend);
~IndexDataManager();
TranslatedIndexData preRenderValidate(GLenum mode, GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices);
private:
std::size_t spaceRequired(GLenum mode, GLenum type, GLsizei count);
Context *mContext;
BufferBackEnd *mBackend;
TranslatedIndexBuffer *mStreamBuffer;
};
}
#endif // LIBGLESV2_GEOMETRY_INDEXDATAMANAGER_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "geometry/backend.h" #include "geometry/backend.h"
#include "geometry/IndexDataManager.h"
namespace namespace
{ {
...@@ -51,17 +52,17 @@ VertexDataManager::ArrayTranslationHelper::ArrayTranslationHelper(GLint first, G ...@@ -51,17 +52,17 @@ VertexDataManager::ArrayTranslationHelper::ArrayTranslationHelper(GLint first, G
void VertexDataManager::ArrayTranslationHelper::translate(const FormatConverter &converter, GLsizei stride, const void *source, void *dest) void VertexDataManager::ArrayTranslationHelper::translate(const FormatConverter &converter, GLsizei stride, const void *source, void *dest)
{ {
converter.convertArray(source, stride, mFirst+mCount, dest); converter.convertArray(source, stride, mCount, dest);
} }
VertexDataManager::IndexedTranslationHelper::IndexedTranslationHelper(const Index *indices, GLsizei count) VertexDataManager::IndexedTranslationHelper::IndexedTranslationHelper(const Index *indices, Index minIndex, GLsizei count)
: mIndices(indices), mCount(count) : mIndices(indices), mMinIndex(minIndex), mCount(count)
{ {
} }
void VertexDataManager::IndexedTranslationHelper::translate(const FormatConverter &converter, GLsizei stride, const void *source, void *dest) void VertexDataManager::IndexedTranslationHelper::translate(const FormatConverter &converter, GLsizei stride, const void *source, void *dest)
{ {
converter.convertIndexed(source, stride, mCount, mIndices, dest); converter.convertIndexed(source, stride, mMinIndex, mCount, mIndices, dest);
} }
std::bitset<MAX_VERTEX_ATTRIBS> VertexDataManager::activeAttribs() std::bitset<MAX_VERTEX_ATTRIBS> VertexDataManager::activeAttribs()
...@@ -85,43 +86,16 @@ GLenum VertexDataManager::preRenderValidate(GLint start, GLsizei count, ...@@ -85,43 +86,16 @@ GLenum VertexDataManager::preRenderValidate(GLint start, GLsizei count,
{ {
ArrayTranslationHelper translationHelper(start, count); ArrayTranslationHelper translationHelper(start, count);
return internalPreRenderValidate(mContext->vertexAttribute, activeAttribs(), start, start+count, &translationHelper, outAttribs); return internalPreRenderValidate(mContext->vertexAttribute, activeAttribs(), start, start+count-1, &translationHelper, outAttribs);
} }
namespace GLenum VertexDataManager::preRenderValidate(const TranslatedIndexData &indexInfo,
{
void indexRange(const Index *indices, std::size_t count, Index *minOut, Index *maxOut)
{
ASSERT(count > 0);
Index minSoFar = indices[0];
Index maxSoFar = indices[0];
for (std::size_t i = 1; i < count; i++)
{
if (indices[i] > maxSoFar) maxSoFar = indices[i];
if (indices[i] < minSoFar) minSoFar = indices[i];
}
*minOut = minSoFar;
*maxOut = maxSoFar;
}
}
GLenum VertexDataManager::preRenderValidate(const Index *indices, GLsizei count,
TranslatedAttribute *outAttribs) TranslatedAttribute *outAttribs)
{ {
Index minIndex; IndexedTranslationHelper translationHelper(indexInfo.indices, indexInfo.minIndex, indexInfo.count);
Index maxIndex;
indexRange(indices, count, &minIndex, &maxIndex); return internalPreRenderValidate(mContext->vertexAttribute, activeAttribs(), indexInfo.minIndex, indexInfo.maxIndex, &translationHelper, outAttribs);
IndexedTranslationHelper translationHelper(indices, count);
return internalPreRenderValidate(mContext->vertexAttribute, activeAttribs(), minIndex, maxIndex, &translationHelper, outAttribs);
} }
GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attribs, GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attribs,
...@@ -159,8 +133,8 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib ...@@ -159,8 +133,8 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib
translated[i].type = attribs[i].mType; translated[i].type = attribs[i].mType;
translated[i].size = attribs[i].mSize; translated[i].size = attribs[i].mSize;
translated[i].normalized = attribs[i].mNormalized; translated[i].normalized = attribs[i].mNormalized;
translated[i].offset = static_cast<std::size_t>(static_cast<const char*>(attribs[i].mPointer) - static_cast<const char*>(NULL));
translated[i].stride = interpretGlStride(attribs[i]); translated[i].stride = interpretGlStride(attribs[i]);
translated[i].offset = static_cast<std::size_t>(static_cast<const char*>(attribs[i].mPointer) - static_cast<const char*>(NULL)) + translated[i].stride * minIndex;
translated[i].buffer = mContext->getBuffer(attribs[i].mBoundBuffer)->identityBuffer(); translated[i].buffer = mContext->getBuffer(attribs[i].mBoundBuffer)->identityBuffer();
} }
else else
...@@ -173,7 +147,7 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib ...@@ -173,7 +147,7 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib
// Handle any attributes needing translation or lifting. // Handle any attributes needing translation or lifting.
if (translateOrLift.any()) if (translateOrLift.any())
{ {
std::size_t count = maxIndex + 1; std::size_t count = maxIndex - minIndex + 1;
std::size_t requiredSpace = 0; std::size_t requiredSpace = 0;
...@@ -222,6 +196,10 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib ...@@ -222,6 +196,10 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib
input = attribs[i].mPointer; input = attribs[i].mPointer;
} }
size_t inputStride = interpretGlStride(attribs[i]);
input = static_cast<const char*>(input) + inputStride * minIndex;
translator->translate(formatConverter, interpretGlStride(attribs[i]), input, output); translator->translate(formatConverter, interpretGlStride(attribs[i]), input, output);
mStreamBuffer->unmap(); mStreamBuffer->unmap();
......
...@@ -26,6 +26,7 @@ class BufferBackEnd; ...@@ -26,6 +26,7 @@ class BufferBackEnd;
class TranslatedVertexBuffer; class TranslatedVertexBuffer;
struct TranslatedAttribute; struct TranslatedAttribute;
struct FormatConverter; struct FormatConverter;
struct TranslatedIndexData;
class VertexDataManager class VertexDataManager
{ {
...@@ -39,8 +40,7 @@ class VertexDataManager ...@@ -39,8 +40,7 @@ class VertexDataManager
GLsizei count, GLsizei count,
TranslatedAttribute *outAttribs); TranslatedAttribute *outAttribs);
GLenum preRenderValidate(const Index *indices, GLenum preRenderValidate(const TranslatedIndexData &indexInfo,
GLsizei count,
TranslatedAttribute* outAttribs); TranslatedAttribute* outAttribs);
private: private:
...@@ -69,12 +69,13 @@ class VertexDataManager ...@@ -69,12 +69,13 @@ class VertexDataManager
class IndexedTranslationHelper : public TranslationHelper class IndexedTranslationHelper : public TranslationHelper
{ {
public: public:
IndexedTranslationHelper(const Index *indices, GLsizei count); IndexedTranslationHelper(const Index *indices, Index minIndex, GLsizei count);
void translate(const FormatConverter &converter, GLint stride, const void *source, void *dest); void translate(const FormatConverter &converter, GLint stride, const void *source, void *dest);
private: private:
const Index *mIndices; const Index *mIndices;
Index mMinIndex;
GLsizei mCount; GLsizei mCount;
}; };
......
...@@ -26,7 +26,7 @@ struct FormatConverter ...@@ -26,7 +26,7 @@ struct FormatConverter
{ {
bool identity; bool identity;
std::size_t outputVertexSize; std::size_t outputVertexSize;
void (*convertIndexed)(const void *in, std::size_t stride, std::size_t n, const Index *indices, void *out); void (*convertIndexed)(const void *in, std::size_t stride, Index minIndex, std::size_t n, const Index *indices, void *out);
void (*convertArray)(const void *in, std::size_t stride, std::size_t n, void *out); void (*convertArray)(const void *in, std::size_t stride, std::size_t n, void *out);
}; };
...@@ -57,7 +57,8 @@ class BufferBackEnd ...@@ -57,7 +57,8 @@ class BufferBackEnd
virtual TranslatedIndexBuffer *createIndexBuffer(std::size_t size) = 0; virtual TranslatedIndexBuffer *createIndexBuffer(std::size_t size) = 0;
virtual FormatConverter getFormatConverter(GLenum type, std::size_t size, bool normalize) = 0; virtual FormatConverter getFormatConverter(GLenum type, std::size_t size, bool normalize) = 0;
virtual GLenum preDraw(const TranslatedAttribute *attributes) = 0; virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo) = 0;
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes) = 0;
}; };
class TranslatedBuffer class TranslatedBuffer
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "geometry/vertexconversion.h" #include "geometry/vertexconversion.h"
#include "geometry/IndexDataManager.h"
namespace namespace
{ {
...@@ -179,7 +180,13 @@ IDirect3DIndexBuffer9 *Dx9BackEnd::getDxBuffer(TranslatedIndexBuffer *ib) const ...@@ -179,7 +180,13 @@ IDirect3DIndexBuffer9 *Dx9BackEnd::getDxBuffer(TranslatedIndexBuffer *ib) const
return ib ? static_cast<Dx9IndexBuffer*>(ib)->getBuffer() : NULL; return ib ? static_cast<Dx9IndexBuffer*>(ib)->getBuffer() : NULL;
} }
GLenum Dx9BackEnd::preDraw(const TranslatedAttribute *attributes) GLenum Dx9BackEnd::setupIndicesPreDraw(const TranslatedIndexData &indexInfo)
{
mDevice->SetIndices(getDxBuffer(indexInfo.buffer));
return GL_NO_ERROR;
}
GLenum Dx9BackEnd::setupAttributesPreDraw(const TranslatedAttribute *attributes)
{ {
HRESULT hr; HRESULT hr;
......
...@@ -27,7 +27,8 @@ class Dx9BackEnd : public BufferBackEnd ...@@ -27,7 +27,8 @@ class Dx9BackEnd : public BufferBackEnd
virtual TranslatedIndexBuffer *createIndexBuffer(std::size_t size); virtual TranslatedIndexBuffer *createIndexBuffer(std::size_t size);
virtual FormatConverter getFormatConverter(GLenum type, std::size_t size, bool normalize); virtual FormatConverter getFormatConverter(GLenum type, std::size_t size, bool normalize);
virtual GLenum preDraw(const TranslatedAttribute *attributes); virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo);
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes);
private: private:
IDirect3DDevice9 *mDevice; IDirect3DDevice9 *mDevice;
......
...@@ -180,12 +180,12 @@ struct VertexDataConverter ...@@ -180,12 +180,12 @@ struct VertexDataConverter
return convertArray(static_cast<const InputType*>(in), stride, n, static_cast<OutputType*>(out)); return convertArray(static_cast<const InputType*>(in), stride, n, static_cast<OutputType*>(out));
} }
static void convertIndexed(const InputType *in, std::size_t stride, std::size_t n, const Index *indices, OutputType *out) static void convertIndexed(const InputType *in, std::size_t stride, Index minIndex, std::size_t n, const Index *indices, OutputType *out)
{ {
for (std::size_t i = 0; i < n; i++) for (std::size_t i = 0; i < n; i++)
{ {
const InputType *ein = pointerAddBytes(in, indices[i] * stride); const InputType *ein = pointerAddBytes(in, (indices[i] - minIndex) * stride);
OutputType *eout = pointerAddBytes(out, indices[i] * finalSize); OutputType *eout = pointerAddBytes(out, (indices[i] - minIndex) * finalSize);
copyComponent(eout, ein, 0, static_cast<OutputType>(DefaultValueRule::zero())); copyComponent(eout, ein, 0, static_cast<OutputType>(DefaultValueRule::zero()));
copyComponent(eout, ein, 1, static_cast<OutputType>(DefaultValueRule::zero())); copyComponent(eout, ein, 1, static_cast<OutputType>(DefaultValueRule::zero()));
...@@ -194,9 +194,9 @@ struct VertexDataConverter ...@@ -194,9 +194,9 @@ struct VertexDataConverter
} }
} }
static void convertIndexed(const void *in, std::size_t stride, std::size_t n, const Index *indices, void *out) static void convertIndexed(const void *in, std::size_t stride, Index minIndex, std::size_t n, const Index *indices, void *out)
{ {
convertIndexed(static_cast<const InputType*>(in), stride, n, indices, static_cast<OutputType*>(out)); convertIndexed(static_cast<const InputType*>(in), stride, minIndex, n, indices, static_cast<OutputType*>(out));
} }
private: private:
......
...@@ -238,6 +238,10 @@ ...@@ -238,6 +238,10 @@
> >
</File> </File>
<File <File
RelativePath=".\geometry\IndexDataManager.cpp"
>
</File>
<File
RelativePath=".\geometry\VertexDataManager.cpp" RelativePath=".\geometry\VertexDataManager.cpp"
> >
</File> </File>
...@@ -316,6 +320,10 @@ ...@@ -316,6 +320,10 @@
> >
</File> </File>
<File <File
RelativePath=".\geometry\IndexDataManager.h"
>
</File>
<File
RelativePath=".\geometry\vertexconversion.h" RelativePath=".\geometry\vertexconversion.h"
> >
</File> </File>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment