Merged the current value attributes into the regular vertex attributes so they…

Merged the current value attributes into the regular vertex attributes so they follow the same conversion rules. TRAC #22693 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2117 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 3026dc7d
......@@ -87,7 +87,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
ilKey.elements[ilKey.elementCount].SemanticName = semanticName;
ilKey.elements[ilKey.elementCount].SemanticIndex = sortedSemanticIndices[i];
ilKey.elements[ilKey.elementCount].Format = attributes[i].attribute->mArrayEnabled ? vertexBuffer->getDXGIFormat(*attributes[i].attribute) : DXGI_FORMAT_R32G32B32A32_FLOAT;
ilKey.elements[ilKey.elementCount].Format = vertexBuffer->getDXGIFormat(*attributes[i].attribute);
ilKey.elements[ilKey.elementCount].InputSlot = i;
ilKey.elements[ilKey.elementCount].AlignedByteOffset = 0;
ilKey.elements[ilKey.elementCount].InputSlotClass = inputClass;
......
......@@ -106,35 +106,11 @@ int VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attr
return oldWritePos;
}
int VertexBufferInterface::storeRawData(const void* data, unsigned int size)
{
if (!reserveSpace(mReservedSpace))
{
return -1;
}
mReservedSpace = 0;
if (!mVertexBuffer->storeRawData(data, size, mWritePosition))
{
return -1;
}
int oldWritePos = static_cast<int>(mWritePosition);
mWritePosition += size;
return oldWritePos;
}
void VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances)
{
mReservedSpace += mVertexBuffer->getSpaceRequired(attribute, count, instances);
}
void VertexBufferInterface::reserveRawDataSpace(unsigned int size)
{
mReservedSpace += size;
}
VertexBuffer* VertexBufferInterface::getVertexBuffer() const
{
return mVertexBuffer;
......
......@@ -31,8 +31,6 @@ class VertexBuffer
virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count,
GLsizei instances, unsigned int offset) = 0;
virtual bool storeRawData(const void* data, unsigned int size, unsigned int offset) = 0;
virtual unsigned int getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count,
GLsizei instances) const = 0;
......@@ -61,14 +59,12 @@ class VertexBufferInterface
virtual ~VertexBufferInterface();
void reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
void reserveRawDataSpace(unsigned int size);
unsigned int getBufferSize() const;
unsigned int getSerial() const;
virtual int storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances);
virtual int storeRawData(const void* data, unsigned int size);
VertexBuffer* getVertexBuffer() const;
......
......@@ -99,14 +99,21 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, GL
char* output = reinterpret_cast<char*>(mappedResource.pData) + offset;
const char *input = NULL;
if (buffer)
if (attrib.mArrayEnabled)
{
BufferStorage *storage = buffer->getStorage();
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.mOffset);
if (buffer)
{
BufferStorage *storage = buffer->getStorage();
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.mOffset);
}
else
{
input = static_cast<const char*>(attrib.mPointer);
}
}
else
{
input = static_cast<const char*>(attrib.mPointer);
input = reinterpret_cast<const char*>(attrib.mCurrentValue.FloatValues);
}
if (instances == 0 || attrib.mDivisor == 0)
......@@ -127,46 +134,25 @@ bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, GL
}
}
bool VertexBuffer11::storeRawData(const void* data, unsigned int size, unsigned int offset)
{
if (mBuffer)
{
ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource);
if (FAILED(result))
{
ERR("Vertex buffer map failed with error 0x%08x", result);
return false;
}
char* bufferData = static_cast<char*>(mappedResource.pData);
memcpy(bufferData + offset, data, size);
dxContext->Unmap(mBuffer, 0);
return true;
}
else
{
ERR("Vertex buffer not initialized.");
return false;
}
}
unsigned int VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count,
GLsizei instances) const
{
unsigned int elementSize = getVertexConversion(attrib).outputElementSize;
if (instances == 0 || attrib.mDivisor == 0)
if (attrib.mArrayEnabled)
{
return elementSize * count;
if (instances == 0 || attrib.mDivisor == 0)
{
return elementSize * count;
}
else
{
return elementSize * ((instances + attrib.mDivisor - 1) / attrib.mDivisor);
}
}
else
{
return elementSize * ((instances + attrib.mDivisor - 1) / attrib.mDivisor);
return elementSize * 4;
}
}
......@@ -419,8 +405,10 @@ const VertexBuffer11::VertexConverter VertexBuffer11::mPossibleTranslations[NUM_
const VertexBuffer11::VertexConverter &VertexBuffer11::getVertexConversion(const gl::VertexAttribute &attribute)
{
GLenum type = attribute.mArrayEnabled ? attribute.mType : attribute.mCurrentValue.Type;
unsigned int typeIndex = 0;
switch (attribute.mType)
switch (type)
{
case GL_BYTE: typeIndex = 0; break;
case GL_UNSIGNED_BYTE: typeIndex = 1; break;
......
......@@ -26,8 +26,7 @@ class VertexBuffer11 : public VertexBuffer
static VertexBuffer11 *makeVertexBuffer11(VertexBuffer *vetexBuffer);
virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances,
unsigned int offset);
virtual bool storeRawData(const void* data, unsigned int size, unsigned int offset);
unsigned int offset);
virtual unsigned int getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances) const;
......@@ -70,4 +69,4 @@ class VertexBuffer11 : public VertexBuffer
}
#endif // LIBGLESV2_RENDERER_VERTEXBUFFER11_H_
\ No newline at end of file
#endif // LIBGLESV2_RENDERER_VERTEXBUFFER11_H_
......@@ -104,14 +104,21 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, GLi
}
const char *input = NULL;
if (buffer)
if (attrib.mArrayEnabled)
{
BufferStorage *storage = buffer->getStorage();
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.mOffset);
if (buffer)
{
BufferStorage *storage = buffer->getStorage();
input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.mOffset);
}
else
{
input = static_cast<const char*>(attrib.mPointer);
}
}
else
{
input = static_cast<const char*>(attrib.mPointer);
input = reinterpret_cast<const char*>(attrib.mCurrentValue.FloatValues);
}
if (instances == 0 || attrib.mDivisor == 0)
......@@ -139,34 +146,6 @@ bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, GLi
}
}
bool VertexBuffer9::storeRawData(const void* data, unsigned int size, unsigned int offset)
{
if (mVertexBuffer)
{
DWORD lockFlags = mDynamicUsage ? D3DLOCK_NOOVERWRITE : 0;
void *mapPtr = NULL;
HRESULT result = mVertexBuffer->Lock(offset, size, &mapPtr, lockFlags);
if (FAILED(result))
{
ERR("Lock failed with error 0x%08x", result);
return false;
}
memcpy(mapPtr, data, size);
mVertexBuffer->Unlock();
return true;
}
else
{
ERR("Vertex buffer not initialized.");
return false;
}
}
unsigned int VertexBuffer9::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances) const
{
return spaceRequired(attrib, count, instances);
......@@ -466,20 +445,28 @@ unsigned int VertexBuffer9::typeIndex(GLenum type)
const VertexBuffer9::FormatConverter &VertexBuffer9::formatConverter(const gl::VertexAttribute &attribute)
{
return mFormatConverters[typeIndex(attribute.mType)][attribute.mNormalized][attribute.mSize - 1];
GLenum type = attribute.mArrayEnabled ? attribute.mType : attribute.mCurrentValue.Type;
return mFormatConverters[typeIndex(type)][attribute.mNormalized][attribute.mSize - 1];
}
unsigned int VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances)
{
unsigned int elementSize = formatConverter(attrib).outputElementSize;
if (instances == 0 || attrib.mDivisor == 0)
if (attrib.mArrayEnabled)
{
return elementSize * count;
if (instances == 0 || attrib.mDivisor == 0)
{
return elementSize * count;
}
else
{
return elementSize * ((instances + attrib.mDivisor - 1) / attrib.mDivisor);
}
}
else
{
return elementSize * ((instances + attrib.mDivisor - 1) / attrib.mDivisor);
return elementSize * 4;
}
}
......
......@@ -27,7 +27,6 @@ class VertexBuffer9 : public VertexBuffer
virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances,
unsigned int offset);
virtual bool storeRawData(const void* data, unsigned int size, unsigned int offset);
virtual unsigned int getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances) const;
......
......@@ -214,9 +214,8 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
if (memcmp(&mCurrentValue[i], &attribs[i].mCurrentValue, sizeof(gl::VertexAttribute::CurrentValueData)) != 0)
{
unsigned int requiredSpace = sizeof(float) * 4;
buffer->reserveRawDataSpace(requiredSpace);
int streamOffset = buffer->storeRawData(attribs[i].mCurrentValue.FloatValues, requiredSpace);
buffer->reserveVertexSpace(attribs[i], 1, 0);
int streamOffset = buffer->storeVertexAttributes(attribs[i], 0, 1, 0);
if (streamOffset == -1)
{
return GL_OUT_OF_MEMORY;
......
......@@ -136,7 +136,7 @@ GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, Transl
element->Stream = stream;
element->Offset = 0;
element->Type = attributes[i].attribute->mArrayEnabled ? vertexBuffer->getDeclType(*attributes[i].attribute) : D3DDECLTYPE_FLOAT4;
element->Type = vertexBuffer->getDeclType(*attributes[i].attribute);
element->Method = D3DDECLMETHOD_DEFAULT;
element->Usage = D3DDECLUSAGE_TEXCOORD;
element->UsageIndex = programBinary->getSemanticIndex(i);
......
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