Commit f75ab350 by Jamie Madill

Make ClearParameters an rx-only type.

This legacy struct duplicates some methods in the gl::State. We can restrict its use to D3D and on newer back-ends use the State directly. BUG=angleproject:930 Change-Id: I2c298e76b072ee73f2b3e17f6696693031ce1f91 Reviewed-on: https://chromium-review.googlesource.com/258070Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 14fc83b6
......@@ -35,7 +35,7 @@ void State::initialize(const Caps& caps, GLuint clientVersion)
mMaxDrawBuffers = caps.maxDrawBuffers;
mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits;
setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f);
mDepthClearValue = 1.0f;
mStencilClearValue = 0;
......@@ -212,7 +212,7 @@ const DepthStencilState &State::getDepthStencilState() const
return mDepthStencil;
}
void State::setClearColor(float red, float green, float blue, float alpha)
void State::setColorClearValue(float red, float green, float blue, float alpha)
{
mColorClearValue.red = red;
mColorClearValue.green = green;
......@@ -220,70 +220,16 @@ void State::setClearColor(float red, float green, float blue, float alpha)
mColorClearValue.alpha = alpha;
}
void State::setClearDepth(float depth)
void State::setDepthClearValue(float depth)
{
mDepthClearValue = depth;
}
void State::setClearStencil(int stencil)
void State::setStencilClearValue(int stencil)
{
mStencilClearValue = stencil;
}
ClearParameters State::getClearParameters(GLbitfield mask) const
{
ClearParameters clearParams;
memset(&clearParams, 0, sizeof(ClearParameters));
for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
{
clearParams.clearColor[i] = false;
}
clearParams.colorFClearValue = mColorClearValue;
clearParams.colorClearType = GL_FLOAT;
clearParams.colorMaskRed = mBlend.colorMaskRed;
clearParams.colorMaskGreen = mBlend.colorMaskGreen;
clearParams.colorMaskBlue = mBlend.colorMaskBlue;
clearParams.colorMaskAlpha = mBlend.colorMaskAlpha;
clearParams.clearDepth = false;
clearParams.depthClearValue = mDepthClearValue;
clearParams.clearStencil = false;
clearParams.stencilClearValue = mStencilClearValue;
clearParams.stencilWriteMask = mDepthStencil.stencilWritemask;
clearParams.scissorEnabled = mScissorTest;
clearParams.scissor = mScissor;
const Framebuffer *framebufferObject = getDrawFramebuffer();
if (mask & GL_COLOR_BUFFER_BIT)
{
if (framebufferObject->hasEnabledColorAttachment())
{
for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
{
clearParams.clearColor[i] = true;
}
}
}
if (mask & GL_DEPTH_BUFFER_BIT)
{
if (mDepthStencil.depthMask && framebufferObject->getDepthbuffer() != NULL)
{
clearParams.clearDepth = true;
}
}
if (mask & GL_STENCIL_BUFFER_BIT)
{
if (framebufferObject->getStencilbuffer() != NULL &&
framebufferObject->getStencilbuffer()->getStencilSize() > 0)
{
clearParams.clearStencil = true;
}
}
return clearParams;
}
void State::setColorMask(bool red, bool green, bool blue, bool alpha)
{
mBlend.colorMaskRed = red;
......
......@@ -44,10 +44,13 @@ class State
const DepthStencilState &getDepthStencilState() const;
// Clear behavior setters & state parameter block generation function
void setClearColor(float red, float green, float blue, float alpha);
void setClearDepth(float depth);
void setClearStencil(int stencil);
ClearParameters getClearParameters(GLbitfield mask) const;
void setColorClearValue(float red, float green, float blue, float alpha);
void setDepthClearValue(float depth);
void setStencilClearValue(int stencil);
const ColorF &getColorClearValue() const { return mColorClearValue; }
float getDepthClearValue() const { return mDepthClearValue; }
int getStencilClearValue() const { return mStencilClearValue; }
// Write mask manipulation
void setColorMask(bool red, bool green, bool blue, bool alpha);
......
......@@ -183,29 +183,6 @@ struct SamplerState
bool operator!=(const SamplerState &other) const;
};
struct ClearParameters
{
bool clearColor[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS];
ColorF colorFClearValue;
ColorI colorIClearValue;
ColorUI colorUIClearValue;
GLenum colorClearType;
bool colorMaskRed;
bool colorMaskGreen;
bool colorMaskBlue;
bool colorMaskAlpha;
bool clearDepth;
float depthClearValue;
bool clearStencil;
GLint stencilClearValue;
GLuint stencilWriteMask;
bool scissorEnabled;
Rectangle scissor;
};
struct PixelUnpackState
{
BindingPointer<Buffer> pixelBuffer;
......
......@@ -18,6 +18,68 @@
namespace rx
{
namespace
{
ClearParameters GetClearParameters(const gl::State &state, GLbitfield mask)
{
ClearParameters clearParams;
memset(&clearParams, 0, sizeof(ClearParameters));
const auto &blendState = state.getBlendState();
for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
{
clearParams.clearColor[i] = false;
}
clearParams.colorFClearValue = state.getColorClearValue();
clearParams.colorClearType = GL_FLOAT;
clearParams.colorMaskRed = blendState.colorMaskRed;
clearParams.colorMaskGreen = blendState.colorMaskGreen;
clearParams.colorMaskBlue = blendState.colorMaskBlue;
clearParams.colorMaskAlpha = blendState.colorMaskAlpha;
clearParams.clearDepth = false;
clearParams.depthClearValue = state.getDepthClearValue();
clearParams.clearStencil = false;
clearParams.stencilClearValue = state.getStencilClearValue();
clearParams.stencilWriteMask = state.getDepthStencilState().stencilWritemask;
clearParams.scissorEnabled = state.isScissorTestEnabled();
clearParams.scissor = state.getScissor();
const gl::Framebuffer *framebufferObject = state.getDrawFramebuffer();
if (mask & GL_COLOR_BUFFER_BIT)
{
if (framebufferObject->hasEnabledColorAttachment())
{
for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
{
clearParams.clearColor[i] = true;
}
}
}
if (mask & GL_DEPTH_BUFFER_BIT)
{
if (state.getDepthStencilState().depthMask && framebufferObject->getDepthbuffer() != NULL)
{
clearParams.clearDepth = true;
}
}
if (mask & GL_STENCIL_BUFFER_BIT)
{
if (framebufferObject->getStencilbuffer() != NULL &&
framebufferObject->getStencilbuffer()->getStencilSize() > 0)
{
clearParams.clearStencil = true;
}
}
return clearParams;
}
}
DefaultAttachmentD3D::DefaultAttachmentD3D(RenderTargetD3D *renderTarget)
: mRenderTarget(renderTarget)
{
......@@ -113,14 +175,14 @@ gl::Error FramebufferD3D::invalidateSub(size_t, const GLenum *, const gl::Rectan
gl::Error FramebufferD3D::clear(const gl::State &state, GLbitfield mask)
{
gl::ClearParameters clearParams = state.getClearParameters(mask);
ClearParameters clearParams = GetClearParameters(state, mask);
return clear(state, clearParams);
}
gl::Error FramebufferD3D::clearBufferfv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLfloat *values)
{
// glClearBufferfv can be called to clear the color buffer or depth buffer
gl::ClearParameters clearParams = state.getClearParameters(0);
ClearParameters clearParams = GetClearParameters(state, 0);
if (buffer == GL_COLOR)
{
......@@ -144,7 +206,7 @@ gl::Error FramebufferD3D::clearBufferfv(const gl::State &state, GLenum buffer, G
gl::Error FramebufferD3D::clearBufferuiv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLuint *values)
{
// glClearBufferuiv can only be called to clear a color buffer
gl::ClearParameters clearParams = state.getClearParameters(0);
ClearParameters clearParams = GetClearParameters(state, 0);
for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
{
clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i));
......@@ -158,7 +220,7 @@ gl::Error FramebufferD3D::clearBufferuiv(const gl::State &state, GLenum buffer,
gl::Error FramebufferD3D::clearBufferiv(const gl::State &state, GLenum buffer, GLint drawbuffer, const GLint *values)
{
// glClearBufferiv can be called to clear the color buffer or stencil buffer
gl::ClearParameters clearParams = state.getClearParameters(0);
ClearParameters clearParams = GetClearParameters(state, 0);
if (buffer == GL_COLOR)
{
......@@ -182,7 +244,7 @@ gl::Error FramebufferD3D::clearBufferiv(const gl::State &state, GLenum buffer, G
gl::Error FramebufferD3D::clearBufferfi(const gl::State &state, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
{
// glClearBufferfi can only be called to clear a depth stencil buffer
gl::ClearParameters clearParams = state.getClearParameters(0);
ClearParameters clearParams = GetClearParameters(state, 0);
clearParams.clearDepth = true;
clearParams.depthClearValue = depth;
clearParams.clearStencil = true;
......
......@@ -9,15 +9,15 @@
#ifndef LIBANGLE_RENDERER_D3D_FRAMBUFFERD3D_H_
#define LIBANGLE_RENDERER_D3D_FRAMBUFFERD3D_H_
#include "libANGLE/renderer/DefaultAttachmentImpl.h"
#include "libANGLE/renderer/FramebufferImpl.h"
#include <vector>
#include <cstdint>
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/DefaultAttachmentImpl.h"
#include "libANGLE/renderer/FramebufferImpl.h"
namespace gl
{
struct ClearParameters;
class FramebufferAttachment;
struct PixelPackState;
}
......@@ -27,6 +27,29 @@ namespace rx
class RenderTargetD3D;
class RendererD3D;
struct ClearParameters
{
bool clearColor[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS];
gl::ColorF colorFClearValue;
gl::ColorI colorIClearValue;
gl::ColorUI colorUIClearValue;
GLenum colorClearType;
bool colorMaskRed;
bool colorMaskGreen;
bool colorMaskBlue;
bool colorMaskAlpha;
bool clearDepth;
float depthClearValue;
bool clearStencil;
GLint stencilClearValue;
GLuint stencilWriteMask;
bool scissorEnabled;
gl::Rectangle scissor;
};
class DefaultAttachmentD3D : public DefaultAttachmentImpl
{
public:
......@@ -92,7 +115,7 @@ class FramebufferD3D : public FramebufferImpl
RendererD3D *const mRenderer;
virtual gl::Error clear(const gl::State &state, const gl::ClearParameters &clearParams) = 0;
virtual gl::Error clear(const gl::State &state, const ClearParameters &clearParams) = 0;
virtual gl::Error readPixels(const gl::Rectangle &area, GLenum format, GLenum type, size_t outputPitch,
const gl::PixelPackState &pack, uint8_t *pixels) const = 0;
......
......@@ -12,6 +12,7 @@
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h"
......@@ -173,7 +174,7 @@ Clear11::~Clear11()
SafeRelease(mRasterizerState);
}
gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, const gl::Framebuffer::Data &fboData)
gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl::Framebuffer::Data &fboData)
{
const auto &colorAttachments = fboData.mColorAttachments;
const auto &drawBufferStates = fboData.mDrawBufferStates;
......@@ -561,7 +562,7 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>&
}
}
ID3D11DepthStencilState *Clear11::getDepthStencilState(const gl::ClearParameters &clearParams)
ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &clearParams)
{
ClearDepthStencilInfo dsKey = { 0 };
dsKey.clearDepth = clearParams.clearDepth;
......
......@@ -9,17 +9,18 @@
#ifndef LIBANGLE_RENDERER_D3D_D3D11_CLEAR11_H_
#define LIBANGLE_RENDERER_D3D_D3D11_CLEAR11_H_
#include <map>
#include <vector>
#include "libANGLE/angletypes.h"
#include "libANGLE/Error.h"
#include "libANGLE/Framebuffer.h"
#include <map>
#include <vector>
namespace rx
{
class Renderer11;
class RenderTarget11;
struct ClearParameters;
class Clear11
{
......@@ -28,18 +29,10 @@ class Clear11
~Clear11();
// Clears the framebuffer with the supplied clear parameters, assumes that the framebuffer is currently applied.
gl::Error clearFramebuffer(const gl::ClearParameters &clearParams, const gl::Framebuffer::Data &fboData);
gl::Error clearFramebuffer(const ClearParameters &clearParams, const gl::Framebuffer::Data &fboData);
private:
Renderer11 *mRenderer;
struct ClearBlendInfo
{
bool maskChannels[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT][4];
};
typedef bool (*ClearBlendInfoComparisonFunction)(const ClearBlendInfo&, const ClearBlendInfo &);
typedef std::map<ClearBlendInfo, ID3D11BlendState*, ClearBlendInfoComparisonFunction> ClearBlendStateMap;
ClearBlendStateMap mClearBlendStates;
DISALLOW_COPY_AND_ASSIGN(Clear11);
struct MaskedRenderTarget
{
......@@ -48,6 +41,7 @@ class Clear11
};
ID3D11BlendState *getBlendState(const std::vector<MaskedRenderTarget> &rts);
ID3D11DepthStencilState *getDepthStencilState(const ClearParameters &clearParams);
struct ClearShader
{
......@@ -55,13 +49,24 @@ class Clear11
ID3D11VertexShader *vertexShader;
ID3D11PixelShader *pixelShader;
};
template <unsigned int vsSize, unsigned int psSize>
static ClearShader CreateClearShader(ID3D11Device *device, DXGI_FORMAT colorType, const BYTE(&vsByteCode)[vsSize], const BYTE(&psByteCode)[psSize]);
Renderer11 *mRenderer;
struct ClearBlendInfo
{
bool maskChannels[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT][4];
};
typedef bool(*ClearBlendInfoComparisonFunction)(const ClearBlendInfo&, const ClearBlendInfo &);
typedef std::map<ClearBlendInfo, ID3D11BlendState*, ClearBlendInfoComparisonFunction> ClearBlendStateMap;
ClearBlendStateMap mClearBlendStates;
ClearShader mFloatClearShader;
ClearShader mUintClearShader;
ClearShader mIntClearShader;
template <unsigned int vsSize, unsigned int psSize>
static ClearShader CreateClearShader(ID3D11Device *device, DXGI_FORMAT colorType, const BYTE (&vsByteCode)[vsSize], const BYTE (&psByteCode)[psSize]);
struct ClearDepthStencilInfo
{
bool clearDepth;
......@@ -72,8 +77,6 @@ class Clear11
typedef std::map<ClearDepthStencilInfo, ID3D11DepthStencilState*, ClearDepthStencilInfoComparisonFunction> ClearDepthStencilStateMap;
ClearDepthStencilStateMap mClearDepthStencilStates;
ID3D11DepthStencilState *getDepthStencilState(const gl::ClearParameters &clearParams);
ID3D11Buffer *mVertexBuffer;
ID3D11RasterizerState *mRasterizerState;
......
......@@ -88,7 +88,7 @@ gl::Error Framebuffer11::invalidateSwizzles() const
return gl::Error(GL_NO_ERROR);
}
gl::Error Framebuffer11::clear(const gl::State &state, const gl::ClearParameters &clearParams)
gl::Error Framebuffer11::clear(const gl::State &state, const ClearParameters &clearParams)
{
Clear11 *clearer = mRenderer->getClearer();
gl::Error error = clearer->clearFramebuffer(clearParams, mData);
......
......@@ -25,7 +25,7 @@ class Framebuffer11 : public FramebufferD3D
gl::Error invalidateSwizzles() const;
private:
gl::Error clear(const gl::State &state, const gl::ClearParameters &clearParams) override;
gl::Error clear(const gl::State &state, const ClearParameters &clearParams) override;
gl::Error readPixels(const gl::Rectangle &area, GLenum format, GLenum type, size_t outputPitch,
const gl::PixelPackState &pack, uint8_t *pixels) const override;
......
......@@ -32,7 +32,7 @@ Framebuffer9::~Framebuffer9()
{
}
gl::Error Framebuffer9::clear(const gl::State &state, const gl::ClearParameters &clearParams)
gl::Error Framebuffer9::clear(const gl::State &state, const ClearParameters &clearParams)
{
const gl::FramebufferAttachment *colorAttachment = mData.mColorAttachments[0];
const gl::FramebufferAttachment *depthStencilAttachment = mData.getDepthOrStencilAttachment();
......
......@@ -22,7 +22,7 @@ class Framebuffer9 : public FramebufferD3D
virtual ~Framebuffer9();
private:
gl::Error clear(const gl::State &state, const gl::ClearParameters &clearParams) override;
gl::Error clear(const gl::State &state, const ClearParameters &clearParams) override;
gl::Error readPixels(const gl::Rectangle &area, GLenum format, GLenum type, size_t outputPitch,
const gl::PixelPackState &pack, uint8_t *pixels) const override;
......
......@@ -1969,7 +1969,8 @@ void Renderer9::applyUniformnbv(gl::LinkedUniform *targetUniform, const GLint *v
applyUniformnfv(targetUniform, (GLfloat*)vector);
}
gl::Error Renderer9::clear(const gl::ClearParameters &clearParams, const gl::FramebufferAttachment *colorBuffer,
gl::Error Renderer9::clear(const ClearParameters &clearParams,
const gl::FramebufferAttachment *colorBuffer,
const gl::FramebufferAttachment *depthStencilBuffer)
{
if (clearParams.colorClearType != GL_FLOAT)
......
......@@ -29,12 +29,13 @@ class AttributeMap;
namespace rx
{
class VertexDataManager;
class Blit9;
class IndexDataManager;
class StreamingIndexBufferInterface;
class StaticIndexBufferInterface;
class VertexDataManager;
struct ClearParameters;
struct TranslatedAttribute;
class Blit9;
enum D3D9InitError
{
......@@ -116,7 +117,8 @@ class Renderer9 : public RendererD3D
virtual gl::Error drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances);
gl::Error clear(const gl::ClearParameters &clearParams, const gl::FramebufferAttachment *colorBuffer,
gl::Error clear(const ClearParameters &clearParams,
const gl::FramebufferAttachment *colorBuffer,
const gl::FramebufferAttachment *depthStencilBuffer);
virtual void markAllStateDirty();
......
......@@ -645,7 +645,7 @@ void GL_APIENTRY ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclamp
Context *context = GetValidGlobalContext();
if (context)
{
context->getState().setClearColor(red, green, blue, alpha);
context->getState().setColorClearValue(red, green, blue, alpha);
}
}
......@@ -656,7 +656,7 @@ void GL_APIENTRY ClearDepthf(GLclampf depth)
Context *context = GetValidGlobalContext();
if (context)
{
context->getState().setClearDepth(depth);
context->getState().setDepthClearValue(depth);
}
}
......@@ -667,7 +667,7 @@ void GL_APIENTRY ClearStencil(GLint s)
Context *context = GetValidGlobalContext();
if (context)
{
context->getState().setClearStencil(s);
context->getState().setStencilClearValue(s);
}
}
......
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