Translate/lift vertex attributes when input stride or offset is not a multiple of 4.

TRAC #11847 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Author: Andrew Lewycky git-svn-id: https://angleproject.googlecode.com/svn/trunk@149 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b587598c
...@@ -128,12 +128,22 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib ...@@ -128,12 +128,22 @@ GLenum VertexDataManager::internalPreRenderValidate(const AttributeState *attrib
{ {
if (attribs[i].mBoundBuffer != 0 && mBackend->getFormatConverter(attribs[i].mType, attribs[i].mSize, attribs[i].mNormalized).identity) if (attribs[i].mBoundBuffer != 0 && mBackend->getFormatConverter(attribs[i].mType, attribs[i].mSize, attribs[i].mNormalized).identity)
{ {
translated[i].type = attribs[i].mType; std::size_t stride = interpretGlStride(attribs[i]);
translated[i].size = attribs[i].mSize; std::size_t offset = static_cast<std::size_t>(static_cast<const char*>(attribs[i].mPointer) - static_cast<const char*>(NULL)) + translated[i].stride * minIndex;
translated[i].normalized = attribs[i].mNormalized;
translated[i].stride = interpretGlStride(attribs[i]); if (mBackend->validateStream(attribs[i].mType, attribs[i].mSize, stride, offset))
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].type = attribs[i].mType;
translated[i].size = attribs[i].mSize;
translated[i].normalized = attribs[i].mNormalized;
translated[i].stride = stride;
translated[i].offset = offset;
translated[i].buffer = mContext->getBuffer(attribs[i].mBoundBuffer)->identityBuffer();
}
else
{
translateOrLift[i] = true;
}
} }
else else
{ {
......
...@@ -57,6 +57,9 @@ class BufferBackEnd ...@@ -57,6 +57,9 @@ 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;
// For an identity-mappable stream, verify that the stride and offset are okay.
virtual bool validateStream(GLenum type, std::size_t size, std::size_t stride, std::size_t offset) const = 0;
virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo) = 0; virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo) = 0;
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes) = 0; virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes) = 0;
}; };
......
...@@ -170,6 +170,12 @@ D3DDECLTYPE Dx9BackEnd::mapAttributeType(GLenum type, std::size_t size, bool nor ...@@ -170,6 +170,12 @@ D3DDECLTYPE Dx9BackEnd::mapAttributeType(GLenum type, std::size_t size, bool nor
} }
} }
bool Dx9BackEnd::validateStream(GLenum type, std::size_t size, std::size_t stride, std::size_t offset) const
{
// D3D9 requires the stream offset and stride to be a multiple of DWORD.
return (stride % sizeof(DWORD) == 0 && offset % sizeof(DWORD) == 0);
}
IDirect3DVertexBuffer9 *Dx9BackEnd::getDxBuffer(TranslatedVertexBuffer *vb) const IDirect3DVertexBuffer9 *Dx9BackEnd::getDxBuffer(TranslatedVertexBuffer *vb) const
{ {
return vb ? static_cast<Dx9VertexBuffer*>(vb)->getBuffer() : NULL; return vb ? static_cast<Dx9VertexBuffer*>(vb)->getBuffer() : NULL;
......
...@@ -27,6 +27,8 @@ class Dx9BackEnd : public BufferBackEnd ...@@ -27,6 +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 bool validateStream(GLenum type, std::size_t size, std::size_t stride, std::size_t offset) const;
virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo); virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo);
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes); virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes);
......
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