aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoff Lang <geofflang@chromium.org>2014-09-08 16:17:08 -0400
committerGeoff Lang <geofflang@chromium.org>2014-09-19 14:01:45 +0000
commitf7100b981f0856b238252e6052509eecf8e5aded (patch)
treef944e3009f2f9b5ba8d06dd717d52be9fce929f4
parentd5a796caeedbc1e6c8d483019f1da0cb676e118a (diff)
downloadangle-f7100b981f0856b238252e6052509eecf8e5aded.tar.gz
Updated the vertex buffer classes to use Error objects.
BUG=angle:520 Change-Id: Id003e66b2acbf37dbbe66aaca2fa336c3c884be2 Reviewed-on: https://chromium-review.googlesource.com/217102 Reviewed-by: Jamie Madill <jmadill@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>
-rw-r--r--src/libGLESv2/Context.cpp16
-rw-r--r--src/libGLESv2/renderer/Renderer.h4
-rw-r--r--src/libGLESv2/renderer/d3d/VertexBuffer.cpp97
-rw-r--r--src/libGLESv2/renderer/d3d/VertexBuffer.h35
-rw-r--r--src/libGLESv2/renderer/d3d/VertexDataManager.cpp123
-rw-r--r--src/libGLESv2/renderer/d3d/VertexDataManager.h34
-rw-r--r--src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp12
-rw-r--r--src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.h5
-rw-r--r--src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp10
-rw-r--r--src/libGLESv2/renderer/d3d/d3d11/Renderer11.h4
-rw-r--r--src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp131
-rw-r--r--src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.h14
-rw-r--r--src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp10
-rw-r--r--src/libGLESv2/renderer/d3d/d3d9/Renderer9.h4
-rw-r--r--src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp164
-rw-r--r--src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.h16
-rw-r--r--src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.cpp13
-rw-r--r--src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.h3
18 files changed, 354 insertions, 341 deletions
diff --git a/src/libGLESv2/Context.cpp b/src/libGLESv2/Context.cpp
index 87480c46..c467fa8b 100644
--- a/src/libGLESv2/Context.cpp
+++ b/src/libGLESv2/Context.cpp
@@ -1683,10 +1683,10 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
applyRenderTarget(mode, false);
applyState(mode);
- GLenum err = mRenderer->applyVertexBuffer(programBinary, mState.getVertexArray()->getVertexAttributes(), mState.getVertexAttribCurrentValues(), first, count, instances);
- if (err != GL_NO_ERROR)
+ Error error = mRenderer->applyVertexBuffer(programBinary, mState.getVertexArray()->getVertexAttributes(), mState.getVertexAttribCurrentValues(), first, count, instances);
+ if (error.isError())
{
- return gl::error(err);
+ return gl::error(error.getCode());
}
bool transformFeedbackActive = applyTransformFeedbackBuffers();
@@ -1740,12 +1740,12 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type,
}
GLsizei vertexCount = indexInfo.indexRange.length() + 1;
- GLenum err = mRenderer->applyVertexBuffer(programBinary, vao->getVertexAttributes(),
- mState.getVertexAttribCurrentValues(),
- indexInfo.indexRange.start, vertexCount, instances);
- if (err != GL_NO_ERROR)
+ error = mRenderer->applyVertexBuffer(programBinary, vao->getVertexAttributes(),
+ mState.getVertexAttribCurrentValues(),
+ indexInfo.indexRange.start, vertexCount, instances);
+ if (error.isError())
{
- return gl::error(err);
+ return gl::error(error.getCode());
}
bool transformFeedbackActive = applyTransformFeedbackBuffers();
diff --git a/src/libGLESv2/renderer/Renderer.h b/src/libGLESv2/renderer/Renderer.h
index 390cdfb7..ec75fbbf 100644
--- a/src/libGLESv2/renderer/Renderer.h
+++ b/src/libGLESv2/renderer/Renderer.h
@@ -133,8 +133,8 @@ class Renderer
bool rasterizerDiscard, bool transformFeedbackActive) = 0;
virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
- virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances) = 0;
+ virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
+ GLint first, GLsizei count, GLsizei instances) = 0;
virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) = 0;
diff --git a/src/libGLESv2/renderer/d3d/VertexBuffer.cpp b/src/libGLESv2/renderer/d3d/VertexBuffer.cpp
index d2a1e8fc..4f85eb94 100644
--- a/src/libGLESv2/renderer/d3d/VertexBuffer.cpp
+++ b/src/libGLESv2/renderer/d3d/VertexBuffer.cpp
@@ -62,7 +62,7 @@ unsigned int VertexBufferInterface::getBufferSize() const
return mVertexBuffer->getBufferSize();
}
-bool VertexBufferInterface::setBufferSize(unsigned int size)
+gl::Error VertexBufferInterface::setBufferSize(unsigned int size)
{
if (mVertexBuffer->getBufferSize() == 0)
{
@@ -84,34 +84,39 @@ void VertexBufferInterface::setWritePosition(unsigned int writePosition)
mWritePosition = writePosition;
}
-bool VertexBufferInterface::discard()
+gl::Error VertexBufferInterface::discard()
{
return mVertexBuffer->discard();
}
-bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
+gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{
+ gl::Error error(GL_NO_ERROR);
+
unsigned int spaceRequired;
- if (!mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired))
+ error = mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired);
+ if (error.isError())
{
- return false;
+ return error;
}
if (mWritePosition + spaceRequired < mWritePosition)
{
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal error, new vertex buffer write position would overflow.");
}
- if (!reserveSpace(mReservedSpace))
+ error = reserveSpace(mReservedSpace);
+ if (error.isError())
{
- return false;
+ return error;
}
mReservedSpace = 0;
- if (!mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition))
+ error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition);
+ if (error.isError())
{
- return false;
+ return error;
}
if (outStreamOffset)
@@ -124,21 +129,25 @@ bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &att
// Align to 16-byte boundary
mWritePosition = rx::roundUp(mWritePosition, 16u);
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-bool VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances)
+gl::Error VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances)
{
+ gl::Error error(GL_NO_ERROR);
+
unsigned int requiredSpace;
- if (!mVertexBuffer->getSpaceRequired(attrib, count, instances, &requiredSpace))
+ error = mVertexBuffer->getSpaceRequired(attrib, count, instances, &requiredSpace);
+ if (error.isError())
{
- return false;
+ return error;
}
// Protect against integer overflow
if (mReservedSpace + requiredSpace < mReservedSpace)
{
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Unable to reserve %u extra bytes in internal vertex buffer, "
+ "it would result in an overflow.", requiredSpace);
}
mReservedSpace += requiredSpace;
@@ -146,7 +155,7 @@ bool VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib
// Align to 16-byte boundary
mReservedSpace = rx::roundUp(mReservedSpace, 16u);
- return true;
+ return gl::Error(GL_NO_ERROR);
}
VertexBuffer* VertexBufferInterface::getVertexBuffer() const
@@ -197,25 +206,29 @@ StreamingVertexBufferInterface::~StreamingVertexBufferInterface()
{
}
-bool StreamingVertexBufferInterface::reserveSpace(unsigned int size)
+gl::Error StreamingVertexBufferInterface::reserveSpace(unsigned int size)
{
- bool result = true;
unsigned int curBufferSize = getBufferSize();
if (size > curBufferSize)
{
- result = setBufferSize(std::max(size, 3 * curBufferSize / 2));
+ gl::Error error = setBufferSize(std::max(size, 3 * curBufferSize / 2));
+ if (error.isError())
+ {
+ return error;
+ }
setWritePosition(0);
}
else if (getWritePosition() + size > curBufferSize)
{
- if (!discard())
+ gl::Error error = discard();
+ if (error.isError())
{
- return false;
+ return error;
}
setWritePosition(0);
}
- return result;
+ return gl::Error(GL_NO_ERROR);
}
StaticVertexBufferInterface::StaticVertexBufferInterface(rx::Renderer *renderer) : VertexBufferInterface(renderer, false)
@@ -251,46 +264,44 @@ bool StaticVertexBufferInterface::lookupAttribute(const gl::VertexAttribute &att
return false;
}
-bool StaticVertexBufferInterface::reserveSpace(unsigned int size)
+gl::Error StaticVertexBufferInterface::reserveSpace(unsigned int size)
{
unsigned int curSize = getBufferSize();
if (curSize == 0)
{
- setBufferSize(size);
- return true;
+ return setBufferSize(size);
}
else if (curSize >= size)
{
- return true;
+ return gl::Error(GL_NO_ERROR);
}
else
{
- UNREACHABLE(); // Static vertex buffers can't be resized
- return false;
+ UNREACHABLE();
+ return gl::Error(GL_INVALID_OPERATION, "Internal error, Static vertex buffers can't be resized.");
}
}
-bool StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
+gl::Error StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{
unsigned int streamOffset;
- if (VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset))
+ gl::Error error = VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset);
+ if (error.isError())
{
- size_t attributeOffset = static_cast<size_t>(attrib.offset) % ComputeVertexAttributeStride(attrib);
- VertexElement element = { attrib.type, attrib.size, ComputeVertexAttributeStride(attrib), attrib.normalized, attrib.pureInteger, attributeOffset, streamOffset };
- mCache.push_back(element);
+ return error;
+ }
- if (outStreamOffset)
- {
- *outStreamOffset = streamOffset;
- }
+ size_t attributeOffset = static_cast<size_t>(attrib.offset) % ComputeVertexAttributeStride(attrib);
+ VertexElement element = { attrib.type, attrib.size, ComputeVertexAttributeStride(attrib), attrib.normalized, attrib.pureInteger, attributeOffset, streamOffset };
+ mCache.push_back(element);
- return true;
- }
- else
+ if (outStreamOffset)
{
- return false;
+ *outStreamOffset = streamOffset;
}
+
+ return gl::Error(GL_NO_ERROR);
}
}
diff --git a/src/libGLESv2/renderer/d3d/VertexBuffer.h b/src/libGLESv2/renderer/d3d/VertexBuffer.h
index e36084fe..fa747d9c 100644
--- a/src/libGLESv2/renderer/d3d/VertexBuffer.h
+++ b/src/libGLESv2/renderer/d3d/VertexBuffer.h
@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_VERTEXBUFFER_H_
#include "common/angleutils.h"
+#include "libGLESv2/Error.h"
#include <GLES2/gl2.h>
@@ -33,16 +34,16 @@ class VertexBuffer
VertexBuffer();
virtual ~VertexBuffer();
- virtual bool initialize(unsigned int size, bool dynamicUsage) = 0;
+ virtual gl::Error initialize(unsigned int size, bool dynamicUsage) = 0;
- virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0;
- virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
- unsigned int *outSpaceRequired) const = 0;
+ virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0;
+ virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
+ unsigned int *outSpaceRequired) const = 0;
virtual unsigned int getBufferSize() const = 0;
- virtual bool setBufferSize(unsigned int size) = 0;
- virtual bool discard() = 0;
+ virtual gl::Error setBufferSize(unsigned int size) = 0;
+ virtual gl::Error discard() = 0;
unsigned int getSerial() const;
@@ -62,14 +63,14 @@ class VertexBufferInterface
VertexBufferInterface(rx::Renderer *renderer, bool dynamic);
virtual ~VertexBufferInterface();
- bool reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
+ gl::Error reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
unsigned int getBufferSize() const;
unsigned int getSerial() const;
- virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
+ virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
bool directStoragePossible(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue) const;
@@ -77,14 +78,14 @@ class VertexBufferInterface
VertexBuffer* getVertexBuffer() const;
protected:
- virtual bool reserveSpace(unsigned int size) = 0;
+ virtual gl::Error reserveSpace(unsigned int size) = 0;
unsigned int getWritePosition() const;
void setWritePosition(unsigned int writePosition);
- bool discard();
+ gl::Error discard();
- bool setBufferSize(unsigned int size);
+ gl::Error setBufferSize(unsigned int size);
private:
DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface);
@@ -105,7 +106,7 @@ class StreamingVertexBufferInterface : public VertexBufferInterface
~StreamingVertexBufferInterface();
protected:
- bool reserveSpace(unsigned int size);
+ gl::Error reserveSpace(unsigned int size);
};
class StaticVertexBufferInterface : public VertexBufferInterface
@@ -114,13 +115,13 @@ class StaticVertexBufferInterface : public VertexBufferInterface
explicit StaticVertexBufferInterface(rx::Renderer *renderer);
~StaticVertexBufferInterface();
- bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
+ gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset);
protected:
- bool reserveSpace(unsigned int size);
+ gl::Error reserveSpace(unsigned int size);
private:
struct VertexElement
diff --git a/src/libGLESv2/renderer/d3d/VertexDataManager.cpp b/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
index a69bc679..7034b78e 100644
--- a/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
+++ b/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
@@ -82,12 +82,12 @@ VertexDataManager::~VertexDataManager()
}
}
-GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[],
- gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *translated, GLsizei instances)
+gl::Error VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[],
+ gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *translated, GLsizei instances)
{
if (!mStreamingBuffer)
{
- return GL_OUT_OF_MEMORY;
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal streaming vertex buffer is unexpectedly NULL.");
}
// Invalidate static buffers that don't contain matching attributes
@@ -106,9 +106,10 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
{
if (translated[i].active && attribs[i].enabled)
{
- if (!reserveSpaceForAttrib(attribs[i], currentValues[i], count, instances))
+ gl::Error error = reserveSpaceForAttrib(attribs[i], currentValues[i], count, instances);
+ if (error.isError())
{
- return GL_OUT_OF_MEMORY;
+ return error;
}
}
}
@@ -118,12 +119,14 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
{
if (translated[i].active)
{
- GLenum result;
-
if (attribs[i].enabled)
{
- result = storeAttribute(attribs[i], currentValues[i], &translated[i],
- start, count, instances);
+ gl::Error error = storeAttribute(attribs[i], currentValues[i], &translated[i],
+ start, count, instances);
+ if (error.isError())
+ {
+ return error;
+ }
}
else
{
@@ -132,14 +135,13 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mRenderer, CONSTANT_VERTEX_BUFFER_SIZE);
}
- result = storeCurrentValue(attribs[i], currentValues[i], &translated[i],
- &mCurrentValue[i], &mCurrentValueOffsets[i],
- mCurrentValueBuffer[i]);
- }
-
- if (result != GL_NO_ERROR)
- {
- return result;
+ gl::Error error = storeCurrentValue(attribs[i], currentValues[i], &translated[i],
+ &mCurrentValue[i], &mCurrentValueOffsets[i],
+ mCurrentValueBuffer[i]);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
}
@@ -158,7 +160,7 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
}
}
- return GL_NO_ERROR;
+ return gl::Error(GL_NO_ERROR);
}
void VertexDataManager::invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
@@ -181,10 +183,10 @@ void VertexDataManager::invalidateMatchingStaticData(const gl::VertexAttribute &
}
}
-bool VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
- const gl::VertexAttribCurrentValueData &currentValue,
- GLsizei count,
- GLsizei instances) const
+gl::Error VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
+ const gl::VertexAttribCurrentValueData &currentValue,
+ GLsizei count,
+ GLsizei instances) const
{
gl::Buffer *buffer = attrib.buffer.get();
BufferD3D *bufferImpl = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL;
@@ -198,9 +200,10 @@ bool VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
if (staticBuffer->getBufferSize() == 0)
{
int totalCount = ElementsInBuffer(attrib, bufferImpl->getSize());
- if (!staticBuffer->reserveVertexSpace(attrib, totalCount, 0))
+ gl::Error error = staticBuffer->reserveVertexSpace(attrib, totalCount, 0);
+ if (error.isError())
{
- return false;
+ return error;
}
}
}
@@ -209,22 +212,23 @@ bool VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
int totalCount = StreamingBufferElementCount(attrib, count, instances);
ASSERT(!bufferImpl || ElementsInBuffer(attrib, bufferImpl->getSize()) >= totalCount);
- if (!mStreamingBuffer->reserveVertexSpace(attrib, totalCount, instances))
+ gl::Error error = mStreamingBuffer->reserveVertexSpace(attrib, totalCount, instances);
+ if (error.isError())
{
- return false;
+ return error;
}
}
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
- const gl::VertexAttribCurrentValueData &currentValue,
- TranslatedAttribute *translated,
- GLint start,
- GLsizei count,
- GLsizei instances)
+gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
+ const gl::VertexAttribCurrentValueData &currentValue,
+ TranslatedAttribute *translated,
+ GLint start,
+ GLsizei count,
+ GLsizei instances)
{
gl::Buffer *buffer = attrib.buffer.get();
ASSERT(buffer || attrib.pointer);
@@ -244,9 +248,10 @@ GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
}
else if (staticBuffer)
{
- if (!staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize))
+ gl::Error error = staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
+ if (error.isError())
{
- return GL_OUT_OF_MEMORY;
+ return error;
}
if (!staticBuffer->lookupAttribute(attrib, &streamOffset))
@@ -255,10 +260,11 @@ GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
int totalCount = ElementsInBuffer(attrib, storage->getSize());
int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib);
- if (!staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount,
- 0, &streamOffset))
+ gl::Error error = staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount,
+ 0, &streamOffset);
+ if (error.isError())
{
- return GL_OUT_OF_MEMORY;
+ return error;
}
}
@@ -266,7 +272,7 @@ GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
unsigned int startOffset = (instances == 0 || attrib.divisor == 0) ? start * outputElementSize : 0;
if (streamOffset + firstElementOffset + startOffset < streamOffset)
{
- return GL_OUT_OF_MEMORY;
+ return gl::Error(GL_OUT_OF_MEMORY);
}
streamOffset += firstElementOffset + startOffset;
@@ -274,11 +280,16 @@ GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
else
{
int totalCount = StreamingBufferElementCount(attrib, count, instances);
- if (!mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize) ||
- !mStreamingBuffer->storeVertexAttributes(attrib, currentValue, start, totalCount, instances,
- &streamOffset))
+ gl::Error error = mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
+ if (error.isError())
{
- return GL_OUT_OF_MEMORY;
+ return error;
+ }
+
+ error = mStreamingBuffer->storeVertexAttributes(attrib, currentValue, start, totalCount, instances, &streamOffset);
+ if (error.isError())
+ {
+ return error;
}
}
@@ -292,27 +303,29 @@ GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
translated->stride = outputElementSize;
translated->offset = streamOffset;
- return GL_NO_ERROR;
+ return gl::Error(GL_NO_ERROR);
}
-GLenum VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib,
- const gl::VertexAttribCurrentValueData &currentValue,
- TranslatedAttribute *translated,
- gl::VertexAttribCurrentValueData *cachedValue,
- size_t *cachedOffset,
- StreamingVertexBufferInterface *buffer)
+gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib,
+ const gl::VertexAttribCurrentValueData &currentValue,
+ TranslatedAttribute *translated,
+ gl::VertexAttribCurrentValueData *cachedValue,
+ size_t *cachedOffset,
+ StreamingVertexBufferInterface *buffer)
{
if (*cachedValue != currentValue)
{
- if (!buffer->reserveVertexSpace(attrib, 1, 0))
+ gl::Error error = buffer->reserveVertexSpace(attrib, 1, 0);
+ if (error.isError())
{
- return GL_OUT_OF_MEMORY;
+ return error;
}
unsigned int streamOffset;
- if (!buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset))
+ error = buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset);
+ if (error.isError())
{
- return GL_OUT_OF_MEMORY;
+ return error;
}
*cachedValue = currentValue;
@@ -329,7 +342,7 @@ GLenum VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib,
translated->stride = 0;
translated->offset = *cachedOffset;
- return GL_NO_ERROR;
+ return gl::Error(GL_NO_ERROR);
}
}
diff --git a/src/libGLESv2/renderer/d3d/VertexDataManager.h b/src/libGLESv2/renderer/d3d/VertexDataManager.h
index 9b27a44b..77287222 100644
--- a/src/libGLESv2/renderer/d3d/VertexDataManager.h
+++ b/src/libGLESv2/renderer/d3d/VertexDataManager.h
@@ -52,33 +52,33 @@ class VertexDataManager
VertexDataManager(rx::Renderer *renderer);
virtual ~VertexDataManager();
- GLenum prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[],
- gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *outAttribs, GLsizei instances);
+ gl::Error prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[],
+ gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *outAttribs, GLsizei instances);
private:
DISALLOW_COPY_AND_ASSIGN(VertexDataManager);
- bool reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
- const gl::VertexAttribCurrentValueData &currentValue,
- GLsizei count,
- GLsizei instances) const;
+ gl::Error reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
+ const gl::VertexAttribCurrentValueData &currentValue,
+ GLsizei count,
+ GLsizei instances) const;
void invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue) const;
- GLenum storeAttribute(const gl::VertexAttribute &attrib,
- const gl::VertexAttribCurrentValueData &currentValue,
- TranslatedAttribute *translated,
- GLint start,
- GLsizei count,
- GLsizei instances);
-
- GLenum storeCurrentValue(const gl::VertexAttribute &attrib,
+ gl::Error storeAttribute(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated,
- gl::VertexAttribCurrentValueData *cachedValue,
- size_t *cachedOffset,
- StreamingVertexBufferInterface *buffer);
+ GLint start,
+ GLsizei count,
+ GLsizei instances);
+
+ gl::Error storeCurrentValue(const gl::VertexAttribute &attrib,
+ const gl::VertexAttribCurrentValueData &currentValue,
+ TranslatedAttribute *translated,
+ gl::VertexAttribCurrentValueData *cachedValue,
+ size_t *cachedOffset,
+ StreamingVertexBufferInterface *buffer);
rx::Renderer *const mRenderer;
diff --git a/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp b/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp
index b06526eb..b006c044 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp
@@ -85,16 +85,15 @@ void InputLayoutCache::markDirty()
}
}
-GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
- gl::ProgramBinary *programBinary)
+gl::Error InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
+ gl::ProgramBinary *programBinary)
{
int sortedSemanticIndices[gl::MAX_VERTEX_ATTRIBS];
programBinary->sortAttributesByLayout(attributes, sortedSemanticIndices);
if (!mDevice || !mDeviceContext)
{
- ERR("InputLayoutCache is not initialized.");
- return GL_INVALID_OPERATION;
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal input layout cache is not initialized.");
}
InputLayoutKey ilKey = { 0 };
@@ -149,8 +148,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
HRESULT result = mDevice->CreateInputLayout(descs, ilKey.elementCount, shader->getFunction(), shader->getLength(), &inputLayout);
if (FAILED(result))
{
- ERR("Failed to crate input layout, result: 0x%08x", result);
- return GL_INVALID_OPERATION;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal input layout, HRESULT: 0x%08x", result);
}
if (mInputLayoutMap.size() >= kMaxInputLayouts)
@@ -222,7 +220,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
mCurrentVertexStrides + minDiff, mCurrentVertexOffsets + minDiff);
}
- return GL_NO_ERROR;
+ return gl::Error(GL_NO_ERROR);
}
std::size_t InputLayoutCache::hashInputLayout(const InputLayoutKey &inputLayout)
diff --git a/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.h b/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.h
index 8a64c5a2..cc71ac3f 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.h
+++ b/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.h
@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_
#include "libGLESv2/Constants.h"
+#include "libGLESv2/Error.h"
#include "common/angleutils.h"
#include <GLES2/gl2.h>
@@ -37,8 +38,8 @@ class InputLayoutCache
void clear();
void markDirty();
- GLenum applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
- gl::ProgramBinary *programBinary);
+ gl::Error applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
+ gl::ProgramBinary *programBinary);
private:
DISALLOW_COPY_AND_ASSIGN(InputLayoutCache);
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
index c59c54b3..8685904c 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
@@ -933,14 +933,14 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
return true;
}
-GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances)
+gl::Error Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
+ GLint first, GLsizei count, GLsizei instances)
{
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
- GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances);
- if (err != GL_NO_ERROR)
+ gl::Error error = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances);
+ if (error.isError())
{
- return err;
+ return error;
}
return mInputLayoutCache.applyVertexBuffers(attributes, programBinary);
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
index 4a794d27..56108d03 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
+++ b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
@@ -80,8 +80,8 @@ class Renderer11 : public Renderer
virtual void applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive);
virtual void applyUniforms(const gl::ProgramBinary &programBinary);
- virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances);
+ virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
+ GLint first, GLsizei count, GLsizei instances);
virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]);
diff --git a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
index 51ea8e58..9bc5b1d2 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp
@@ -28,7 +28,7 @@ VertexBuffer11::~VertexBuffer11()
SafeRelease(mBuffer);
}
-bool VertexBuffer11::initialize(unsigned int size, bool dynamicUsage)
+gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage)
{
SafeRelease(mBuffer);
@@ -49,13 +49,14 @@ bool VertexBuffer11::initialize(unsigned int size, bool dynamicUsage)
HRESULT result = dxDevice->CreateBuffer(&bufferDesc, NULL, &mBuffer);
if (FAILED(result))
{
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate internal vertex buffer of size, %lu.", size);
}
}
mBufferSize = size;
mDynamicUsage = dynamicUsage;
- return true;
+
+ return gl::Error(GL_NO_ERROR);
}
VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer)
@@ -64,66 +65,62 @@ VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer)
return static_cast<VertexBuffer11*>(vetexBuffer);
}
-bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int offset)
+gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int offset)
{
- if (mBuffer)
+ if (!mBuffer)
{
- gl::Buffer *buffer = attrib.buffer.get();
- int inputStride = ComputeVertexAttributeStride(attrib);
- ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
+ }
- 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;
- }
+ gl::Buffer *buffer = attrib.buffer.get();
+ int inputStride = ComputeVertexAttributeStride(attrib);
+ ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
- uint8_t* output = reinterpret_cast<uint8_t*>(mappedResource.pData) + offset;
+ D3D11_MAPPED_SUBRESOURCE mappedResource;
+ HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource);
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal vertex buffer, HRESULT: 0x%08x.", result);
+ }
+
+ uint8_t *output = reinterpret_cast<uint8_t*>(mappedResource.pData) + offset;
- const uint8_t *input = NULL;
- if (attrib.enabled)
+ const uint8_t *input = NULL;
+ if (attrib.enabled)
+ {
+ if (buffer)
{
- if (buffer)
- {
- Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation());
- input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
- }
- else
- {
- input = static_cast<const uint8_t*>(attrib.pointer);
- }
+ Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation());
+ input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
}
else
{
- input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
+ input = static_cast<const uint8_t*>(attrib.pointer);
}
-
- if (instances == 0 || attrib.divisor == 0)
- {
- input += inputStride * start;
- }
-
- gl::VertexFormat vertexFormat(attrib, currentValue.Type);
- const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat);
- ASSERT(vertexFormatInfo.copyFunction != NULL);
- vertexFormatInfo.copyFunction(input, inputStride, count, output);
-
- dxContext->Unmap(mBuffer, 0);
-
- return true;
}
else
{
- ERR("Vertex buffer not initialized.");
- return false;
+ input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
}
+
+ if (instances == 0 || attrib.divisor == 0)
+ {
+ input += inputStride * start;
+ }
+
+ gl::VertexFormat vertexFormat(attrib, currentValue.Type);
+ const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat);
+ ASSERT(vertexFormatInfo.copyFunction != NULL);
+ vertexFormatInfo.copyFunction(input, inputStride, count, output);
+
+ dxContext->Unmap(mBuffer, 0);
+
+ return gl::Error(GL_NO_ERROR);
}
-bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count,
- GLsizei instances, unsigned int *outSpaceRequired) const
+gl::Error VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count,
+ GLsizei instances, unsigned int *outSpaceRequired) const
{
unsigned int elementCount = 0;
if (attrib.enabled)
@@ -148,11 +145,11 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei
{
*outSpaceRequired = elementSize * elementCount;
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
else
{
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "New vertex buffer size would result in an overflow.");
}
}
else
@@ -162,7 +159,7 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei
{
*outSpaceRequired = elementSize * 4;
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
}
@@ -171,7 +168,7 @@ unsigned int VertexBuffer11::getBufferSize() const
return mBufferSize;
}
-bool VertexBuffer11::setBufferSize(unsigned int size)
+gl::Error VertexBuffer11::setBufferSize(unsigned int size)
{
if (size > mBufferSize)
{
@@ -179,33 +176,29 @@ bool VertexBuffer11::setBufferSize(unsigned int size)
}
else
{
- return true;
+ return gl::Error(GL_NO_ERROR);
}
}
-bool VertexBuffer11::discard()
+gl::Error VertexBuffer11::discard()
{
- if (mBuffer)
+ if (!mBuffer)
{
- ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
-
- D3D11_MAPPED_SUBRESOURCE mappedResource;
- HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
- if (FAILED(result))
- {
- ERR("Vertex buffer map failed with error 0x%08x", result);
- return false;
- }
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
+ }
- dxContext->Unmap(mBuffer, 0);
+ ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
- return true;
- }
- else
+ D3D11_MAPPED_SUBRESOURCE mappedResource;
+ HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+ if (FAILED(result))
{
- ERR("Vertex buffer not initialized.");
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer for discarding, HRESULT: 0x%08x", result);
}
+
+ dxContext->Unmap(mBuffer, 0);
+
+ return gl::Error(GL_NO_ERROR);
}
ID3D11Buffer *VertexBuffer11::getBuffer() const
diff --git a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.h b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.h
index c2a5aa7a..0e10da1d 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.h
+++ b/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.h
@@ -21,19 +21,19 @@ class VertexBuffer11 : public VertexBuffer
explicit VertexBuffer11(rx::Renderer11 *const renderer);
virtual ~VertexBuffer11();
- virtual bool initialize(unsigned int size, bool dynamicUsage);
+ virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
static VertexBuffer11 *makeVertexBuffer11(VertexBuffer *vetexBuffer);
- virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int offset);
+ virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int offset);
- virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
- unsigned int *outSpaceRequired) const;
+ virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
+ unsigned int *outSpaceRequired) const;
virtual unsigned int getBufferSize() const;
- virtual bool setBufferSize(unsigned int size);
- virtual bool discard();
+ virtual gl::Error setBufferSize(unsigned int size);
+ virtual gl::Error discard();
ID3D11Buffer *getBuffer() const;
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
index deea35b5..7a3c3509 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
@@ -1260,14 +1260,14 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
return true;
}
-GLenum Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances)
+gl::Error Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
+ GLint first, GLsizei count, GLsizei instances)
{
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
- GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances);
- if (err != GL_NO_ERROR)
+ gl::Error error = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances);
+ if (error.isError())
{
- return err;
+ return error;
}
return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, programBinary, instances, &mRepeatDraw);
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h
index c7c3dde3..c23ce89b 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h
+++ b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h
@@ -81,8 +81,8 @@ class Renderer9 : public Renderer
bool rasterizerDiscard, bool transformFeedbackActive);
virtual void applyUniforms(const gl::ProgramBinary &programBinary);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
- virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances);
+ virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
+ GLint first, GLsizei count, GLsizei instances);
virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]);
diff --git a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
index 7a20db3d..4cf77791 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp
@@ -29,7 +29,7 @@ VertexBuffer9::~VertexBuffer9()
SafeRelease(mVertexBuffer);
}
-bool VertexBuffer9::initialize(unsigned int size, bool dynamicUsage)
+gl::Error VertexBuffer9::initialize(unsigned int size, bool dynamicUsage)
{
SafeRelease(mVertexBuffer);
@@ -47,14 +47,13 @@ bool VertexBuffer9::initialize(unsigned int size, bool dynamicUsage)
if (FAILED(result))
{
- ERR("Out of memory allocating a vertex buffer of size %lu.", size);
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate internal vertex buffer of size, %lu.", size);
}
}
mBufferSize = size;
mDynamicUsage = dynamicUsage;
- return true;
+ return gl::Error(GL_NO_ERROR);
}
VertexBuffer9 *VertexBuffer9::makeVertexBuffer9(VertexBuffer *vertexBuffer)
@@ -63,84 +62,80 @@ VertexBuffer9 *VertexBuffer9::makeVertexBuffer9(VertexBuffer *vertexBuffer)
return static_cast<VertexBuffer9*>(vertexBuffer);
}
-bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int offset)
+gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int offset)
{
- if (mVertexBuffer)
+ if (!mVertexBuffer)
{
- gl::Buffer *buffer = attrib.buffer.get();
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
+ }
- int inputStride = gl::ComputeVertexAttributeStride(attrib);
- int elementSize = gl::ComputeVertexAttributeTypeSize(attrib);
+ gl::Buffer *buffer = attrib.buffer.get();
- DWORD lockFlags = mDynamicUsage ? D3DLOCK_NOOVERWRITE : 0;
+ int inputStride = gl::ComputeVertexAttributeStride(attrib);
+ int elementSize = gl::ComputeVertexAttributeTypeSize(attrib);
- uint8_t *mapPtr = NULL;
+ DWORD lockFlags = mDynamicUsage ? D3DLOCK_NOOVERWRITE : 0;
- unsigned int mapSize;
- if (!spaceRequired(attrib, count, instances, &mapSize))
- {
- return false;
- }
+ uint8_t *mapPtr = NULL;
- HRESULT result = mVertexBuffer->Lock(offset, mapSize, reinterpret_cast<void**>(&mapPtr), lockFlags);
+ unsigned int mapSize;
+ gl::Error error = spaceRequired(attrib, count, instances, &mapSize);
+ if (error.isError())
+ {
+ return error;
+ }
- if (FAILED(result))
- {
- ERR("Lock failed with error 0x%08x", result);
- return false;
- }
+ HRESULT result = mVertexBuffer->Lock(offset, mapSize, reinterpret_cast<void**>(&mapPtr), lockFlags);
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal vertex buffer, HRESULT: 0x%08x.", result);
+ }
- const uint8_t *input = NULL;
- if (attrib.enabled)
+ const uint8_t *input = NULL;
+ if (attrib.enabled)
+ {
+ if (buffer)
{
- if (buffer)
- {
- BufferImpl *storage = buffer->getImplementation();
- input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
- }
- else
- {
- input = static_cast<const uint8_t*>(attrib.pointer);
- }
+ BufferImpl *storage = buffer->getImplementation();
+ input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
}
else
{
- input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
- }
-
- if (instances == 0 || attrib.divisor == 0)
- {
- input += inputStride * start;
+ input = static_cast<const uint8_t*>(attrib.pointer);
}
+ }
+ else
+ {
+ input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
+ }
- gl::VertexFormat vertexFormat(attrib, currentValue.Type);
- const d3d9::VertexFormat &d3dVertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat);
- bool needsConversion = (d3dVertexInfo.conversionType & VERTEX_CONVERT_CPU) > 0;
-
- if (!needsConversion && inputStride == elementSize)
- {
- size_t copySize = static_cast<size_t>(count) * static_cast<size_t>(inputStride);
- memcpy(mapPtr, input, copySize);
- }
- else
- {
- d3dVertexInfo.copyFunction(input, inputStride, count, mapPtr);
- }
+ if (instances == 0 || attrib.divisor == 0)
+ {
+ input += inputStride * start;
+ }
- mVertexBuffer->Unlock();
+ gl::VertexFormat vertexFormat(attrib, currentValue.Type);
+ const d3d9::VertexFormat &d3dVertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat);
+ bool needsConversion = (d3dVertexInfo.conversionType & VERTEX_CONVERT_CPU) > 0;
- return true;
+ if (!needsConversion && inputStride == elementSize)
+ {
+ size_t copySize = static_cast<size_t>(count) * static_cast<size_t>(inputStride);
+ memcpy(mapPtr, input, copySize);
}
else
{
- ERR("Vertex buffer not initialized.");
- return false;
+ d3dVertexInfo.copyFunction(input, inputStride, count, mapPtr);
}
+
+ mVertexBuffer->Unlock();
+
+ return gl::Error(GL_NO_ERROR);
}
-bool VertexBuffer9::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
- unsigned int *outSpaceRequired) const
+gl::Error VertexBuffer9::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
+ unsigned int *outSpaceRequired) const
{
return spaceRequired(attrib, count, instances, outSpaceRequired);
}
@@ -150,7 +145,7 @@ unsigned int VertexBuffer9::getBufferSize() const
return mBufferSize;
}
-bool VertexBuffer9::setBufferSize(unsigned int size)
+gl::Error VertexBuffer9::setBufferSize(unsigned int size)
{
if (size > mBufferSize)
{
@@ -158,38 +153,33 @@ bool VertexBuffer9::setBufferSize(unsigned int size)
}
else
{
- return true;
+ return gl::Error(GL_NO_ERROR);
}
}
-bool VertexBuffer9::discard()
+gl::Error VertexBuffer9::discard()
{
- if (mVertexBuffer)
+ if (!mVertexBuffer)
{
- void *dummy;
- HRESULT result;
-
- result = mVertexBuffer->Lock(0, 1, &dummy, D3DLOCK_DISCARD);
- if (FAILED(result))
- {
- ERR("Discard lock failed with error 0x%08x", result);
- return false;
- }
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
+ }
- result = mVertexBuffer->Unlock();
- if (FAILED(result))
- {
- ERR("Discard unlock failed with error 0x%08x", result);
- return false;
- }
+ void *dummy;
+ HRESULT result;
- return true;
+ result = mVertexBuffer->Lock(0, 1, &dummy, D3DLOCK_DISCARD);
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal buffer for discarding, HRESULT: 0x%08x", result);
}
- else
+
+ result = mVertexBuffer->Unlock();
+ if (FAILED(result))
{
- ERR("Vertex buffer not initialized.");
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to unlock internal buffer for discarding, HRESULT: 0x%08x", result);
}
+
+ return gl::Error(GL_NO_ERROR);
}
IDirect3DVertexBuffer9 * VertexBuffer9::getBuffer() const
@@ -197,8 +187,8 @@ IDirect3DVertexBuffer9 * VertexBuffer9::getBuffer() const
return mVertexBuffer;
}
-bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances,
- unsigned int *outSpaceRequired) const
+gl::Error VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances,
+ unsigned int *outSpaceRequired) const
{
gl::VertexFormat vertexFormat(attrib, GL_FLOAT);
const d3d9::VertexFormat &d3d9VertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat);
@@ -222,11 +212,11 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t
{
*outSpaceRequired = d3d9VertexInfo.outputElementSize * elementCount;
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
else
{
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "New vertex buffer size would result in an overflow.");
}
}
else
@@ -236,7 +226,7 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t
{
*outSpaceRequired = elementSize * 4;
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
}
diff --git a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.h b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.h
index 6bde0cde..bdcf4bb6 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.h
+++ b/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.h
@@ -21,18 +21,18 @@ class VertexBuffer9 : public VertexBuffer
explicit VertexBuffer9(rx::Renderer9 *renderer);
virtual ~VertexBuffer9();
- virtual bool initialize(unsigned int size, bool dynamicUsage);
+ virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
static VertexBuffer9 *makeVertexBuffer9(VertexBuffer *vertexBuffer);
- virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
- GLint start, GLsizei count, GLsizei instances, unsigned int offset);
+ virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int offset);
- virtual bool getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, unsigned int *outSpaceRequired) const;
+ virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, unsigned int *outSpaceRequired) const;
virtual unsigned int getBufferSize() const;
- virtual bool setBufferSize(unsigned int size);
- virtual bool discard();
+ virtual gl::Error setBufferSize(unsigned int size);
+ virtual gl::Error discard();
IDirect3DVertexBuffer9 *getBuffer() const;
@@ -45,8 +45,8 @@ class VertexBuffer9 : public VertexBuffer
unsigned int mBufferSize;
bool mDynamicUsage;
- bool spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances,
- unsigned int *outSpaceRequired) const;
+ gl::Error spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances,
+ unsigned int *outSpaceRequired) const;
};
}
diff --git a/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.cpp b/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.cpp
index d0d72c01..cefd786f 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.cpp
@@ -40,7 +40,7 @@ VertexDeclarationCache::~VertexDeclarationCache()
}
}
-GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw)
+gl::Error VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw)
{
*repeatDraw = 1;
@@ -188,7 +188,7 @@ GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, Transl
mLastSetVDecl = entry->vertexDeclaration;
}
- return GL_NO_ERROR;
+ return gl::Error(GL_NO_ERROR);
}
}
@@ -210,12 +210,17 @@ GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, Transl
}
memcpy(lastCache->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9));
- device->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration);
+ HRESULT result = device->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration);
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal vertex declaration, result: 0x%X.", result);
+ }
+
device->SetVertexDeclaration(lastCache->vertexDeclaration);
mLastSetVDecl = lastCache->vertexDeclaration;
lastCache->lruCount = ++mMaxLru;
- return GL_NO_ERROR;
+ return gl::Error(GL_NO_ERROR);
}
void VertexDeclarationCache::markStateDirty()
diff --git a/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.h b/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.h
index 004e28df..9af36e0d 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.h
+++ b/src/libGLESv2/renderer/d3d/d3d9/VertexDeclarationCache.h
@@ -9,6 +9,7 @@
#ifndef LIBGLESV2_RENDERER_VERTEXDECLARATIONCACHE_H_
#define LIBGLESV2_RENDERER_VERTEXDECLARATIONCACHE_H_
+#include "libGLESv2/Error.h"
#include "libGLESv2/renderer/d3d/VertexDataManager.h"
namespace gl
@@ -25,7 +26,7 @@ class VertexDeclarationCache
VertexDeclarationCache();
~VertexDeclarationCache();
- GLenum applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw);
+ gl::Error applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw);
void markStateDirty();