aboutsummaryrefslogtreecommitdiff
path: root/src/libGLESv2/renderer/d3d/d3d9
diff options
context:
space:
mode:
Diffstat (limited to 'src/libGLESv2/renderer/d3d/d3d9')
-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
6 files changed, 103 insertions, 107 deletions
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();