Commit 4ad1709f by Geoff Lang

Implement FramebufferGL.

BUG=angleproject:885 Change-Id: Ifb5818f185236c671cd7f20ed352edb887b49675 Reviewed-on: https://chromium-review.googlesource.com/258420Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 0728514a
......@@ -82,9 +82,17 @@ FramebufferAttachment *Framebuffer::Data::getDepthOrStencilAttachment() const
Framebuffer::Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id)
: mData(caps),
mImpl(factory->createFramebuffer(mData)),
mImpl(nullptr),
mId(id)
{
if (mId == 0)
{
mImpl = factory->createDefaultFramebuffer(mData);
}
else
{
mImpl = factory->createFramebuffer(mData);
}
ASSERT(mImpl != nullptr);
}
......
......@@ -15,6 +15,19 @@
namespace gl
{
bool operator==(const Rectangle &a, const Rectangle &b)
{
return a.x == b.x &&
a.y == b.y &&
a.width == b.width &&
a.height == b.height;
}
bool operator!=(const Rectangle &a, const Rectangle &b)
{
return !(a == b);
}
SamplerState::SamplerState()
: minFilter(GL_NEAREST_MIPMAP_LINEAR),
magFilter(GL_LINEAR),
......
......@@ -40,6 +40,21 @@ struct Color
Color(T r, T g, T b, T a) : red(r), green(g), blue(b), alpha(a) { }
};
template <typename T>
bool operator==(const Color<T> &a, const Color<T> &b)
{
return a.red == b.red &&
a.green == b.green &&
a.blue == b.blue &&
a.alpha == b.alpha;
}
template <typename T>
bool operator!=(const Color<T> &a, const Color<T> &b)
{
return !(a == b);
}
typedef Color<float> ColorF;
typedef Color<int> ColorI;
typedef Color<unsigned int> ColorUI;
......@@ -55,6 +70,9 @@ struct Rectangle
Rectangle(int x_in, int y_in, int width_in, int height_in) : x(x_in), y(y_in), width(width_in), height(height_in) { }
};
bool operator==(const Rectangle &a, const Rectangle &b);
bool operator!=(const Rectangle &a, const Rectangle &b);
bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *intersection);
struct Offset
......
......@@ -41,6 +41,7 @@ class ImplFactory
// Framebuffer creation
virtual DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) = 0;
virtual FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) = 0;
virtual FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) = 0;
// Texture creation
......
......@@ -2647,6 +2647,11 @@ DefaultAttachmentImpl *Renderer11::createDefaultAttachment(GLenum type, egl::Sur
}
}
FramebufferImpl *Renderer11::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return createFramebuffer(data);
}
FramebufferImpl *Renderer11::createFramebuffer(const gl::Framebuffer::Data &data)
{
return new Framebuffer11(data, this);
......
......@@ -149,6 +149,7 @@ class Renderer11 : public RendererD3D
// Framebuffer creation
DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override;
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation
......
......@@ -2656,6 +2656,11 @@ DefaultAttachmentImpl *Renderer9::createDefaultAttachment(GLenum type, egl::Surf
}
}
FramebufferImpl *Renderer9::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return createFramebuffer(data);
}
FramebufferImpl *Renderer9::createFramebuffer(const gl::Framebuffer::Data &data)
{
return new Framebuffer9(data, this);
......
......@@ -162,6 +162,7 @@ class Renderer9 : public RendererD3D
// Framebuffer creation
DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override;
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation
......
......@@ -9,39 +9,44 @@
#include "libANGLE/renderer/gl/DefaultAttachmentGL.h"
#include "common/debug.h"
#include "libANGLE/Config.h"
#include "libANGLE/renderer/gl/SurfaceGL.h"
namespace rx
{
DefaultAttachmentGL::DefaultAttachmentGL()
: DefaultAttachmentImpl()
{}
DefaultAttachmentGL::DefaultAttachmentGL(GLenum type, SurfaceGL *surface)
: DefaultAttachmentImpl(),
mType(type),
mSurface(surface)
{
ASSERT(mSurface != nullptr);
}
DefaultAttachmentGL::~DefaultAttachmentGL()
{}
{
}
GLsizei DefaultAttachmentGL::getWidth() const
{
UNIMPLEMENTED();
return GLsizei();
return mSurface->getWidth();
}
GLsizei DefaultAttachmentGL::getHeight() const
{
UNIMPLEMENTED();
return GLsizei();
return mSurface->getHeight();
}
GLenum DefaultAttachmentGL::getInternalFormat() const
{
UNIMPLEMENTED();
return GLenum();
const egl::Config *config = mSurface->getConfig();
return (mType == GL_COLOR ? config->renderTargetFormat : config->depthStencilFormat);
}
GLsizei DefaultAttachmentGL::getSamples() const
{
UNIMPLEMENTED();
return GLsizei();
const egl::Config *config = mSurface->getConfig();
return config->samples;
}
}
......@@ -14,10 +14,12 @@
namespace rx
{
class SurfaceGL;
class DefaultAttachmentGL : public DefaultAttachmentImpl
{
public:
DefaultAttachmentGL();
DefaultAttachmentGL(GLenum type, SurfaceGL *surface);
~DefaultAttachmentGL() override;
GLsizei getWidth() const override;
......@@ -27,6 +29,9 @@ class DefaultAttachmentGL : public DefaultAttachmentImpl
private:
DISALLOW_COPY_AND_ASSIGN(DefaultAttachmentGL);
GLenum mType;
SurfaceGL *mSurface;
};
}
......
......@@ -14,10 +14,13 @@
namespace rx
{
class FunctionsGL;
class StateManagerGL;
class FramebufferGL : public FramebufferImpl
{
public:
FramebufferGL(const gl::Framebuffer::Data &data);
FramebufferGL(const gl::Framebuffer::Data &data, const FunctionsGL *functions, StateManagerGL *stateManager, bool isDefault);
~FramebufferGL() override;
void setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) override;
......@@ -46,8 +49,15 @@ class FramebufferGL : public FramebufferImpl
GLenum checkStatus() const override;
GLuint getFramebufferID() const;
private:
DISALLOW_COPY_AND_ASSIGN(FramebufferGL);
const FunctionsGL *mFunctions;
StateManagerGL *mStateManager;
GLuint mFramebufferID;
};
}
......
......@@ -10,6 +10,7 @@
#include "common/debug.h"
#include "libANGLE/Data.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/gl/BufferGL.h"
#include "libANGLE/renderer/gl/CompilerGL.h"
#include "libANGLE/renderer/gl/DefaultAttachmentGL.h"
......@@ -22,6 +23,7 @@
#include "libANGLE/renderer/gl/RenderbufferGL.h"
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/SurfaceGL.h"
#include "libANGLE/renderer/gl/TextureGL.h"
#include "libANGLE/renderer/gl/TransformFeedbackGL.h"
#include "libANGLE/renderer/gl/VertexArrayGL.h"
......@@ -108,12 +110,17 @@ ProgramImpl *RendererGL::createProgram()
DefaultAttachmentImpl *RendererGL::createDefaultAttachment(GLenum type, egl::Surface *surface)
{
return new DefaultAttachmentGL();
return new DefaultAttachmentGL(type, GetImplAs<SurfaceGL>(surface));
}
FramebufferImpl *RendererGL::createDefaultFramebuffer(const gl::Framebuffer::Data &data)
{
return new FramebufferGL(data, mFunctions, mStateManager, true);
}
FramebufferImpl *RendererGL::createFramebuffer(const gl::Framebuffer::Data &data)
{
return new FramebufferGL(data);
return new FramebufferGL(data, mFunctions, mStateManager, false);
}
TextureImpl *RendererGL::createTexture(GLenum target)
......
......@@ -38,6 +38,7 @@ class RendererGL : public Renderer
// Framebuffer creation
DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override;
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Texture creation
......
......@@ -9,7 +9,9 @@
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/Data.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/ProgramGL.h"
#include "libANGLE/renderer/gl/TextureGL.h"
......@@ -26,7 +28,19 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &ren
mTextureUnitIndex(0),
mTextures(),
mUnpackAlignment(4),
mUnpackRowLength(0)
mUnpackRowLength(0),
mFramebuffers(),
mScissor(0, 0, 0, 0),
mViewport(0, 0, 0, 0),
mClearColor(0.0f, 0.0f, 0.0f, 0.0f),
mColorMaskRed(true),
mColorMaskGreen(true),
mColorMaskBlue(true),
mColorMaskAlpha(true),
mClearDepth(1.0f),
mDepthMask(true),
mClearStencil(0),
mStencilMask(static_cast<GLuint>(-1))
{
ASSERT(mFunctions);
......@@ -34,6 +48,9 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &ren
mTextures[GL_TEXTURE_CUBE_MAP].resize(rendererCaps.maxCombinedTextureImageUnits);
mTextures[GL_TEXTURE_2D_ARRAY].resize(rendererCaps.maxCombinedTextureImageUnits);
mTextures[GL_TEXTURE_3D].resize(rendererCaps.maxCombinedTextureImageUnits);
mFramebuffers[GL_READ_FRAMEBUFFER] = 0;
mFramebuffers[GL_DRAW_FRAMEBUFFER] = 0;
}
void StateManagerGL::useProgram(GLuint program)
......@@ -96,6 +113,42 @@ void StateManagerGL::setPixelUnpackState(GLint alignment, GLint rowLength)
}
}
void StateManagerGL::bindFramebuffer(GLenum type, GLuint framebuffer)
{
if (mFramebuffers[type] != framebuffer)
{
mFramebuffers[type] = framebuffer;
mFunctions->bindFramebuffer(type, framebuffer);
}
}
void StateManagerGL::setClearState(const gl::State &state, GLbitfield mask)
{
// Only apply the state required to do a clear
setScissor(state.getScissor());
setViewport(state.getViewport());
if ((mask & GL_COLOR_BUFFER_BIT) != 0)
{
setClearColor(state.getColorClearValue());
const gl::BlendState &blendState = state.getBlendState();
setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha);
}
if ((mask & GL_DEPTH_BUFFER_BIT) != 0)
{
setClearDepth(state.getDepthClearValue());
setDepthMask(state.getDepthStencilState().depthMask);
}
if ((mask & GL_STENCIL_BUFFER_BIT) != 0)
{
setClearStencil(state.getStencilClearValue());
setStencilMask(state.getDepthStencilState().stencilMask);
}
}
gl::Error StateManagerGL::setDrawArraysState(const gl::Data &data, GLint first, GLsizei count)
{
const gl::State &state = *data.state;
......@@ -181,7 +234,96 @@ gl::Error StateManagerGL::setGenericDrawState(const gl::Data &data)
}
}
const gl::Framebuffer *framebuffer = state.getDrawFramebuffer();
const FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(framebuffer);
bindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferGL->getFramebufferID());
setScissor(state.getScissor());
setViewport(state.getViewport());
const gl::BlendState &blendState = state.getBlendState();
setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha);
const gl::DepthStencilState &depthStencilState = state.getDepthStencilState();
setDepthMask(depthStencilState.depthMask);
setStencilMask(depthStencilState.stencilMask);
return gl::Error(GL_NO_ERROR);
}
void StateManagerGL::setScissor(const gl::Rectangle &scissor)
{
if (scissor != mScissor)
{
mScissor = scissor;
mFunctions->scissor(mScissor.x, mScissor.y, mScissor.width, mScissor.height);
}
}
void StateManagerGL::setViewport(const gl::Rectangle &viewport)
{
if (viewport != mViewport)
{
mViewport = viewport;
mFunctions->viewport(mViewport.x, mViewport.y, mViewport.width, mViewport.height);
}
}
void StateManagerGL::setClearColor(const gl::ColorF &clearColor)
{
if (mClearColor != clearColor)
{
mClearColor = clearColor;
mFunctions->clearColor(mClearColor.red, mClearColor.green, mClearColor.blue, mClearColor.alpha);
}
}
void StateManagerGL::setColorMask(bool red, bool green, bool blue, bool alpha)
{
if (mColorMaskRed != red || mColorMaskGreen != green || mColorMaskBlue != blue || mColorMaskAlpha != alpha)
{
mColorMaskRed = red;
mColorMaskGreen = green;
mColorMaskBlue = blue;
mColorMaskAlpha = alpha;
mFunctions->colorMask(mColorMaskRed, mColorMaskGreen, mColorMaskBlue, mColorMaskAlpha);
}
}
void StateManagerGL::setClearDepth(float clearDepth)
{
if (mClearDepth != clearDepth)
{
mClearDepth = clearDepth;
mFunctions->clearDepth(mClearDepth);
}
}
void StateManagerGL::setDepthMask(bool mask)
{
if (mDepthMask != mask)
{
mDepthMask = mask;
mFunctions->depthMask(mDepthMask);
}
}
void StateManagerGL::setClearStencil(GLint clearStencil)
{
if (mClearStencil != clearStencil)
{
mClearStencil = clearStencil;
mFunctions->clearStencil(mClearStencil);
}
}
void StateManagerGL::setStencilMask(GLuint mask)
{
if (mStencilMask != mask)
{
mStencilMask = mask;
mFunctions->stencilMask(mStencilMask);
}
}
}
......@@ -11,6 +11,7 @@
#include "common/debug.h"
#include "libANGLE/Error.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/gl/functionsgl_typedefs.h"
#include <map>
......@@ -19,6 +20,7 @@ namespace gl
{
struct Caps;
struct Data;
class State;
}
namespace rx
......@@ -37,6 +39,9 @@ class StateManagerGL
void activeTexture(size_t unit);
void bindTexture(GLenum type, GLuint texture);
void setPixelUnpackState(GLint alignment, GLint rowLength);
void bindFramebuffer(GLenum type, GLuint framebuffer);
void setClearState(const gl::State &state, GLbitfield mask);
gl::Error setDrawArraysState(const gl::Data &data, GLint first, GLsizei count);
gl::Error setDrawElementsState(const gl::Data &data, GLsizei count, GLenum type, const GLvoid *indices,
......@@ -47,6 +52,15 @@ class StateManagerGL
gl::Error setGenericDrawState(const gl::Data &data);
void setScissor(const gl::Rectangle &scissor);
void setViewport(const gl::Rectangle &viewport);
void setClearColor(const gl::ColorF &clearColor);
void setColorMask(bool red, bool green, bool blue, bool alpha);
void setClearDepth(float clearDepth);
void setDepthMask(bool mask);
void setClearStencil(GLint clearStencil);
void setStencilMask(GLuint mask);
const FunctionsGL *mFunctions;
GLuint mProgram;
......@@ -58,6 +72,23 @@ class StateManagerGL
GLint mUnpackAlignment;
GLint mUnpackRowLength;
std::map<GLenum, GLuint> mFramebuffers;
gl::Rectangle mScissor;
gl::Rectangle mViewport;
gl::ColorF mClearColor;
bool mColorMaskRed;
bool mColorMaskGreen;
bool mColorMaskBlue;
bool mColorMaskAlpha;
float mClearDepth;
bool mDepthMask;
GLint mClearStencil;
GLuint mStencilMask;
};
}
......
......@@ -40,8 +40,8 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM
caps->maxArrayTextureLayers = QuerySingleGLInt(functions, GL_MAX_ARRAY_TEXTURE_LAYERS);
caps->maxLODBias = 2.0f;
caps->maxRenderbufferSize = 2048;
caps->maxDrawBuffers = 4;
caps->maxColorAttachments = 4;
caps->maxDrawBuffers = QuerySingleGLInt(functions, GL_MAX_DRAW_BUFFERS);
caps->maxColorAttachments = QuerySingleGLInt(functions, GL_MAX_COLOR_ATTACHMENTS);
caps->maxViewportWidth = caps->max2DTextureSize;
caps->maxViewportHeight = caps->maxViewportWidth;
caps->minAliasedPointSize = 1.0f;
......
......@@ -392,8 +392,8 @@ egl::ConfigSet DisplayWGL::generateConfigs() const
DescribePixelFormat(mDeviceContext, mPixelFormat, sizeof(pixelFormatDescriptor), &pixelFormatDescriptor);
egl::Config config;
config.renderTargetFormat = GL_NONE; // TODO
config.depthStencilFormat = GL_NONE; // TODO
config.renderTargetFormat = GL_RGBA8; // TODO: use the bit counts to determine the format
config.depthStencilFormat = GL_DEPTH24_STENCIL8; // TODO: use the bit counts to determine the format
config.bufferSize = pixelFormatDescriptor.cColorBits;
config.redSize = pixelFormatDescriptor.cRedBits;
config.greenSize = pixelFormatDescriptor.cGreenBits;
......
......@@ -27,6 +27,7 @@ class NullFactory : public ImplFactory
// Framebuffer creation
DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override { return nullptr; }
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override { return nullptr; }
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override { return nullptr; }
// Texture creation
......
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