mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-02 09:03:37 +00:00
BufferManipulationObjects WIP
This commit is contained in:
parent
8357729020
commit
cf5e9d8ed2
|
@ -301,6 +301,7 @@
|
|||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\Context.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLFunctions.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_BufferManipulationObjectFactory.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_CachedFunctions.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Parameters.cpp" />
|
||||
|
@ -430,6 +431,7 @@
|
|||
<ClInclude Include="..\..\src\Graphics\ContextImpl.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\ObjectHandle.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLFunctions.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_BufferManipulationObjectFactory.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_CachedFunctions.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GLVersion.h" />
|
||||
|
|
|
@ -293,6 +293,9 @@
|
|||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_CachedFunctions.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_BufferManipulationObjectFactory.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\3DMath.h">
|
||||
|
@ -535,5 +538,8 @@
|
|||
<ClInclude Include="..\..\src\Graphics\ObjectHandle.h">
|
||||
<Filter>Header Files\Graphics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_BufferManipulationObjectFactory.h">
|
||||
<Filter>Header Files\Graphics\OpenGL</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -25,9 +25,15 @@ DepthBuffer::DepthBuffer() : m_address(0), m_width(0), m_ulx(0), m_uly(0), m_lrx
|
|||
m_cleared(false), m_pResolveDepthBufferTexture(nullptr), m_resolved(false),
|
||||
m_pDepthBufferCopyTexture(nullptr), m_copied(false)
|
||||
{
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
glGenFramebuffers(1, &m_copyFBO);
|
||||
if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0)
|
||||
glGenFramebuffers(1, &m_depthImageFBO);
|
||||
#else // GRAPHICS_CONTEXT
|
||||
m_copyFBO = GLuint(gfxContext.createFramebuffer());
|
||||
if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0)
|
||||
m_depthImageFBO = GLuint(gfxContext.createFramebuffer());
|
||||
#endif
|
||||
}
|
||||
|
||||
DepthBuffer::DepthBuffer(DepthBuffer && _other) :
|
||||
|
@ -50,20 +56,23 @@ DepthBuffer::DepthBuffer(DepthBuffer && _other) :
|
|||
|
||||
DepthBuffer::~DepthBuffer()
|
||||
{
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
if (m_depthImageFBO != 0)
|
||||
glDeleteFramebuffers(1, &m_depthImageFBO);
|
||||
if (m_pDepthImageTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pDepthImageTexture);
|
||||
if (m_pDepthBufferTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pDepthBufferTexture);
|
||||
if (m_depthRenderbuffer != 0)
|
||||
glDeleteRenderbuffers(1, &m_depthRenderbuffer);
|
||||
if (m_pResolveDepthBufferTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pResolveDepthBufferTexture);
|
||||
if (m_copyFBO != 0)
|
||||
glDeleteFramebuffers(1, &m_copyFBO);
|
||||
if (m_pDepthBufferCopyTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pDepthBufferCopyTexture);
|
||||
#else
|
||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_depthImageFBO));
|
||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_depthRenderbuffer));
|
||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_copyFBO));
|
||||
#endif
|
||||
|
||||
textureCache().removeFrameBufferTexture(m_pDepthImageTexture);
|
||||
textureCache().removeFrameBufferTexture(m_pDepthBufferTexture);
|
||||
textureCache().removeFrameBufferTexture(m_pResolveDepthBufferTexture);
|
||||
textureCache().removeFrameBufferTexture(m_pDepthBufferCopyTexture);
|
||||
}
|
||||
|
||||
void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer)
|
||||
|
@ -198,6 +207,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
|
|||
params.dataType = fboFormats.depthType;
|
||||
gfxContext.init2DTexture(params);
|
||||
}
|
||||
_pTexture->frameBufferTexture = _multisample ? CachedTexture::fbMultiSample : CachedTexture::fbOneSample;
|
||||
{
|
||||
graphics::Context::TexParameters params;
|
||||
params.handle = graphics::ObjectHandle(_pTexture->glName);
|
||||
|
|
|
@ -42,23 +42,30 @@ FrameBuffer::FrameBuffer() :
|
|||
{
|
||||
m_loadTileOrigin.uls = m_loadTileOrigin.ult = 0;
|
||||
m_pTexture = textureCache().addFrameBufferTexture(config.video.multisampling != 0);
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
glGenFramebuffers(1, &m_FBO);
|
||||
#else
|
||||
m_FBO = GLuint(gfxContext.createFramebuffer());
|
||||
#endif
|
||||
}
|
||||
|
||||
FrameBuffer::~FrameBuffer()
|
||||
{
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
if (m_FBO != 0)
|
||||
glDeleteFramebuffers(1, &m_FBO);
|
||||
if (m_pTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
if (m_resolveFBO != 0)
|
||||
glDeleteFramebuffers(1, &m_resolveFBO);
|
||||
if (m_pResolveTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pResolveTexture);
|
||||
if (m_SubFBO != 0)
|
||||
glDeleteFramebuffers(1, &m_SubFBO);
|
||||
if (m_pSubTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pSubTexture);
|
||||
#else
|
||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_FBO));
|
||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_resolveFBO));
|
||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_SubFBO));
|
||||
#endif
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
textureCache().removeFrameBufferTexture(m_pResolveTexture);
|
||||
textureCache().removeFrameBufferTexture(m_pSubTexture);
|
||||
}
|
||||
|
||||
void FrameBuffer::_initTexture(u16 _width, u16 _height, u16 _format, u16 _size, CachedTexture *_pTexture)
|
||||
|
@ -87,11 +94,11 @@ void FrameBuffer::_initTexture(u16 _width, u16 _height, u16 _format, u16 _size,
|
|||
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
|
||||
}
|
||||
|
||||
void FrameBuffer::_setAndAttachTexture(u16 _size, CachedTexture *_pTexture, u32 _t, bool _multisampling)
|
||||
void FrameBuffer::_setAndAttachTexture(u32 _fbo, CachedTexture *_pTexture, u32 _t, bool _multisampling)
|
||||
{
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
glBindTexture(GL_TEXTURE_2D, _pTexture->glName);
|
||||
if (_size > G_IM_SIZ_8b) {
|
||||
if (_pTexture->size > G_IM_SIZ_8b) {
|
||||
|
||||
#if defined(GLES3) || defined (GLES3_1)
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, fboFormats.colorInternalFormat, _pTexture->realWidth, _pTexture->realHeight);
|
||||
|
@ -110,6 +117,9 @@ void FrameBuffer::_setAndAttachTexture(u16 _size, CachedTexture *_pTexture, u32
|
|||
}
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _pTexture->glName, 0);
|
||||
#else // GRAPHICS_CONTEXT
|
||||
{
|
||||
graphics::Context::InitTextureParams params;
|
||||
|
@ -118,7 +128,7 @@ void FrameBuffer::_setAndAttachTexture(u16 _size, CachedTexture *_pTexture, u32
|
|||
params.msaaLevel = config.video.multisampling;
|
||||
params.width = _pTexture->realWidth;
|
||||
params.height = _pTexture->realHeight;
|
||||
if (_size > G_IM_SIZ_8b) {
|
||||
if (_pTexture->size > G_IM_SIZ_8b) {
|
||||
params.internalFormat = fboFormats.colorInternalFormat;
|
||||
params.format = fboFormats.colorFormat;
|
||||
params.dataType = fboFormats.colorType;
|
||||
|
@ -139,9 +149,17 @@ void FrameBuffer::_setAndAttachTexture(u16 _size, CachedTexture *_pTexture, u32
|
|||
params.magFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
gfxContext.setTextureParameters(params);
|
||||
}
|
||||
{
|
||||
graphics::Context::FrameBufferRenderTarget bufTarget;
|
||||
bufTarget.bufferHandle = graphics::ObjectHandle(_fbo);
|
||||
bufTarget.bufferTarget = graphics::bufferTarget::FRAMEBUFFER;
|
||||
bufTarget.attachment = graphics::bufferAttachment::COLOR_ATTACHMENT0;
|
||||
bufTarget.textureTarget = _multisampling ? graphics::target::TEXTURE_2D_MULTISAMPLE : graphics::target::TEXTURE_2D;
|
||||
bufTarget.textureHandle = graphics::ObjectHandle(_pTexture->glName);
|
||||
gfxContext.addFrameBufferRenderTarget(bufTarget);
|
||||
}
|
||||
assert(checkFBO());
|
||||
#endif // GRAPHICS_CONTEXT
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _pTexture->glName, 0);
|
||||
}
|
||||
|
||||
bool FrameBuffer::_isMarioTennisScoreboard() const
|
||||
|
@ -183,11 +201,11 @@ void FrameBuffer::init(u32 _address, u32 _endAddress, u16 _format, u16 _size, u1
|
|||
m_fingerprint = false;
|
||||
|
||||
_initTexture(_width, _height, _format, _size, m_pTexture);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
|
||||
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
|
||||
#ifdef GL_MULTISAMPLING_SUPPORT
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
|
||||
|
||||
if (config.video.multisampling != 0) {
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_pTexture->glName);
|
||||
#if defined(GLESX)
|
||||
|
@ -208,31 +226,29 @@ void FrameBuffer::init(u32 _address, u32 _endAddress, u16 _format, u16 _size, u1
|
|||
_initTexture(_width, _height, _format, _size, m_pResolveTexture);
|
||||
glGenFramebuffers(1, &m_resolveFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_resolveFBO);
|
||||
_setAndAttachTexture(_size, m_pResolveTexture, 0, false);
|
||||
_setAndAttachTexture(m_resolveFBO, m_pResolveTexture, 0, false);
|
||||
assert(checkFBO());
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
|
||||
} else
|
||||
#endif // GL_MULTISAMPLING_SUPPORT
|
||||
_setAndAttachTexture(_size, m_pTexture, 0, false);
|
||||
_setAndAttachTexture(m_FBO, m_pTexture, 0, false);
|
||||
|
||||
#else // GRAPHICS_CONTEXT
|
||||
|
||||
if (config.video.multisampling != 0) {
|
||||
_setAndAttachTexture(_size, m_pTexture, 0, true);
|
||||
_setAndAttachTexture(m_FBO, m_pTexture, 0, true);
|
||||
m_pTexture->frameBufferTexture = CachedTexture::fbMultiSample;
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_pTexture->glName, 0);
|
||||
|
||||
m_pResolveTexture = textureCache().addFrameBufferTexture(false);
|
||||
_initTexture(_width, _height, _format, _size, m_pResolveTexture);
|
||||
glGenFramebuffers(1, &m_resolveFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_resolveFBO);
|
||||
_setAndAttachTexture(_size, m_pResolveTexture, 0, false);
|
||||
m_resolveFBO = GLuint(gfxContext.createFramebuffer());
|
||||
_setAndAttachTexture(m_resolveFBO, m_pResolveTexture, 0, false);
|
||||
assert(checkFBO());
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
|
||||
} else
|
||||
_setAndAttachTexture(_size, m_pTexture, 0, false);
|
||||
_setAndAttachTexture(m_FBO, m_pTexture, 0, false);
|
||||
|
||||
#endif // GRAPHICS_CONTEXT
|
||||
|
||||
|
@ -243,12 +259,16 @@ void FrameBuffer::reinit(u16 _height)
|
|||
{
|
||||
const u16 format = m_pTexture->format;
|
||||
const u32 endAddress = m_startAddress + ((m_width * _height) << m_size >> 1) - 1;
|
||||
if (m_pTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
if (m_resolveFBO != 0)
|
||||
glDeleteFramebuffers(1, &m_resolveFBO);
|
||||
if (m_pResolveTexture != nullptr)
|
||||
textureCache().removeFrameBufferTexture(m_pResolveTexture);
|
||||
#else
|
||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_resolveFBO));
|
||||
#endif
|
||||
|
||||
textureCache().removeFrameBufferTexture(m_pResolveTexture);
|
||||
m_pTexture = textureCache().addFrameBufferTexture(config.video.multisampling != 0);
|
||||
init(m_startAddress, endAddress, format, m_size, m_width, _height, m_cfb);
|
||||
}
|
||||
|
@ -378,8 +398,13 @@ void FrameBuffer::resolveMultisampledTexture(bool _bForce)
|
|||
|
||||
bool FrameBuffer::_initSubTexture(u32 _t)
|
||||
{
|
||||
#ifndef GRAPHICS_CONTEXT
|
||||
if (m_SubFBO == 0)
|
||||
glGenFramebuffers(1, &m_SubFBO);
|
||||
#else
|
||||
if (m_SubFBO == 0)
|
||||
m_SubFBO = GLuint(gfxContext.createFramebuffer());
|
||||
#endif
|
||||
|
||||
gDPTile * pTile = gSP.textureTile[_t];
|
||||
if (pTile->lrs < pTile->uls || pTile->lrt < pTile->ult)
|
||||
|
@ -430,8 +455,7 @@ bool FrameBuffer::_initSubTexture(u32 _t)
|
|||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pSubTexture->glName, 0);
|
||||
#else // GRAPHICS_CONTEXT
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_SubFBO);
|
||||
_setAndAttachTexture(m_pSubTexture->size, m_pSubTexture, _t, false);
|
||||
_setAndAttachTexture(m_SubFBO, m_pSubTexture, _t, false);
|
||||
|
||||
#endif // GRAPHICS_CONTEXT
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ private:
|
|||
} m_clearParams;
|
||||
|
||||
void _initTexture(u16 _width, u16 _height, u16 _format, u16 _size, CachedTexture *_pTexture);
|
||||
void _setAndAttachTexture(u16 _size, CachedTexture *_pTexture, u32 _t, bool _multisampling);
|
||||
void _setAndAttachTexture(u32 _fbo, CachedTexture *_pTexture, u32 _t, bool _multisampling);
|
||||
bool _initSubTexture(u32 _t);
|
||||
CachedTexture * _getSubTexture(u32 _t);
|
||||
mutable u32 m_validityChecked;
|
||||
|
|
|
@ -43,6 +43,21 @@ void Context::setTextureParameters(const TexParameters & _parameters)
|
|||
m_impl->setTextureParameters(_parameters);
|
||||
}
|
||||
|
||||
ObjectHandle Context::createFramebuffer()
|
||||
{
|
||||
return m_impl->createFramebuffer();
|
||||
}
|
||||
|
||||
void Context::deleteFramebuffer(ObjectHandle _name)
|
||||
{
|
||||
m_impl->deleteFramebuffer(_name);
|
||||
}
|
||||
|
||||
void Context::addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params)
|
||||
{
|
||||
m_impl->addFrameBufferRenderTarget(_params);
|
||||
}
|
||||
|
||||
bool Context::isMultisamplingSupported() const
|
||||
{
|
||||
// TODO
|
||||
|
|
|
@ -53,6 +53,20 @@ namespace graphics {
|
|||
|
||||
void setTextureParameters(const TexParameters & _parameters);
|
||||
|
||||
ObjectHandle createFramebuffer();
|
||||
|
||||
void deleteFramebuffer(ObjectHandle _name);
|
||||
|
||||
struct FrameBufferRenderTarget {
|
||||
ObjectHandle bufferHandle;
|
||||
Parameter bufferTarget;
|
||||
Parameter attachment;
|
||||
Parameter textureTarget;
|
||||
ObjectHandle textureHandle;
|
||||
};
|
||||
|
||||
void addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params);
|
||||
|
||||
bool isMultisamplingSupported() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -16,6 +16,9 @@ namespace graphics {
|
|||
virtual void deleteTexture(ObjectHandle _name) = 0;
|
||||
virtual void init2DTexture(const Context::InitTextureParams & _params) = 0;
|
||||
virtual void setTextureParameters(const Context::TexParameters & _parameters) = 0;
|
||||
virtual ObjectHandle createFramebuffer() = 0;
|
||||
virtual void deleteFramebuffer(ObjectHandle _name) = 0;
|
||||
virtual void addFrameBufferRenderTarget(const Context::FrameBufferRenderTarget & _params) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -97,6 +97,9 @@ PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC glTextureStorage2DMultisample;
|
|||
PFNGLTEXTUREPARAMETERIPROC glTextureParameteri;
|
||||
PFNGLTEXTUREPARAMETERFPROC glTextureParameterf;
|
||||
PFNGLCREATETEXTURESPROC glCreateTextures;
|
||||
PFNGLCREATEBUFFERSPROC glCreateBuffers;
|
||||
PFNGLCREATEFRAMEBUFFERSPROC glCreateFramebuffers;
|
||||
PFNGLNAMEDFRAMEBUFFERTEXTUREPROC glNamedFramebufferTexture;
|
||||
|
||||
void initGLFunctions()
|
||||
{
|
||||
|
@ -188,4 +191,7 @@ void initGLFunctions()
|
|||
GL_GET_PROC_ADR(PFNGLTEXTUREPARAMETERIPROC, glTextureParameteri);
|
||||
GL_GET_PROC_ADR(PFNGLTEXTUREPARAMETERFPROC, glTextureParameterf);
|
||||
GL_GET_PROC_ADR(PFNGLCREATETEXTURESPROC, glCreateTextures);
|
||||
GL_GET_PROC_ADR(PFNGLCREATEBUFFERSPROC, glCreateBuffers);
|
||||
GL_GET_PROC_ADR(PFNGLCREATEFRAMEBUFFERSPROC, glCreateFramebuffers);
|
||||
GL_GET_PROC_ADR(PFNGLNAMEDFRAMEBUFFERTEXTUREPROC, glNamedFramebufferTexture);
|
||||
}
|
||||
|
|
|
@ -101,6 +101,9 @@ extern PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC glTextureStorage2DMultisample;
|
|||
extern PFNGLTEXTUREPARAMETERIPROC glTextureParameteri;
|
||||
extern PFNGLTEXTUREPARAMETERFPROC glTextureParameterf;
|
||||
extern PFNGLCREATETEXTURESPROC glCreateTextures;
|
||||
extern PFNGLCREATEBUFFERSPROC glCreateBuffers;
|
||||
extern PFNGLCREATEFRAMEBUFFERSPROC glCreateFramebuffers;
|
||||
extern PFNGLNAMEDFRAMEBUFFERTEXTUREPROC glNamedFramebufferTexture;
|
||||
|
||||
void initGLFunctions();
|
||||
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
#include <Graphics/Parameters.h>
|
||||
#include "opengl_GLVersion.h"
|
||||
#include "opengl_CachedFunctions.h"
|
||||
#include "opengl_BufferManipulationObjectFactory.h"
|
||||
|
||||
//#define ENABLE_GL_4_5
|
||||
|
||||
using namespace opengl;
|
||||
|
||||
/*---------------CreateFramebufferObject-------------*/
|
||||
|
||||
class GenFramebuffer : public CreateFramebufferObject
|
||||
{
|
||||
public:
|
||||
graphics::ObjectHandle createFramebuffer() override
|
||||
{
|
||||
GLuint fbo;
|
||||
glGenFramebuffers(1, &fbo);
|
||||
return graphics::ObjectHandle(fbo);
|
||||
}
|
||||
};
|
||||
|
||||
class CreateFramebuffer : public CreateFramebufferObject
|
||||
{
|
||||
public:
|
||||
static bool Check(const GLVersion & _version) {
|
||||
#ifdef ENABLE_GL_4_5
|
||||
return (_version.majorVersion > 4) || (_version.majorVersion == 4 && _version.minorVersion >= 5);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
graphics::ObjectHandle createFramebuffer() override
|
||||
{
|
||||
GLuint fbo;
|
||||
glCreateFramebuffers(1, &fbo);
|
||||
return graphics::ObjectHandle(fbo);
|
||||
}
|
||||
};
|
||||
|
||||
/*---------------AddFramebufferTarget-------------*/
|
||||
|
||||
class AddFramebufferTexture2D : public AddFramebufferRenderTarget
|
||||
{
|
||||
public:
|
||||
AddFramebufferTexture2D(CachedBindFramebuffer * _bind) : m_bind(_bind) {}
|
||||
|
||||
void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) override
|
||||
{
|
||||
m_bind->bind(_params.bufferTarget, _params.bufferHandle);
|
||||
glFramebufferTexture2D(GLenum(_params.bufferTarget),
|
||||
GLenum(_params.attachment),
|
||||
GLenum(_params.textureTarget),
|
||||
GLuint(_params.textureHandle),
|
||||
0);
|
||||
}
|
||||
|
||||
private:
|
||||
CachedBindFramebuffer * m_bind;
|
||||
};
|
||||
|
||||
class AddNamedFramebufferTexture : public AddFramebufferRenderTarget
|
||||
{
|
||||
public:
|
||||
static bool Check(const GLVersion & _version) {
|
||||
#ifdef ENABLE_GL_4_5
|
||||
return (_version.majorVersion > 4) || (_version.majorVersion == 4 && _version.minorVersion >= 5);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) override
|
||||
{
|
||||
glNamedFramebufferTexture(GLuint(_params.bufferHandle),
|
||||
GLenum(_params.attachment),
|
||||
GLuint(_params.textureHandle),
|
||||
0);
|
||||
}
|
||||
};
|
||||
|
||||
/*---------------BufferManipulationObjectFactory-------------*/
|
||||
|
||||
BufferManipulationObjectFactory::BufferManipulationObjectFactory(const GLVersion & _version,
|
||||
CachedFunctions & _cachedFunctions)
|
||||
: m_version(_version)
|
||||
, m_cachedFunctions(_cachedFunctions)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BufferManipulationObjectFactory::~BufferManipulationObjectFactory()
|
||||
{
|
||||
}
|
||||
|
||||
CreateFramebufferObject * BufferManipulationObjectFactory::getCreateFramebufferObject() const
|
||||
{
|
||||
if (CreateFramebuffer::Check(m_version))
|
||||
return new CreateFramebuffer;
|
||||
|
||||
return new GenFramebuffer;
|
||||
}
|
||||
|
||||
AddFramebufferRenderTarget * BufferManipulationObjectFactory::getAddFramebufferRenderTarget() const
|
||||
{
|
||||
if (AddNamedFramebufferTexture::Check(m_version))
|
||||
return new AddNamedFramebufferTexture;
|
||||
|
||||
return new AddFramebufferTexture2D(m_cachedFunctions.geCachedBindFramebuffer());
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
#include <Graphics/ObjectHandle.h>
|
||||
#include <Graphics/Parameter.h>
|
||||
#include <Graphics/Context.h>
|
||||
|
||||
namespace opengl {
|
||||
|
||||
struct GLVersion;
|
||||
class CachedFunctions;
|
||||
|
||||
class CreateFramebufferObject
|
||||
{
|
||||
public:
|
||||
virtual ~CreateFramebufferObject() {};
|
||||
virtual graphics::ObjectHandle createFramebuffer() = 0;
|
||||
};
|
||||
|
||||
|
||||
class AddFramebufferRenderTarget
|
||||
{
|
||||
public:
|
||||
virtual ~AddFramebufferRenderTarget() {};
|
||||
virtual void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) = 0;
|
||||
};
|
||||
|
||||
|
||||
class BufferManipulationObjectFactory
|
||||
{
|
||||
public:
|
||||
BufferManipulationObjectFactory(const GLVersion & _version, CachedFunctions & _cachedFunctions);
|
||||
~BufferManipulationObjectFactory();
|
||||
|
||||
CreateFramebufferObject * getCreateFramebufferObject() const;
|
||||
|
||||
AddFramebufferRenderTarget * getAddFramebufferRenderTarget() const;
|
||||
|
||||
private:
|
||||
const GLVersion & m_version;
|
||||
CachedFunctions & m_cachedFunctions;
|
||||
};
|
||||
|
||||
}
|
|
@ -71,7 +71,7 @@ void CachedActiveTexture::setActiveTexture(u32 _index) {
|
|||
/*---------------CachedFunctions-------------*/
|
||||
|
||||
CachedFunctions::CachedFunctions()
|
||||
{
|
||||
: m_bindFramebuffer(glBindFramebuffer) {
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,3 +109,8 @@ CachedActiveTexture * CachedFunctions::geCachedActiveTexture()
|
|||
{
|
||||
return &m_activeTexture;
|
||||
}
|
||||
|
||||
CachedBindFramebuffer * CachedFunctions::geCachedBindFramebuffer()
|
||||
{
|
||||
return &m_bindFramebuffer;
|
||||
}
|
||||
|
|
|
@ -25,18 +25,25 @@ namespace opengl {
|
|||
class CachedBind
|
||||
{
|
||||
public:
|
||||
CachedBind(Bind * _bind) : m_bind(_bind), m_name(0U) {}
|
||||
CachedBind(Bind _bind) : m_bind(_bind), m_name(0U) {}
|
||||
|
||||
void bind(graphics::Parameter _target, graphics::ObjectHandle _name) {
|
||||
// TODO make cacheble
|
||||
m_bind(GLenum(_target), GLuint(_name));
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_name = graphics::ObjectHandle(0U);
|
||||
}
|
||||
|
||||
private:
|
||||
graphics::ObjectHandle m_name;
|
||||
Bind * m_bind;
|
||||
Bind m_bind;
|
||||
};
|
||||
|
||||
typedef CachedBind<decltype(glBindFramebuffer)> CachedBindFramebuffer;
|
||||
|
||||
class CachedBindTexture
|
||||
{
|
||||
public:
|
||||
|
@ -78,12 +85,15 @@ namespace opengl {
|
|||
|
||||
CachedActiveTexture * geCachedActiveTexture();
|
||||
|
||||
CachedBindFramebuffer * geCachedBindFramebuffer();
|
||||
|
||||
private:
|
||||
typedef std::unordered_map<u32, CachedEnable> EnableParameters;
|
||||
|
||||
EnableParameters m_enables;
|
||||
CachedBindTexture m_bindTexture;
|
||||
CachedActiveTexture m_activeTexture;
|
||||
CachedBindFramebuffer m_bindFramebuffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -5,36 +5,49 @@
|
|||
using namespace opengl;
|
||||
|
||||
ContextImpl::ContextImpl()
|
||||
: m_init2DTexture(nullptr)
|
||||
{
|
||||
initGLFunctions();
|
||||
}
|
||||
|
||||
|
||||
ContextImpl::~ContextImpl()
|
||||
{
|
||||
m_init2DTexture.reset(nullptr);
|
||||
}
|
||||
|
||||
void ContextImpl::init()
|
||||
{
|
||||
initGLFunctions();
|
||||
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &m_version.majorVersion);
|
||||
LOG(LOG_VERBOSE, "OpenGL major version: %d\n", m_version.majorVersion);
|
||||
assert(m_version.majorVersion >= 3 && "Plugin requires GL version 3 or higher.");
|
||||
glGetIntegerv(GL_MINOR_VERSION, &m_version.minorVersion);
|
||||
LOG(LOG_VERBOSE, "OpenGL minor version: %d\n", m_version.minorVersion);
|
||||
|
||||
TextureManipulationObjectFactory textureObjectsFactory(m_version, m_cachedFunctions);
|
||||
if (!m_cachedFunctions)
|
||||
m_cachedFunctions.reset(new CachedFunctions);
|
||||
|
||||
m_createTexture.reset(textureObjectsFactory.getCreate2DTexture());
|
||||
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
|
||||
m_set2DTextureParameters.reset(textureObjectsFactory.getSet2DTextureParameters());
|
||||
{
|
||||
TextureManipulationObjectFactory textureObjectsFactory(m_version, *m_cachedFunctions.get());
|
||||
m_createTexture.reset(textureObjectsFactory.getCreate2DTexture());
|
||||
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
|
||||
m_set2DTextureParameters.reset(textureObjectsFactory.getSet2DTextureParameters());
|
||||
}
|
||||
|
||||
{
|
||||
BufferManipulationObjectFactory bufferObjectFactory(m_version, *m_cachedFunctions.get());
|
||||
m_createFramebuffer.reset(bufferObjectFactory.getCreateFramebufferObject());
|
||||
m_addFramebufferRenderTarget.reset(bufferObjectFactory.getAddFramebufferRenderTarget());
|
||||
}
|
||||
}
|
||||
|
||||
void ContextImpl::destroy()
|
||||
{
|
||||
m_cachedFunctions.reset(nullptr);
|
||||
m_createTexture.reset(nullptr);
|
||||
m_init2DTexture.reset(nullptr);
|
||||
m_set2DTextureParameters.reset(nullptr);
|
||||
|
||||
m_createFramebuffer.reset(nullptr);
|
||||
m_addFramebufferRenderTarget.reset(nullptr);
|
||||
}
|
||||
|
||||
graphics::ObjectHandle ContextImpl::createTexture(graphics::Parameter _target)
|
||||
|
@ -60,3 +73,20 @@ void ContextImpl::setTextureParameters(const graphics::Context::TexParameters &
|
|||
assert(m_set2DTextureParameters);
|
||||
m_set2DTextureParameters->setTextureParameters(_parameters);
|
||||
}
|
||||
|
||||
graphics::ObjectHandle ContextImpl::createFramebuffer()
|
||||
{
|
||||
return m_createFramebuffer->createFramebuffer();
|
||||
}
|
||||
|
||||
void ContextImpl::deleteFramebuffer(graphics::ObjectHandle _name)
|
||||
{
|
||||
u32 fbo(_name);
|
||||
if (fbo != 0)
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
}
|
||||
|
||||
void ContextImpl::addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params)
|
||||
{
|
||||
m_addFramebufferRenderTarget->addFrameBufferRenderTarget(_params);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <memory>
|
||||
#include <Graphics/ContextImpl.h>
|
||||
#include "opengl_TextureManipulationObjectFactory.h"
|
||||
#include "opengl_BufferManipulationObjectFactory.h"
|
||||
#include "opengl_GLVersion.h"
|
||||
#include "opengl_CachedFunctions.h"
|
||||
|
||||
|
@ -25,12 +26,22 @@ namespace opengl {
|
|||
|
||||
void setTextureParameters(const graphics::Context::TexParameters & _parameters) override;
|
||||
|
||||
graphics::ObjectHandle createFramebuffer() override;
|
||||
|
||||
void deleteFramebuffer(graphics::ObjectHandle _name) override;
|
||||
|
||||
void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<CachedFunctions> m_cachedFunctions;
|
||||
std::unique_ptr<Create2DTexture> m_createTexture;
|
||||
std::unique_ptr<Init2DTexture> m_init2DTexture;
|
||||
std::unique_ptr<Set2DTextureParameters> m_set2DTextureParameters;
|
||||
|
||||
std::unique_ptr<CreateFramebufferObject> m_createFramebuffer;
|
||||
std::unique_ptr<AddFramebufferRenderTarget> m_addFramebufferRenderTarget;
|
||||
|
||||
GLVersion m_version;
|
||||
CachedFunctions m_cachedFunctions;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,16 @@ namespace graphics {
|
|||
Parameter TEXTURE_2D_MULTISAMPLE(GL_TEXTURE_2D_MULTISAMPLE);
|
||||
}
|
||||
|
||||
namespace bufferTarget {
|
||||
Parameter FRAMEBUFFER(GL_FRAMEBUFFER);
|
||||
Parameter DRAW_FRAMEBUFFER(GL_DRAW_FRAMEBUFFER);
|
||||
Parameter READ_FRAMEBUFFER(GL_READ_FRAMEBUFFER);
|
||||
}
|
||||
|
||||
namespace bufferAttachment {
|
||||
Parameter COLOR_ATTACHMENT0(GL_COLOR_ATTACHMENT0);
|
||||
}
|
||||
|
||||
namespace enable {
|
||||
Parameter BLEND(GL_BLEND);
|
||||
Parameter CULL_FACE(GL_CULL_FACE);
|
||||
|
|
|
@ -30,6 +30,16 @@ namespace graphics {
|
|||
extern Parameter TEXTURE_2D_MULTISAMPLE;
|
||||
}
|
||||
|
||||
namespace bufferTarget {
|
||||
extern Parameter FRAMEBUFFER;
|
||||
extern Parameter DRAW_FRAMEBUFFER;
|
||||
extern Parameter READ_FRAMEBUFFER;
|
||||
}
|
||||
|
||||
namespace bufferAttachment {
|
||||
extern Parameter COLOR_ATTACHMENT0;
|
||||
}
|
||||
|
||||
namespace enable {
|
||||
extern Parameter BLEND;
|
||||
extern Parameter CULL_FACE;
|
||||
|
|
|
@ -606,6 +606,8 @@ CachedTexture * TextureCache::_addTexture(u32 _crc32)
|
|||
|
||||
void TextureCache::removeFrameBufferTexture(CachedTexture * _pTexture)
|
||||
{
|
||||
if (_pTexture == nullptr)
|
||||
return;
|
||||
FBTextures::const_iterator iter = m_fbTextures.find(_pTexture->glName);
|
||||
assert(iter != m_fbTextures.cend());
|
||||
m_cachedBytes -= iter->second.textureBytes;
|
||||
|
|
Loading…
Reference in New Issue
Block a user