Commit c77e8c39 by Geoff Lang

Update the draw calls to return Error objects.

BUG=angle:520 Change-Id: I3330ba2dbe095fc9460789822a938420a80a149f Reviewed-on: https://chromium-review.googlesource.com/213823Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 3110ffdc
...@@ -1310,12 +1310,16 @@ bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned ...@@ -1310,12 +1310,16 @@ bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned
// Applies the render target surface, depth stencil surface, viewport rectangle and // Applies the render target surface, depth stencil surface, viewport rectangle and
// scissor rectangle to the renderer // scissor rectangle to the renderer
void Context::applyRenderTarget(GLenum drawMode, bool ignoreViewport) Error Context::applyRenderTarget(GLenum drawMode, bool ignoreViewport)
{ {
Framebuffer *framebufferObject = mState.getDrawFramebuffer(); Framebuffer *framebufferObject = mState.getDrawFramebuffer();
ASSERT(framebufferObject && framebufferObject->completeness() == GL_FRAMEBUFFER_COMPLETE); ASSERT(framebufferObject && framebufferObject->completeness() == GL_FRAMEBUFFER_COMPLETE);
mRenderer->applyRenderTarget(framebufferObject); gl::Error error = mRenderer->applyRenderTarget(framebufferObject);
if (error.isError())
{
return error;
}
float nearZ, farZ; float nearZ, farZ;
mState.getDepthRange(&nearZ, &farZ); mState.getDepthRange(&nearZ, &farZ);
...@@ -1323,10 +1327,12 @@ void Context::applyRenderTarget(GLenum drawMode, bool ignoreViewport) ...@@ -1323,10 +1327,12 @@ void Context::applyRenderTarget(GLenum drawMode, bool ignoreViewport)
ignoreViewport); ignoreViewport);
mRenderer->setScissorRectangle(mState.getScissor(), mState.isScissorTestEnabled()); mRenderer->setScissorRectangle(mState.getScissor(), mState.isScissorTestEnabled());
return gl::Error(GL_NO_ERROR);
} }
// Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device
void Context::applyState(GLenum drawMode) Error Context::applyState(GLenum drawMode)
{ {
Framebuffer *framebufferObject = mState.getDrawFramebuffer(); Framebuffer *framebufferObject = mState.getDrawFramebuffer();
int samples = framebufferObject->getSamples(); int samples = framebufferObject->getSamples();
...@@ -1335,7 +1341,11 @@ void Context::applyState(GLenum drawMode) ...@@ -1335,7 +1341,11 @@ void Context::applyState(GLenum drawMode)
rasterizer.pointDrawMode = (drawMode == GL_POINTS); rasterizer.pointDrawMode = (drawMode == GL_POINTS);
rasterizer.multiSample = (samples != 0); rasterizer.multiSample = (samples != 0);
mRenderer->setRasterizerState(rasterizer); Error error = mRenderer->setRasterizerState(rasterizer);
if (error.isError())
{
return error;
}
unsigned int mask = 0; unsigned int mask = 0;
if (mState.isSampleCoverageEnabled()) if (mState.isSampleCoverageEnabled())
...@@ -1345,7 +1355,6 @@ void Context::applyState(GLenum drawMode) ...@@ -1345,7 +1355,6 @@ void Context::applyState(GLenum drawMode)
mState.getSampleCoverageParams(&coverageValue, &coverageInvert); mState.getSampleCoverageParams(&coverageValue, &coverageInvert);
if (coverageValue != 0) if (coverageValue != 0)
{ {
float threshold = 0.5f; float threshold = 0.5f;
for (int i = 0; i < samples; ++i) for (int i = 0; i < samples; ++i)
...@@ -1369,14 +1378,24 @@ void Context::applyState(GLenum drawMode) ...@@ -1369,14 +1378,24 @@ void Context::applyState(GLenum drawMode)
{ {
mask = 0xFFFFFFFF; mask = 0xFFFFFFFF;
} }
mRenderer->setBlendState(framebufferObject, mState.getBlendState(), mState.getBlendColor(), mask); error = mRenderer->setBlendState(framebufferObject, mState.getBlendState(), mState.getBlendColor(), mask);
if (error.isError())
{
return error;
}
mRenderer->setDepthStencilState(mState.getDepthStencilState(), mState.getStencilRef(), mState.getStencilBackRef(), error = mRenderer->setDepthStencilState(mState.getDepthStencilState(), mState.getStencilRef(), mState.getStencilBackRef(),
rasterizer.frontFace == GL_CCW); rasterizer.frontFace == GL_CCW);
if (error.isError())
{
return error;
}
return Error(GL_NO_ERROR);
} }
// Applies the shaders and shader constants to the Direct3D 9 device // Applies the shaders and shader constants to the Direct3D 9 device
void Context::applyShaders(ProgramBinary *programBinary, bool transformFeedbackActive) Error Context::applyShaders(ProgramBinary *programBinary, bool transformFeedbackActive)
{ {
const VertexAttribute *vertexAttributes = mState.getVertexArray()->getVertexAttributes(); const VertexAttribute *vertexAttributes = mState.getVertexArray()->getVertexAttributes();
...@@ -1385,9 +1404,13 @@ void Context::applyShaders(ProgramBinary *programBinary, bool transformFeedbackA ...@@ -1385,9 +1404,13 @@ void Context::applyShaders(ProgramBinary *programBinary, bool transformFeedbackA
const Framebuffer *fbo = mState.getDrawFramebuffer(); const Framebuffer *fbo = mState.getDrawFramebuffer();
mRenderer->applyShaders(programBinary, inputLayout, fbo, mState.getRasterizerState().rasterizerDiscard, transformFeedbackActive); Error error = mRenderer->applyShaders(programBinary, inputLayout, fbo, mState.getRasterizerState().rasterizerDiscard, transformFeedbackActive);
if (error.isError())
{
return error;
}
programBinary->applyUniforms(); return programBinary->applyUniforms();
} }
Error Context::generateSwizzles(ProgramBinary *programBinary, SamplerType type) Error Context::generateSwizzles(ProgramBinary *programBinary, SamplerType type)
...@@ -1435,7 +1458,7 @@ Error Context::generateSwizzles(ProgramBinary *programBinary) ...@@ -1435,7 +1458,7 @@ Error Context::generateSwizzles(ProgramBinary *programBinary)
// For each Direct3D sampler of either the pixel or vertex stage, // For each Direct3D sampler of either the pixel or vertex stage,
// looks up the corresponding OpenGL texture image unit and texture type, // looks up the corresponding OpenGL texture image unit and texture type,
// and sets the texture and its addressing/filtering state (or NULL when inactive). // and sets the texture and its addressing/filtering state (or NULL when inactive).
void Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderType, Error Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderType,
const FramebufferTextureSerialArray &framebufferSerials, size_t framebufferSerialCount) const FramebufferTextureSerialArray &framebufferSerials, size_t framebufferSerialCount)
{ {
size_t samplerRange = programBinary->getUsedSamplerRange(shaderType); size_t samplerRange = programBinary->getUsedSamplerRange(shaderType);
...@@ -1459,20 +1482,37 @@ void Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderType ...@@ -1459,20 +1482,37 @@ void Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderType
if (texture->isSamplerComplete(sampler, mTextureCaps, mExtensions, mClientVersion) && if (texture->isSamplerComplete(sampler, mTextureCaps, mExtensions, mClientVersion) &&
!std::binary_search(framebufferSerials.begin(), framebufferSerials.begin() + framebufferSerialCount, texture->getTextureSerial())) !std::binary_search(framebufferSerials.begin(), framebufferSerials.begin() + framebufferSerialCount, texture->getTextureSerial()))
{ {
mRenderer->setSamplerState(shaderType, samplerIndex, sampler); Error error = mRenderer->setSamplerState(shaderType, samplerIndex, sampler);
mRenderer->setTexture(shaderType, samplerIndex, texture); if (error.isError())
{
return error;
}
error = mRenderer->setTexture(shaderType, samplerIndex, texture);
if (error.isError())
{
return error;
}
} }
else else
{ {
// Texture is not sampler complete or it is in use by the framebuffer. Bind the incomplete texture. // Texture is not sampler complete or it is in use by the framebuffer. Bind the incomplete texture.
Texture *incompleteTexture = getIncompleteTexture(textureType); Texture *incompleteTexture = getIncompleteTexture(textureType);
mRenderer->setTexture(shaderType, samplerIndex, incompleteTexture); gl::Error error = mRenderer->setTexture(shaderType, samplerIndex, incompleteTexture);
if (error.isError())
{
return error;
}
} }
} }
else else
{ {
// No texture bound to this slot even though it is used by the shader, bind a NULL texture // No texture bound to this slot even though it is used by the shader, bind a NULL texture
mRenderer->setTexture(shaderType, samplerIndex, NULL); Error error = mRenderer->setTexture(shaderType, samplerIndex, NULL);
if (error.isError())
{
return error;
}
} }
} }
...@@ -1481,20 +1521,37 @@ void Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderType ...@@ -1481,20 +1521,37 @@ void Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderType
: mCaps.maxVertexTextureImageUnits; : mCaps.maxVertexTextureImageUnits;
for (size_t samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++) for (size_t samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++)
{ {
mRenderer->setTexture(shaderType, samplerIndex, NULL); Error error = mRenderer->setTexture(shaderType, samplerIndex, NULL);
if (error.isError())
{
return error;
} }
}
return Error(GL_NO_ERROR);
} }
void Context::applyTextures(ProgramBinary *programBinary) Error Context::applyTextures(ProgramBinary *programBinary)
{ {
FramebufferTextureSerialArray framebufferSerials; FramebufferTextureSerialArray framebufferSerials;
size_t framebufferSerialCount = getBoundFramebufferTextureSerials(&framebufferSerials); size_t framebufferSerialCount = getBoundFramebufferTextureSerials(&framebufferSerials);
applyTextures(programBinary, SAMPLER_VERTEX, framebufferSerials, framebufferSerialCount); Error error = applyTextures(programBinary, SAMPLER_VERTEX, framebufferSerials, framebufferSerialCount);
applyTextures(programBinary, SAMPLER_PIXEL, framebufferSerials, framebufferSerialCount); if (error.isError())
{
return error;
}
error = applyTextures(programBinary, SAMPLER_PIXEL, framebufferSerials, framebufferSerialCount);
if (error.isError())
{
return error;
}
return Error(GL_NO_ERROR);
} }
bool Context::applyUniformBuffers() Error Context::applyUniformBuffers()
{ {
Program *programObject = getProgram(mState.getCurrentProgramId()); Program *programObject = getProgram(mState.getCurrentProgramId());
ProgramBinary *programBinary = programObject->getProgramBinary(); ProgramBinary *programBinary = programObject->getProgramBinary();
...@@ -1508,7 +1565,7 @@ bool Context::applyUniformBuffers() ...@@ -1508,7 +1565,7 @@ bool Context::applyUniformBuffers()
if (mState.getIndexedUniformBuffer(blockBinding)->id() == 0) if (mState.getIndexedUniformBuffer(blockBinding)->id() == 0)
{ {
// undefined behaviour // undefined behaviour
return false; return gl::Error(GL_INVALID_OPERATION, "It is undefined behaviour to have a used but unbound uniform buffer.");
} }
else else
{ {
...@@ -1683,7 +1740,7 @@ Error Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -1683,7 +1740,7 @@ Error Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
reinterpret_cast<uint8_t*>(pixels)); reinterpret_cast<uint8_t*>(pixels));
} }
void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances) Error Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances)
{ {
ASSERT(mState.getCurrentProgramId() != 0); ASSERT(mState.getCurrentProgramId() != 0);
...@@ -1693,46 +1750,70 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan ...@@ -1693,46 +1750,70 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
Error error = generateSwizzles(programBinary); Error error = generateSwizzles(programBinary);
if (error.isError()) if (error.isError())
{ {
return gl::error(error.getCode()); return error;
} }
if (!mRenderer->applyPrimitiveType(mode, count)) if (!mRenderer->applyPrimitiveType(mode, count))
{ {
return; return Error(GL_NO_ERROR);
} }
applyRenderTarget(mode, false); error = applyRenderTarget(mode, false);
applyState(mode); if (error.isError())
{
return error;
}
error = applyState(mode);
if (error.isError())
{
return error;
}
error = mRenderer->applyVertexBuffer(programBinary, mState.getVertexArray()->getVertexAttributes(), mState.getVertexAttribCurrentValues(), first, count, instances); error = mRenderer->applyVertexBuffer(programBinary, mState.getVertexArray()->getVertexAttributes(), mState.getVertexAttribCurrentValues(), first, count, instances);
if (error.isError()) if (error.isError())
{ {
return gl::error(error.getCode()); return error;
} }
bool transformFeedbackActive = applyTransformFeedbackBuffers(); bool transformFeedbackActive = applyTransformFeedbackBuffers();
applyShaders(programBinary, transformFeedbackActive); error = applyShaders(programBinary, transformFeedbackActive);
if (error.isError())
{
return error;
}
applyTextures(programBinary); error = applyTextures(programBinary);
if (error.isError())
{
return error;
}
if (!applyUniformBuffers()) error = applyUniformBuffers();
if (error.isError())
{ {
return; return error;
} }
if (!skipDraw(mode)) if (!skipDraw(mode))
{ {
mRenderer->drawArrays(mode, count, instances, transformFeedbackActive); error = mRenderer->drawArrays(mode, count, instances, transformFeedbackActive);
if (error.isError())
{
return error;
}
if (transformFeedbackActive) if (transformFeedbackActive)
{ {
markTransformFeedbackUsage(); markTransformFeedbackUsage();
} }
} }
return gl::Error(GL_NO_ERROR);
} }
void Context::drawElements(GLenum mode, GLsizei count, GLenum type, Error Context::drawElements(GLenum mode, GLsizei count, GLenum type,
const GLvoid *indices, GLsizei instances, const GLvoid *indices, GLsizei instances,
const rx::RangeUI &indexRange) const rx::RangeUI &indexRange)
{ {
...@@ -1744,16 +1825,25 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, ...@@ -1744,16 +1825,25 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type,
Error error = generateSwizzles(programBinary); Error error = generateSwizzles(programBinary);
if (error.isError()) if (error.isError())
{ {
return gl::error(error.getCode()); return error;
} }
if (!mRenderer->applyPrimitiveType(mode, count)) if (!mRenderer->applyPrimitiveType(mode, count))
{ {
return; return Error(GL_NO_ERROR);
} }
applyRenderTarget(mode, false); error = applyRenderTarget(mode, false);
applyState(mode); if (error.isError())
{
return error;
}
error = applyState(mode);
if (error.isError())
{
return error;
}
VertexArray *vao = mState.getVertexArray(); VertexArray *vao = mState.getVertexArray();
rx::TranslatedIndexData indexInfo; rx::TranslatedIndexData indexInfo;
...@@ -1761,7 +1851,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, ...@@ -1761,7 +1851,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type,
error = mRenderer->applyIndexBuffer(indices, vao->getElementArrayBuffer(), count, mode, type, &indexInfo); error = mRenderer->applyIndexBuffer(indices, vao->getElementArrayBuffer(), count, mode, type, &indexInfo);
if (error.isError()) if (error.isError())
{ {
return gl::error(error.getCode()); return error;
} }
GLsizei vertexCount = indexInfo.indexRange.length() + 1; GLsizei vertexCount = indexInfo.indexRange.length() + 1;
...@@ -1770,7 +1860,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, ...@@ -1770,7 +1860,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type,
indexInfo.indexRange.start, vertexCount, instances); indexInfo.indexRange.start, vertexCount, instances);
if (error.isError()) if (error.isError())
{ {
return gl::error(error.getCode()); return error;
} }
bool transformFeedbackActive = applyTransformFeedbackBuffers(); bool transformFeedbackActive = applyTransformFeedbackBuffers();
...@@ -1778,19 +1868,34 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, ...@@ -1778,19 +1868,34 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type,
// layer. // layer.
ASSERT(!transformFeedbackActive); ASSERT(!transformFeedbackActive);
applyShaders(programBinary, transformFeedbackActive); error = applyShaders(programBinary, transformFeedbackActive);
if (error.isError())
{
return error;
}
applyTextures(programBinary); error = applyTextures(programBinary);
if (error.isError())
{
return error;
}
if (!applyUniformBuffers()) error = applyUniformBuffers();
if (error.isError())
{ {
return; return error;
} }
if (!skipDraw(mode)) if (!skipDraw(mode))
{ {
mRenderer->drawElements(mode, count, type, indices, vao->getElementArrayBuffer(), indexInfo, instances); error = mRenderer->drawElements(mode, count, type, indices, vao->getElementArrayBuffer(), indexInfo, instances);
if (error.isError())
{
return error;
} }
}
return Error(GL_NO_ERROR);
} }
// Implements glFlush when block is false, glFinish when block is true // Implements glFlush when block is false, glFinish when block is true
......
...@@ -189,8 +189,8 @@ class Context ...@@ -189,8 +189,8 @@ class Context
Error clearBufferfi(GLenum buffer, int drawbuffer, float depth, int stencil); Error clearBufferfi(GLenum buffer, int drawbuffer, float depth, int stencil);
Error readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels); Error readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances); Error drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances);
void drawElements(GLenum mode, GLsizei count, GLenum type, Error drawElements(GLenum mode, GLsizei count, GLenum type,
const GLvoid *indices, GLsizei instances, const GLvoid *indices, GLsizei instances,
const rx::RangeUI &indexRange); const rx::RangeUI &indexRange);
void sync(bool block); // flush/finish void sync(bool block); // flush/finish
...@@ -231,13 +231,13 @@ class Context ...@@ -231,13 +231,13 @@ class Context
// TODO: std::array may become unavailable using older versions of GCC // TODO: std::array may become unavailable using older versions of GCC
typedef std::array<unsigned int, IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS> FramebufferTextureSerialArray; typedef std::array<unsigned int, IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS> FramebufferTextureSerialArray;
void applyRenderTarget(GLenum drawMode, bool ignoreViewport); Error applyRenderTarget(GLenum drawMode, bool ignoreViewport);
void applyState(GLenum drawMode); Error applyState(GLenum drawMode);
void applyShaders(ProgramBinary *programBinary, bool transformFeedbackActive); Error applyShaders(ProgramBinary *programBinary, bool transformFeedbackActive);
void applyTextures(ProgramBinary *programBinary, SamplerType shaderType, const FramebufferTextureSerialArray &framebufferSerials, Error applyTextures(ProgramBinary *programBinary, SamplerType shaderType, const FramebufferTextureSerialArray &framebufferSerials,
size_t framebufferSerialCount); size_t framebufferSerialCount);
void applyTextures(ProgramBinary *programBinary); Error applyTextures(ProgramBinary *programBinary);
bool applyUniformBuffers(); Error applyUniformBuffers();
bool applyTransformFeedbackBuffers(); bool applyTransformFeedbackBuffers();
void markTransformFeedbackUsage(); void markTransformFeedbackUsage();
......
...@@ -970,19 +970,25 @@ void ProgramBinary::updateSamplerMapping() ...@@ -970,19 +970,25 @@ void ProgramBinary::updateSamplerMapping()
} }
// Applies all the uniforms set for this program object to the renderer // Applies all the uniforms set for this program object to the renderer
void ProgramBinary::applyUniforms() Error ProgramBinary::applyUniforms()
{ {
updateSamplerMapping(); updateSamplerMapping();
mProgram->getRenderer()->applyUniforms(*this); Error error = mProgram->getRenderer()->applyUniforms(*this);
if (error.isError())
{
return error;
}
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++) for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
{ {
mUniforms[uniformIndex]->dirty = false; mUniforms[uniformIndex]->dirty = false;
} }
return gl::Error(GL_NO_ERROR);
} }
bool ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const Caps &caps) Error ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const Caps &caps)
{ {
const gl::Buffer *vertexUniformBuffers[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS] = {NULL}; const gl::Buffer *vertexUniformBuffers[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS] = {NULL};
const gl::Buffer *fragmentUniformBuffers[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS] = {NULL}; const gl::Buffer *fragmentUniformBuffers[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS] = {NULL};
...@@ -1002,7 +1008,7 @@ bool ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuff ...@@ -1002,7 +1008,7 @@ bool ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuff
if (uniformBuffer->getSize() < uniformBlock->dataSize) if (uniformBuffer->getSize() < uniformBlock->dataSize)
{ {
// undefined behaviour // undefined behaviour
return false; return gl::Error(GL_INVALID_OPERATION, "It is undefined behaviour to use a uniform buffer that is too small.");
} }
// Unnecessary to apply an unreferenced standard or shared UBO // Unnecessary to apply an unreferenced standard or shared UBO
......
...@@ -146,8 +146,9 @@ class ProgramBinary : public RefCountObject ...@@ -146,8 +146,9 @@ class ProgramBinary : public RefCountObject
void getUniformuiv(GLint location, GLuint *params); void getUniformuiv(GLint location, GLuint *params);
void dirtyAllUniforms(); void dirtyAllUniforms();
void applyUniforms();
bool applyUniformBuffers(const std::vector<Buffer*> boundBuffers, const Caps &caps); Error applyUniforms();
Error applyUniformBuffers(const std::vector<Buffer*> boundBuffers, const Caps &caps);
bool load(InfoLog &infoLog, GLenum binaryFormat, const void *binary, GLsizei length); bool load(InfoLog &infoLog, GLenum binaryFormat, const void *binary, GLsizei length);
bool save(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length); bool save(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length);
......
...@@ -1343,7 +1343,12 @@ void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -1343,7 +1343,12 @@ void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
return; return;
} }
context->drawArrays(mode, first, count, 0); gl::Error error = context->drawArrays(mode, first, count, 0);
if (error.isError())
{
context->recordError(error);
return;
}
} }
} }
...@@ -1359,7 +1364,12 @@ void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei coun ...@@ -1359,7 +1364,12 @@ void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei coun
return; return;
} }
context->drawArrays(mode, first, count, primcount); gl::Error error = context->drawArrays(mode, first, count, primcount);
if (error.isError())
{
context->recordError(error);
return;
}
} }
} }
...@@ -1377,7 +1387,12 @@ void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLv ...@@ -1377,7 +1387,12 @@ void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLv
return; return;
} }
context->drawElements(mode, count, type, indices, 0, indexRange); gl::Error error = context->drawElements(mode, count, type, indices, 0, indexRange);
if (error.isError())
{
context->recordError(error);
return;
}
} }
} }
...@@ -1395,7 +1410,12 @@ void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum t ...@@ -1395,7 +1410,12 @@ void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum t
return; return;
} }
context->drawElements(mode, count, type, indices, primcount, indexRange); gl::Error error = context->drawElements(mode, count, type, indices, primcount, indexRange);
if (error.isError())
{
context->recordError(error);
return;
}
} }
} }
......
...@@ -110,33 +110,33 @@ class Renderer ...@@ -110,33 +110,33 @@ class Renderer
virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0; virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
virtual gl::Error generateSwizzle(gl::Texture *texture) = 0; virtual gl::Error generateSwizzle(gl::Texture *texture) = 0;
virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0; virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0; virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0; virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0;
virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0; virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState) = 0;
virtual void setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor, virtual gl::Error setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
unsigned int sampleMask) = 0; unsigned int sampleMask) = 0;
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW) = 0; int stencilBackRef, bool frontFaceCCW) = 0;
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0; virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
virtual void setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, virtual void setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport) = 0; bool ignoreViewport) = 0;
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0; virtual gl::Error applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
virtual void applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, virtual gl::Error applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive) = 0; bool rasterizerDiscard, bool transformFeedbackActive) = 0;
virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0; virtual gl::Error applyUniforms(const gl::ProgramBinary &programBinary) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0; virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances) = 0; 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 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; virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) = 0;
virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) = 0; virtual gl::Error drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) = 0;
virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, virtual gl::Error drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0; gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0; virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
......
...@@ -436,7 +436,7 @@ gl::Error Renderer11::generateSwizzle(gl::Texture *texture) ...@@ -436,7 +436,7 @@ gl::Error Renderer11::generateSwizzle(gl::Texture *texture)
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
{ {
if (type == gl::SAMPLER_PIXEL) if (type == gl::SAMPLER_PIXEL)
{ {
...@@ -448,11 +448,10 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp ...@@ -448,11 +448,10 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp
gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState); gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
if (error.isError()) if (error.isError())
{ {
ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" return error;
"sampler state for pixel shaders at slot %i.", index);
dxSamplerState = NULL;
} }
ASSERT(dxSamplerState != NULL);
mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState); mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState);
mCurPixelSamplerStates[index] = samplerState; mCurPixelSamplerStates[index] = samplerState;
...@@ -470,11 +469,10 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp ...@@ -470,11 +469,10 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp
gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState); gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
if (error.isError()) if (error.isError())
{ {
ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" return error;
"sampler state for vertex shaders at slot %i.", index);
dxSamplerState = NULL;
} }
ASSERT(dxSamplerState != NULL);
mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState); mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState);
mCurVertexSamplerStates[index] = samplerState; mCurVertexSamplerStates[index] = samplerState;
...@@ -483,9 +481,11 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp ...@@ -483,9 +481,11 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp
mForceSetVertexSamplerStates[index] = false; mForceSetVertexSamplerStates[index] = false;
} }
else UNREACHABLE(); else UNREACHABLE();
return gl::Error(GL_NO_ERROR);
} }
void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture)
{ {
ID3D11ShaderResourceView *textureSRV = NULL; ID3D11ShaderResourceView *textureSRV = NULL;
bool forceSetTexture = false; bool forceSetTexture = false;
...@@ -493,15 +493,13 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur ...@@ -493,15 +493,13 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur
if (texture) if (texture)
{ {
TextureD3D* textureImpl = TextureD3D::makeTextureD3D(texture->getImplementation()); TextureD3D* textureImpl = TextureD3D::makeTextureD3D(texture->getImplementation());
TextureStorage *texStorage = textureImpl->getNativeTexture(); TextureStorage *texStorage = textureImpl->getNativeTexture();
if (texStorage) ASSERT(texStorage != NULL);
{
TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage); TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage);
gl::SamplerState samplerState; gl::SamplerState samplerState;
texture->getSamplerStateWithNativeOffset(&samplerState); texture->getSamplerStateWithNativeOffset(&samplerState);
textureSRV = storage11->getSRV(samplerState); textureSRV = storage11->getSRV(samplerState);
}
// If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly // If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly
// missing the shader resource view // missing the shader resource view
...@@ -534,9 +532,11 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur ...@@ -534,9 +532,11 @@ void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *textur
mCurVertexSRVs[index] = textureSRV; mCurVertexSRVs[index] = textureSRV;
} }
else UNREACHABLE(); else UNREACHABLE();
return gl::Error(GL_NO_ERROR);
} }
bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) gl::Error Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[])
{ {
for (unsigned int uniformBufferIndex = 0; uniformBufferIndex < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; uniformBufferIndex++) for (unsigned int uniformBufferIndex = 0; uniformBufferIndex < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; uniformBufferIndex++)
{ {
...@@ -548,7 +548,7 @@ bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], con ...@@ -548,7 +548,7 @@ bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], con
if (!constantBuffer) if (!constantBuffer)
{ {
return false; return gl::Error(GL_OUT_OF_MEMORY);
} }
if (mCurrentConstantBufferVS[uniformBufferIndex] != bufferStorage->getSerial()) if (mCurrentConstantBufferVS[uniformBufferIndex] != bufferStorage->getSerial())
...@@ -570,7 +570,7 @@ bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], con ...@@ -570,7 +570,7 @@ bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], con
if (!constantBuffer) if (!constantBuffer)
{ {
return false; return gl::Error(GL_OUT_OF_MEMORY);
} }
if (mCurrentConstantBufferPS[uniformBufferIndex] != bufferStorage->getSerial()) if (mCurrentConstantBufferPS[uniformBufferIndex] != bufferStorage->getSerial())
...@@ -582,10 +582,10 @@ bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], con ...@@ -582,10 +582,10 @@ bool Renderer11::setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], con
} }
} }
return true; return gl::Error(GL_NO_ERROR);
} }
void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) gl::Error Renderer11::setRasterizerState(const gl::RasterizerState &rasterState)
{ {
if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0)
{ {
...@@ -593,9 +593,7 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) ...@@ -593,9 +593,7 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState)
gl::Error error = mStateCache.getRasterizerState(rasterState, mScissorEnabled, &dxRasterState); gl::Error error = mStateCache.getRasterizerState(rasterState, mScissorEnabled, &dxRasterState);
if (error.isError()) if (error.isError())
{ {
ERR("NULL rasterizer state returned by RenderStateCache::getRasterizerState, setting the default" return error;
"rasterizer state.");
dxRasterState = NULL;
} }
mDeviceContext->RSSetState(dxRasterState); mDeviceContext->RSSetState(dxRasterState);
...@@ -604,9 +602,11 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) ...@@ -604,9 +602,11 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState)
} }
mForceSetRasterState = false; mForceSetRasterState = false;
return gl::Error(GL_NO_ERROR);
} }
void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor, gl::Error Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
unsigned int sampleMask) unsigned int sampleMask)
{ {
if (mForceSetBlendState || if (mForceSetBlendState ||
...@@ -618,11 +618,11 @@ void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendStat ...@@ -618,11 +618,11 @@ void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendStat
gl::Error error = mStateCache.getBlendState(framebuffer, blendState, &dxBlendState); gl::Error error = mStateCache.getBlendState(framebuffer, blendState, &dxBlendState);
if (error.isError()) if (error.isError())
{ {
ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " return error;
"blend state.");
dxBlendState = NULL;
} }
ASSERT(dxBlendState != NULL);
float blendColors[4] = {0.0f}; float blendColors[4] = {0.0f};
if (blendState.sourceBlendRGB != GL_CONSTANT_ALPHA && blendState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA && if (blendState.sourceBlendRGB != GL_CONSTANT_ALPHA && blendState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA &&
blendState.destBlendRGB != GL_CONSTANT_ALPHA && blendState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA) blendState.destBlendRGB != GL_CONSTANT_ALPHA && blendState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA)
...@@ -648,9 +648,11 @@ void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendStat ...@@ -648,9 +648,11 @@ void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendStat
} }
mForceSetBlendState = false; mForceSetBlendState = false;
return gl::Error(GL_NO_ERROR);
} }
void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, gl::Error Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW) int stencilBackRef, bool frontFaceCCW)
{ {
if (mForceSetDepthStencilState || if (mForceSetDepthStencilState ||
...@@ -665,11 +667,11 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS ...@@ -665,11 +667,11 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS
gl::Error error = mStateCache.getDepthStencilState(depthStencilState, &dxDepthStencilState); gl::Error error = mStateCache.getDepthStencilState(depthStencilState, &dxDepthStencilState);
if (error.isError()) if (error.isError())
{ {
ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " return error;
"setting the default depth stencil state.");
dxDepthStencilState = NULL;
} }
ASSERT(dxDepthStencilState);
// Max D3D11 stencil reference value is 0xFF, corresponding to the max 8 bits in a stencil buffer // Max D3D11 stencil reference value is 0xFF, corresponding to the max 8 bits in a stencil buffer
// GL specifies we should clamp the ref value to the nearest bit depth when doing stencil ops // GL specifies we should clamp the ref value to the nearest bit depth when doing stencil ops
META_ASSERT(D3D11_DEFAULT_STENCIL_READ_MASK == 0xFF); META_ASSERT(D3D11_DEFAULT_STENCIL_READ_MASK == 0xFF);
...@@ -684,6 +686,8 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS ...@@ -684,6 +686,8 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS
} }
mForceSetDepthStencilState = false; mForceSetDepthStencilState = false;
return gl::Error(GL_NO_ERROR);
} }
void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
...@@ -802,7 +806,7 @@ bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count) ...@@ -802,7 +806,7 @@ bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count)
return count >= minCount; return count >= minCount;
} }
bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) gl::Error Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
{ {
// Get the color render buffer and serial // Get the color render buffer and serial
// Also extract the render target dimensions and view // Also extract the render target dimensions and view
...@@ -828,7 +832,7 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -828,7 +832,7 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
// this will not report any gl error but will cause the calling method to return. // this will not report any gl error but will cause the calling method to return.
if (colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0) if (colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0)
{ {
return false; return gl::Error(GL_NO_ERROR);
} }
renderTargetSerials[colorAttachment] = GetAttachmentSerial(colorbuffer); renderTargetSerials[colorAttachment] = GetAttachmentSerial(colorbuffer);
...@@ -837,15 +841,13 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -837,15 +841,13 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer); RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
if (!renderTarget) if (!renderTarget)
{ {
ERR("render target pointer unexpectedly null."); return gl::Error(GL_OUT_OF_MEMORY, "Internal render target pointer unexpectedly null.");
return false;
} }
framebufferRTVs[colorAttachment] = renderTarget->getRenderTargetView(); framebufferRTVs[colorAttachment] = renderTarget->getRenderTargetView();
if (!framebufferRTVs[colorAttachment]) if (!framebufferRTVs[colorAttachment])
{ {
ERR("render target view pointer unexpectedly null."); return gl::Error(GL_OUT_OF_MEMORY, "Internal render target view pointer unexpectedly null.");
return false;
} }
if (missingColorRenderTarget) if (missingColorRenderTarget)
...@@ -881,17 +883,15 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -881,17 +883,15 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
RenderTarget11 *depthStencilRenderTarget = d3d11::GetAttachmentRenderTarget(depthStencil); RenderTarget11 *depthStencilRenderTarget = d3d11::GetAttachmentRenderTarget(depthStencil);
if (!depthStencilRenderTarget) if (!depthStencilRenderTarget)
{ {
ERR("render target pointer unexpectedly null.");
SafeRelease(framebufferRTVs); SafeRelease(framebufferRTVs);
return false; return gl::Error(GL_OUT_OF_MEMORY, "Internal render target pointer unexpectedly null.");
} }
framebufferDSV = depthStencilRenderTarget->getDepthStencilView(); framebufferDSV = depthStencilRenderTarget->getDepthStencilView();
if (!framebufferDSV) if (!framebufferDSV)
{ {
ERR("depth stencil view pointer unexpectedly null.");
SafeRelease(framebufferRTVs); SafeRelease(framebufferRTVs);
return false; return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil view pointer unexpectedly null.");
} }
// If there is no render buffer, the width, height and format values come from // If there is no render buffer, the width, height and format values come from
...@@ -936,7 +936,7 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -936,7 +936,7 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
invalidateFramebufferSwizzles(framebuffer); invalidateFramebufferSwizzles(framebuffer);
return true; return gl::Error(GL_NO_ERROR);
} }
gl::Error Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], gl::Error Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
...@@ -1024,7 +1024,7 @@ void Renderer11::applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuff ...@@ -1024,7 +1024,7 @@ void Renderer11::applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuff
} }
} }
void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) gl::Error Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive)
{ {
if (mode == GL_POINTS && transformFeedbackActive) if (mode == GL_POINTS && transformFeedbackActive)
{ {
...@@ -1057,49 +1057,55 @@ void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool ...@@ -1057,49 +1057,55 @@ void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool
} }
mDeviceContext->GSSetShader(mAppliedGeometryShader, NULL, 0); mDeviceContext->GSSetShader(mAppliedGeometryShader, NULL, 0);
return gl::Error(GL_NO_ERROR);
} }
else if (mode == GL_LINE_LOOP) else if (mode == GL_LINE_LOOP)
{ {
drawLineLoop(count, GL_NONE, NULL, 0, NULL); return drawLineLoop(count, GL_NONE, NULL, 0, NULL);
} }
else if (mode == GL_TRIANGLE_FAN) else if (mode == GL_TRIANGLE_FAN)
{ {
drawTriangleFan(count, GL_NONE, NULL, 0, NULL, instances); return drawTriangleFan(count, GL_NONE, NULL, 0, NULL, instances);
} }
else if (instances > 0) else if (instances > 0)
{ {
mDeviceContext->DrawInstanced(count, instances, 0, 0); mDeviceContext->DrawInstanced(count, instances, 0, 0);
return gl::Error(GL_NO_ERROR);
} }
else else
{ {
mDeviceContext->Draw(count, 0); mDeviceContext->Draw(count, 0);
return gl::Error(GL_NO_ERROR);
} }
} }
void Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Error Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances)
{ {
int minIndex = static_cast<int>(indexInfo.indexRange.start); int minIndex = static_cast<int>(indexInfo.indexRange.start);
if (mode == GL_LINE_LOOP) if (mode == GL_LINE_LOOP)
{ {
drawLineLoop(count, type, indices, minIndex, elementArrayBuffer); return drawLineLoop(count, type, indices, minIndex, elementArrayBuffer);
} }
else if (mode == GL_TRIANGLE_FAN) else if (mode == GL_TRIANGLE_FAN)
{ {
drawTriangleFan(count, type, indices, minIndex, elementArrayBuffer, instances); return drawTriangleFan(count, type, indices, minIndex, elementArrayBuffer, instances);
} }
else if (instances > 0) else if (instances > 0)
{ {
mDeviceContext->DrawIndexedInstanced(count, instances, 0, -minIndex, 0); mDeviceContext->DrawIndexedInstanced(count, instances, 0, -minIndex, 0);
return gl::Error(GL_NO_ERROR);
} }
else else
{ {
mDeviceContext->DrawIndexed(count, 0, -minIndex); mDeviceContext->DrawIndexed(count, 0, -minIndex);
return gl::Error(GL_NO_ERROR);
} }
} }
void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) gl::Error Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer)
{ {
// Get the raw indices for an indexed draw // Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer) if (type != GL_NONE && elementArrayBuffer)
...@@ -1117,9 +1123,7 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1117,9 +1123,7 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (error.isError()) if (error.isError())
{ {
SafeDelete(mLineLoopIB); SafeDelete(mLineLoopIB);
return error;
ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP.");
return gl::error(GL_OUT_OF_MEMORY);
} }
} }
...@@ -1128,16 +1132,14 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1128,16 +1132,14 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int))) if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int)))
{ {
ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP, too many indices required."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create a 32-bit looping index buffer for GL_LINE_LOOP, too many indices required.");
return gl::error(GL_OUT_OF_MEMORY);
} }
const unsigned int spaceNeeded = (static_cast<unsigned int>(count) + 1) * sizeof(unsigned int); const unsigned int spaceNeeded = (static_cast<unsigned int>(count) + 1) * sizeof(unsigned int);
gl::Error error = mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT); gl::Error error = mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT);
if (error.isError()) if (error.isError())
{ {
ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
void* mappedMemory = NULL; void* mappedMemory = NULL;
...@@ -1145,8 +1147,7 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1145,8 +1147,7 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
error = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset); error = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset);
if (error.isError()) if (error.isError())
{ {
ERR("Could not map index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory);
...@@ -1188,8 +1189,7 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1188,8 +1189,7 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
error = mLineLoopIB->unmapBuffer(); error = mLineLoopIB->unmapBuffer();
if (error.isError()) if (error.isError())
{ {
ERR("Could not unmap index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer()); IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer());
...@@ -1205,9 +1205,11 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1205,9 +1205,11 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
} }
mDeviceContext->DrawIndexed(count + 1, 0, -minIndex); mDeviceContext->DrawIndexed(count + 1, 0, -minIndex);
return gl::Error(GL_NO_ERROR);
} }
void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances) gl::Error Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances)
{ {
// Get the raw indices for an indexed draw // Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer) if (type != GL_NONE && elementArrayBuffer)
...@@ -1225,9 +1227,7 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1225,9 +1227,7 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
if (error.isError()) if (error.isError())
{ {
SafeDelete(mTriangleFanIB); SafeDelete(mTriangleFanIB);
return error;
ERR("Could not create a scratch index buffer for GL_TRIANGLE_FAN.");
return gl::error(GL_OUT_OF_MEMORY);
} }
} }
...@@ -1238,16 +1238,14 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1238,16 +1238,14 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
if (numTris > (std::numeric_limits<unsigned int>::max() / (sizeof(unsigned int) * 3))) if (numTris > (std::numeric_limits<unsigned int>::max() / (sizeof(unsigned int) * 3)))
{ {
ERR("Could not create a scratch index buffer for GL_TRIANGLE_FAN, too many indices required."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create a scratch index buffer for GL_TRIANGLE_FAN, too many indices required.");
return gl::error(GL_OUT_OF_MEMORY);
} }
const unsigned int spaceNeeded = (numTris * 3) * sizeof(unsigned int); const unsigned int spaceNeeded = (numTris * 3) * sizeof(unsigned int);
gl::Error error = mTriangleFanIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT); gl::Error error = mTriangleFanIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT);
if (error.isError()) if (error.isError())
{ {
ERR("Could not reserve enough space in scratch index buffer for GL_TRIANGLE_FAN."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
void* mappedMemory = NULL; void* mappedMemory = NULL;
...@@ -1255,8 +1253,7 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1255,8 +1253,7 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
error = mTriangleFanIB->mapBuffer(spaceNeeded, &mappedMemory, &offset); error = mTriangleFanIB->mapBuffer(spaceNeeded, &mappedMemory, &offset);
if (error.isError()) if (error.isError())
{ {
ERR("Could not map scratch index buffer for GL_TRIANGLE_FAN."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory);
...@@ -1302,8 +1299,7 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1302,8 +1299,7 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
error = mTriangleFanIB->unmapBuffer(); error = mTriangleFanIB->unmapBuffer();
if (error.isError()) if (error.isError())
{ {
ERR("Could not unmap scratch index buffer for GL_TRIANGLE_FAN."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mTriangleFanIB->getIndexBuffer()); IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mTriangleFanIB->getIndexBuffer());
...@@ -1326,9 +1322,11 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1326,9 +1322,11 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
{ {
mDeviceContext->DrawIndexed(numTris * 3, 0, -minIndex); mDeviceContext->DrawIndexed(numTris * 3, 0, -minIndex);
} }
return gl::Error(GL_NO_ERROR);
} }
void Renderer11::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, gl::Error Renderer11::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive) bool rasterizerDiscard, bool transformFeedbackActive)
{ {
ShaderExecutable *vertexExe = programBinary->getVertexExecutableForInputLayout(inputLayout); ShaderExecutable *vertexExe = programBinary->getVertexExecutableForInputLayout(inputLayout);
...@@ -1390,9 +1388,11 @@ void Renderer11::applyShaders(gl::ProgramBinary *programBinary, const gl::Vertex ...@@ -1390,9 +1388,11 @@ void Renderer11::applyShaders(gl::ProgramBinary *programBinary, const gl::Vertex
{ {
programBinary->dirtyAllUniforms(); programBinary->dirtyAllUniforms();
} }
return gl::Error(GL_NO_ERROR);
} }
void Renderer11::applyUniforms(const gl::ProgramBinary &programBinary) gl::Error Renderer11::applyUniforms(const gl::ProgramBinary &programBinary)
{ {
const std::vector<gl::LinkedUniform*> &uniformArray = programBinary.getUniforms(); const std::vector<gl::LinkedUniform*> &uniformArray = programBinary.getUniforms();
...@@ -1547,6 +1547,8 @@ void Renderer11::applyUniforms(const gl::ProgramBinary &programBinary) ...@@ -1547,6 +1547,8 @@ void Renderer11::applyUniforms(const gl::ProgramBinary &programBinary)
mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS); mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS);
mCurrentGeometryConstantBuffer = mDriverConstantBufferPS; mCurrentGeometryConstantBuffer = mDriverConstantBufferPS;
} }
return gl::Error(GL_NO_ERROR);
} }
gl::Error Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) gl::Error Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer)
......
...@@ -60,15 +60,15 @@ class Renderer11 : public Renderer ...@@ -60,15 +60,15 @@ class Renderer11 : public Renderer
virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat); virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat);
virtual gl::Error generateSwizzle(gl::Texture *texture); virtual gl::Error generateSwizzle(gl::Texture *texture);
virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler); virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture); virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture);
virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]); virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]);
virtual void setRasterizerState(const gl::RasterizerState &rasterState); virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState);
virtual void setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor, virtual gl::Error setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
unsigned int sampleMask); unsigned int sampleMask);
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW); int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled); virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
...@@ -76,17 +76,17 @@ class Renderer11 : public Renderer ...@@ -76,17 +76,17 @@ class Renderer11 : public Renderer
bool ignoreViewport); bool ignoreViewport);
virtual bool applyPrimitiveType(GLenum mode, GLsizei count); virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual gl::Error applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, virtual gl::Error applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive); bool rasterizerDiscard, bool transformFeedbackActive);
virtual void applyUniforms(const gl::ProgramBinary &programBinary); virtual gl::Error applyUniforms(const gl::ProgramBinary &programBinary);
virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances); 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 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[]); virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]);
virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive); virtual gl::Error drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive);
virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, virtual gl::Error drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances); gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances);
virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer); virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer);
...@@ -206,8 +206,8 @@ class Renderer11 : public Renderer ...@@ -206,8 +206,8 @@ class Renderer11 : public Renderer
virtual void generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const; virtual void generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const;
void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer); gl::Error drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
void drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances); gl::Error drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances);
gl::Error readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format, gl::Error readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels); GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels);
......
...@@ -643,7 +643,7 @@ gl::Error Renderer9::generateSwizzle(gl::Texture *texture) ...@@ -643,7 +643,7 @@ gl::Error Renderer9::generateSwizzle(gl::Texture *texture)
return gl::Error(GL_INVALID_OPERATION); return gl::Error(GL_INVALID_OPERATION);
} }
void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) gl::Error Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
{ {
std::vector<bool> &forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates; std::vector<bool> &forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates;
std::vector<gl::SamplerState> &appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates; std::vector<gl::SamplerState> &appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates;
...@@ -670,9 +670,11 @@ void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::Sampl ...@@ -670,9 +670,11 @@ void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::Sampl
forceSetSamplers[index] = false; forceSetSamplers[index] = false;
appliedSamplers[index] = samplerState; appliedSamplers[index] = samplerState;
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture) gl::Error Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture)
{ {
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset; int d3dSampler = index + d3dSamplerOffset;
...@@ -707,15 +709,17 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture ...@@ -707,15 +709,17 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture
} }
appliedSerials[index] = serial; appliedSerials[index] = serial;
return gl::Error(GL_NO_ERROR);
} }
bool Renderer9::setUniformBuffers(const gl::Buffer* /*vertexUniformBuffers*/[], const gl::Buffer* /*fragmentUniformBuffers*/[]) gl::Error Renderer9::setUniformBuffers(const gl::Buffer* /*vertexUniformBuffers*/[], const gl::Buffer* /*fragmentUniformBuffers*/[])
{ {
// No effect in ES2/D3D9 // No effect in ES2/D3D9
return true; return gl::Error(GL_NO_ERROR);
} }
void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState) gl::Error Renderer9::setRasterizerState(const gl::RasterizerState &rasterState)
{ {
bool rasterStateChanged = mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0; bool rasterStateChanged = mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0;
...@@ -751,9 +755,11 @@ void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState) ...@@ -751,9 +755,11 @@ void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState)
} }
mForceSetRasterState = false; mForceSetRasterState = false;
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor, gl::Error Renderer9::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
unsigned int sampleMask) unsigned int sampleMask)
{ {
bool blendStateChanged = mForceSetBlendState || memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0; bool blendStateChanged = mForceSetBlendState || memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0;
...@@ -855,9 +861,11 @@ void Renderer9::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState ...@@ -855,9 +861,11 @@ void Renderer9::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState
} }
mForceSetBlendState = false; mForceSetBlendState = false;
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, gl::Error Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW) int stencilBackRef, bool frontFaceCCW)
{ {
bool depthStencilStateChanged = mForceSetDepthStencilState || bool depthStencilStateChanged = mForceSetDepthStencilState ||
...@@ -947,6 +955,8 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -947,6 +955,8 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
} }
mForceSetDepthStencilState = false; mForceSetDepthStencilState = false;
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
...@@ -1140,7 +1150,7 @@ gl::FramebufferAttachment *Renderer9::getNullColorbuffer(gl::FramebufferAttachme ...@@ -1140,7 +1150,7 @@ gl::FramebufferAttachment *Renderer9::getNullColorbuffer(gl::FramebufferAttachme
return nullbuffer; return nullbuffer;
} }
bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) gl::Error Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
{ {
// if there is no color attachment we must synthesize a NULL colorattachment // if there is no color attachment we must synthesize a NULL colorattachment
// to keep the D3D runtime happy. This should only be possible if depth texturing. // to keep the D3D runtime happy. This should only be possible if depth texturing.
...@@ -1151,8 +1161,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1151,8 +1161,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
} }
if (!attachment) if (!attachment)
{ {
ERR("unable to locate renderbuffer for FBO."); return gl::Error(GL_OUT_OF_MEMORY, "Unable to locate renderbuffer for FBO.");
return false;
} }
bool renderTargetChanged = false; bool renderTargetChanged = false;
...@@ -1170,8 +1179,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1170,8 +1179,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
if (!renderTargetSurface) if (!renderTargetSurface)
{ {
ERR("render target pointer unexpectedly null."); return gl::Error(GL_OUT_OF_MEMORY, "Internal render target pointer unexpectedly null.");
return false; // Context must be lost
} }
mDevice->SetRenderTarget(0, renderTargetSurface); mDevice->SetRenderTarget(0, renderTargetSurface);
...@@ -1214,8 +1222,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1214,8 +1222,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
if (!depthStencilSurface) if (!depthStencilSurface)
{ {
ERR("depth stencil pointer unexpectedly null."); return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil pointer unexpectedly null.");
return false; // Context must be lost
} }
mDevice->SetDepthStencilSurface(depthStencilSurface); mDevice->SetDepthStencilSurface(depthStencilSurface);
...@@ -1258,7 +1265,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1258,7 +1265,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
mRenderTargetDescInitialized = true; mRenderTargetDescInitialized = true;
} }
return true; return gl::Error(GL_NO_ERROR);
} }
gl::Error Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], gl::Error Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
...@@ -1302,7 +1309,7 @@ void Renderer9::applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffe ...@@ -1302,7 +1309,7 @@ void Renderer9::applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffe
UNREACHABLE(); UNREACHABLE();
} }
void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) gl::Error Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive)
{ {
ASSERT(!transformFeedbackActive); ASSERT(!transformFeedbackActive);
...@@ -1310,14 +1317,15 @@ void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool t ...@@ -1310,14 +1317,15 @@ void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool t
if (mode == GL_LINE_LOOP) if (mode == GL_LINE_LOOP)
{ {
drawLineLoop(count, GL_NONE, NULL, 0, NULL); return drawLineLoop(count, GL_NONE, NULL, 0, NULL);
} }
else if (instances > 0) else if (instances > 0)
{ {
StaticIndexBufferInterface *countingIB = getCountingIB(count); StaticIndexBufferInterface *countingIB = NULL;
if (!countingIB) gl::Error error = getCountingIB(count, &countingIB);
if (error.isError())
{ {
return; return error;
} }
if (mAppliedIBSerial != countingIB->getSerial()) if (mAppliedIBSerial != countingIB->getSerial())
...@@ -1332,14 +1340,17 @@ void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool t ...@@ -1332,14 +1340,17 @@ void Renderer9::drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool t
{ {
mDevice->DrawIndexedPrimitive(mPrimitiveType, 0, 0, count, 0, mPrimitiveCount); mDevice->DrawIndexedPrimitive(mPrimitiveType, 0, 0, count, 0, mPrimitiveCount);
} }
return gl::Error(GL_NO_ERROR);
} }
else // Regular case else // Regular case
{ {
mDevice->DrawPrimitive(mPrimitiveType, 0, mPrimitiveCount); mDevice->DrawPrimitive(mPrimitiveType, 0, mPrimitiveCount);
return gl::Error(GL_NO_ERROR);
} }
} }
void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Error Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei /*instances*/) gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei /*instances*/)
{ {
startScene(); startScene();
...@@ -1348,11 +1359,11 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo ...@@ -1348,11 +1359,11 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo
if (mode == GL_POINTS) if (mode == GL_POINTS)
{ {
drawIndexedPoints(count, type, indices, minIndex, elementArrayBuffer); return drawIndexedPoints(count, type, indices, minIndex, elementArrayBuffer);
} }
else if (mode == GL_LINE_LOOP) else if (mode == GL_LINE_LOOP)
{ {
drawLineLoop(count, type, indices, minIndex, elementArrayBuffer); return drawLineLoop(count, type, indices, minIndex, elementArrayBuffer);
} }
else else
{ {
...@@ -1361,10 +1372,11 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo ...@@ -1361,10 +1372,11 @@ void Renderer9::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvo
GLsizei vertexCount = static_cast<int>(indexInfo.indexRange.length()) + 1; GLsizei vertexCount = static_cast<int>(indexInfo.indexRange.length()) + 1;
mDevice->DrawIndexedPrimitive(mPrimitiveType, -minIndex, minIndex, vertexCount, indexInfo.startIndex, mPrimitiveCount); mDevice->DrawIndexedPrimitive(mPrimitiveType, -minIndex, minIndex, vertexCount, indexInfo.startIndex, mPrimitiveCount);
} }
return gl::Error(GL_NO_ERROR);
} }
} }
void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) gl::Error Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer)
{ {
// Get the raw indices for an indexed draw // Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer) if (type != GL_NONE && elementArrayBuffer)
...@@ -1386,9 +1398,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1386,9 +1398,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (error.isError()) if (error.isError())
{ {
SafeDelete(mLineLoopIB); SafeDelete(mLineLoopIB);
return error;
ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP.");
return gl::error(GL_OUT_OF_MEMORY);
} }
} }
...@@ -1397,16 +1407,14 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1397,16 +1407,14 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int))) if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int)))
{ {
ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP, too many indices required."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create a 32-bit looping index buffer for GL_LINE_LOOP, too many indices required.");
return gl::error(GL_OUT_OF_MEMORY);
} }
const unsigned int spaceNeeded = (static_cast<unsigned int>(count)+1) * sizeof(unsigned int); const unsigned int spaceNeeded = (static_cast<unsigned int>(count)+1) * sizeof(unsigned int);
gl::Error error = mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT); gl::Error error = mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT);
if (error.isError()) if (error.isError())
{ {
ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
void* mappedMemory = NULL; void* mappedMemory = NULL;
...@@ -1414,8 +1422,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1414,8 +1422,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
error = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset); error = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset);
if (error.isError()) if (error.isError())
{ {
ERR("Could not map index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
startIndex = static_cast<unsigned int>(offset) / 4; startIndex = static_cast<unsigned int>(offset) / 4;
...@@ -1457,8 +1464,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1457,8 +1464,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
error = mLineLoopIB->unmapBuffer(); error = mLineLoopIB->unmapBuffer();
if (error.isError()) if (error.isError())
{ {
ERR("Could not unmap index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
} }
else else
...@@ -1470,9 +1476,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1470,9 +1476,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (error.isError()) if (error.isError())
{ {
SafeDelete(mLineLoopIB); SafeDelete(mLineLoopIB);
return error;
ERR("Could not create a 16-bit looping index buffer for GL_LINE_LOOP.");
return gl::error(GL_OUT_OF_MEMORY);
} }
} }
...@@ -1481,16 +1485,14 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1481,16 +1485,14 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned short>::max() / sizeof(unsigned short))) if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned short>::max() / sizeof(unsigned short)))
{ {
ERR("Could not create a 16-bit looping index buffer for GL_LINE_LOOP, too many indices required."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create a 16-bit looping index buffer for GL_LINE_LOOP, too many indices required.");
return gl::error(GL_OUT_OF_MEMORY);
} }
const unsigned int spaceNeeded = (static_cast<unsigned int>(count) + 1) * sizeof(unsigned short); const unsigned int spaceNeeded = (static_cast<unsigned int>(count) + 1) * sizeof(unsigned short);
gl::Error error = mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_SHORT); gl::Error error = mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_SHORT);
if (error.isError()) if (error.isError())
{ {
ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
void* mappedMemory = NULL; void* mappedMemory = NULL;
...@@ -1498,8 +1500,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1498,8 +1500,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
error = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset); error = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset);
if (error.isError()) if (error.isError())
{ {
ERR("Could not map index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
startIndex = static_cast<unsigned int>(offset) / 2; startIndex = static_cast<unsigned int>(offset) / 2;
...@@ -1541,8 +1542,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1541,8 +1542,7 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
error = mLineLoopIB->unmapBuffer(); error = mLineLoopIB->unmapBuffer();
if (error.isError()) if (error.isError())
{ {
ERR("Could not unmap index buffer for GL_LINE_LOOP."); return error;
return gl::error(GL_OUT_OF_MEMORY);
} }
} }
...@@ -1555,19 +1555,23 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1555,19 +1555,23 @@ void Renderer9::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
} }
mDevice->DrawIndexedPrimitive(D3DPT_LINESTRIP, -minIndex, minIndex, count, startIndex, count); mDevice->DrawIndexedPrimitive(D3DPT_LINESTRIP, -minIndex, minIndex, count, startIndex, count);
return gl::Error(GL_NO_ERROR);
} }
template <typename T> template <typename T>
static void drawPoints(IDirect3DDevice9* device, GLsizei count, const GLvoid *indices, int minIndex) static gl::Error drawPoints(IDirect3DDevice9* device, GLsizei count, const GLvoid *indices, int minIndex)
{ {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
unsigned int indexValue = static_cast<unsigned int>(static_cast<const T*>(indices)[i]) - minIndex; unsigned int indexValue = static_cast<unsigned int>(static_cast<const T*>(indices)[i]) - minIndex;
device->DrawPrimitive(D3DPT_POINTLIST, indexValue, 1); device->DrawPrimitive(D3DPT_POINTLIST, indexValue, 1);
} }
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) gl::Error Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer)
{ {
// Drawing index point lists is unsupported in d3d9, fall back to a regular DrawPrimitive call // Drawing index point lists is unsupported in d3d9, fall back to a regular DrawPrimitive call
// for each individual point. This call is not expected to happen often. // for each individual point. This call is not expected to happen often.
...@@ -1581,14 +1585,14 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi ...@@ -1581,14 +1585,14 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi
switch (type) switch (type)
{ {
case GL_UNSIGNED_BYTE: drawPoints<GLubyte>(mDevice, count, indices, minIndex); break; case GL_UNSIGNED_BYTE: return drawPoints<GLubyte>(mDevice, count, indices, minIndex);
case GL_UNSIGNED_SHORT: drawPoints<GLushort>(mDevice, count, indices, minIndex); break; case GL_UNSIGNED_SHORT: return drawPoints<GLushort>(mDevice, count, indices, minIndex);
case GL_UNSIGNED_INT: drawPoints<GLuint>(mDevice, count, indices, minIndex); break; case GL_UNSIGNED_INT: return drawPoints<GLuint>(mDevice, count, indices, minIndex);
default: UNREACHABLE(); default: UNREACHABLE(); return gl::Error(GL_INVALID_OPERATION);
} }
} }
StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count) gl::Error Renderer9::getCountingIB(size_t count, StaticIndexBufferInterface **outIB)
{ {
// Update the counting index buffer if it is not large enough or has not been created yet. // Update the counting index buffer if it is not large enough or has not been created yet.
if (count <= 65536) // 16-bit indices if (count <= 65536) // 16-bit indices
...@@ -1605,8 +1609,7 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count) ...@@ -1605,8 +1609,7 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count)
gl::Error error = mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, NULL); gl::Error error = mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, NULL);
if (error.isError()) if (error.isError())
{ {
ERR("Failed to map counting buffer."); return error;
return NULL;
} }
unsigned short *data = reinterpret_cast<unsigned short*>(mappedMemory); unsigned short *data = reinterpret_cast<unsigned short*>(mappedMemory);
...@@ -1618,12 +1621,9 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count) ...@@ -1618,12 +1621,9 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count)
error = mCountingIB->unmapBuffer(); error = mCountingIB->unmapBuffer();
if (error.isError()) if (error.isError())
{ {
ERR("Failed to unmap counting buffer."); return error;
return NULL;
} }
} }
return mCountingIB;
} }
else if (getRendererExtensions().elementIndexUint) else if (getRendererExtensions().elementIndexUint)
{ {
...@@ -1639,8 +1639,7 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count) ...@@ -1639,8 +1639,7 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count)
gl::Error error = mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, NULL); gl::Error error = mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, NULL);
if (error.isError()) if (error.isError())
{ {
ERR("Failed to map counting buffer."); return error;
return NULL;
} }
unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory);
...@@ -1652,21 +1651,20 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count) ...@@ -1652,21 +1651,20 @@ StaticIndexBufferInterface *Renderer9::getCountingIB(size_t count)
error = mCountingIB->unmapBuffer(); error = mCountingIB->unmapBuffer();
if (error.isError()) if (error.isError())
{ {
ERR("Failed to unmap counting buffer."); return error;
return NULL;
} }
} }
return mCountingIB;
} }
else else
{ {
ERR("Could not create a counting index buffer for glDrawArraysInstanced."); return gl::Error(GL_OUT_OF_MEMORY, "Could not create a counting index buffer for glDrawArraysInstanced.");
return gl::error<StaticIndexBufferInterface*>(GL_OUT_OF_MEMORY, NULL);
} }
*outIB = mCountingIB;
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, gl::Error Renderer9::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive) bool rasterizerDiscard, bool transformFeedbackActive)
{ {
ASSERT(!transformFeedbackActive); ASSERT(!transformFeedbackActive);
...@@ -1702,9 +1700,11 @@ void Renderer9::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexF ...@@ -1702,9 +1700,11 @@ void Renderer9::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexF
mDxUniformsDirty = true; mDxUniformsDirty = true;
mAppliedProgramSerial = programSerial; mAppliedProgramSerial = programSerial;
} }
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::applyUniforms(const gl::ProgramBinary &programBinary) gl::Error Renderer9::applyUniforms(const gl::ProgramBinary &programBinary)
{ {
const std::vector<gl::LinkedUniform*> &uniformArray = programBinary.getUniforms(); const std::vector<gl::LinkedUniform*> &uniformArray = programBinary.getUniforms();
...@@ -1756,6 +1756,8 @@ void Renderer9::applyUniforms(const gl::ProgramBinary &programBinary) ...@@ -1756,6 +1756,8 @@ void Renderer9::applyUniforms(const gl::ProgramBinary &programBinary)
mDevice->SetPixelShaderConstantF(0, (float*)&mPixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4])); mDevice->SetPixelShaderConstantF(0, (float*)&mPixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4]));
mDxUniformsDirty = false; mDxUniformsDirty = false;
} }
return gl::Error(GL_NO_ERROR);
} }
void Renderer9::applyUniformnfv(gl::LinkedUniform *targetUniform, const GLfloat *v) void Renderer9::applyUniformnfv(gl::LinkedUniform *targetUniform, const GLfloat *v)
......
...@@ -61,25 +61,25 @@ class Renderer9 : public Renderer ...@@ -61,25 +61,25 @@ class Renderer9 : public Renderer
HRESULT createVertexBuffer(UINT Length, DWORD Usage, IDirect3DVertexBuffer9 **ppVertexBuffer); HRESULT createVertexBuffer(UINT Length, DWORD Usage, IDirect3DVertexBuffer9 **ppVertexBuffer);
HRESULT createIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, IDirect3DIndexBuffer9 **ppIndexBuffer); HRESULT createIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, IDirect3DIndexBuffer9 **ppIndexBuffer);
virtual gl::Error generateSwizzle(gl::Texture *texture); virtual gl::Error generateSwizzle(gl::Texture *texture);
virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler); virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture); virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture);
virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]); virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]);
virtual void setRasterizerState(const gl::RasterizerState &rasterState); virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState);
virtual void setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor, virtual gl::Error setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
unsigned int sampleMask); unsigned int sampleMask);
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW); int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled); virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
virtual void setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, virtual void setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport); bool ignoreViewport);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual gl::Error applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, virtual gl::Error applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive); bool rasterizerDiscard, bool transformFeedbackActive);
virtual void applyUniforms(const gl::ProgramBinary &programBinary); virtual gl::Error applyUniforms(const gl::ProgramBinary &programBinary);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount); virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances); GLint first, GLsizei count, GLsizei instances);
...@@ -87,8 +87,8 @@ class Renderer9 : public Renderer ...@@ -87,8 +87,8 @@ class Renderer9 : public Renderer
virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]); virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]);
virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive); virtual gl::Error drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive);
virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, virtual gl::Error drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances); gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances);
virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer); virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer);
...@@ -209,10 +209,10 @@ class Renderer9 : public Renderer ...@@ -209,10 +209,10 @@ class Renderer9 : public Renderer
void applyUniformniv(gl::LinkedUniform *targetUniform, const GLint *v); void applyUniformniv(gl::LinkedUniform *targetUniform, const GLint *v);
void applyUniformnbv(gl::LinkedUniform *targetUniform, const GLint *v); void applyUniformnbv(gl::LinkedUniform *targetUniform, const GLint *v);
void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer); gl::Error drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer); gl::Error drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
StaticIndexBufferInterface *getCountingIB(size_t count); gl::Error getCountingIB(size_t count, StaticIndexBufferInterface **outIB);
bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged); bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
gl::FramebufferAttachment *getNullColorbuffer(gl::FramebufferAttachment *depthbuffer); gl::FramebufferAttachment *getNullColorbuffer(gl::FramebufferAttachment *depthbuffer);
......
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