mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Rewrite NoiseTexture
This commit is contained in:
parent
41d0a9ade5
commit
6ef2431e19
|
@ -456,6 +456,8 @@
|
||||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Utilis.h" />
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Utilis.h" />
|
||||||
<ClInclude Include="..\..\src\Graphics\Parameter.h" />
|
<ClInclude Include="..\..\src\Graphics\Parameter.h" />
|
||||||
<ClInclude Include="..\..\src\Graphics\Parameters.h" />
|
<ClInclude Include="..\..\src\Graphics\Parameters.h" />
|
||||||
|
<ClInclude Include="..\..\src\Graphics\PixelBuffer.h" />
|
||||||
|
<ClInclude Include="..\..\src\Graphics\ShaderProgram.h" />
|
||||||
<ClInclude Include="..\..\src\gSP.h" />
|
<ClInclude Include="..\..\src\gSP.h" />
|
||||||
<ClInclude Include="..\..\src\inc\glext.h" />
|
<ClInclude Include="..\..\src\inc\glext.h" />
|
||||||
<ClInclude Include="..\..\src\Keys.h" />
|
<ClInclude Include="..\..\src\Keys.h" />
|
||||||
|
|
|
@ -601,5 +601,11 @@
|
||||||
<ClInclude Include="..\..\src\NoiseTexture.h">
|
<ClInclude Include="..\..\src\NoiseTexture.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Graphics\ShaderProgram.h">
|
||||||
|
<Filter>Header Files\Graphics</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Graphics\PixelBuffer.h">
|
||||||
|
<Filter>Header Files\Graphics</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -38,6 +38,11 @@ void Context::init2DTexture(const InitTextureParams & _params)
|
||||||
m_impl->init2DTexture(_params);
|
m_impl->init2DTexture(_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Context::update2DTexture(const UpdateTextureDataParams & _params)
|
||||||
|
{
|
||||||
|
m_impl->update2DTexture(_params);
|
||||||
|
}
|
||||||
|
|
||||||
void Context::setTextureParameters(const TexParameters & _parameters)
|
void Context::setTextureParameters(const TexParameters & _parameters)
|
||||||
{
|
{
|
||||||
m_impl->setTextureParameters(_parameters);
|
m_impl->setTextureParameters(_parameters);
|
||||||
|
@ -68,10 +73,14 @@ void Context::addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params
|
||||||
m_impl->addFrameBufferRenderTarget(_params);
|
m_impl->addFrameBufferRenderTarget(_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PixelWriteBuffer * Context::createPixelWriteBuffer(size_t _sizeInBytes)
|
||||||
|
{
|
||||||
|
return m_impl->createPixelWriteBuffer(_sizeInBytes);
|
||||||
|
}
|
||||||
|
|
||||||
CombinerProgram * Context::createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key)
|
CombinerProgram * Context::createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key)
|
||||||
{
|
{
|
||||||
return m_impl->createCombinerProgram(_color, _alpha, _key);
|
return m_impl->createCombinerProgram(_color, _alpha, _key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Context::isMultisamplingSupported() const
|
bool Context::isMultisamplingSupported() const
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include "ObjectHandle.h"
|
#include "ObjectHandle.h"
|
||||||
#include "Parameter.h"
|
#include "Parameter.h"
|
||||||
#include "CombinerProgram.h"
|
#include "CombinerProgram.h"
|
||||||
|
#include "ShaderProgram.h"
|
||||||
|
#include "PixelBuffer.h"
|
||||||
|
|
||||||
#define GRAPHICS_CONTEXT
|
#define GRAPHICS_CONTEXT
|
||||||
|
|
||||||
|
@ -41,6 +43,21 @@ namespace graphics {
|
||||||
|
|
||||||
void init2DTexture(const InitTextureParams & _params);
|
void init2DTexture(const InitTextureParams & _params);
|
||||||
|
|
||||||
|
struct UpdateTextureDataParams {
|
||||||
|
ObjectHandle handle;
|
||||||
|
u32 textureUnitIndex = 0;
|
||||||
|
u32 x = 0;
|
||||||
|
u32 y = 0;
|
||||||
|
u32 width = 0;
|
||||||
|
u32 height = 0;
|
||||||
|
u32 mipMapLevel = 0;
|
||||||
|
Parameter format;
|
||||||
|
Parameter dataType;
|
||||||
|
const void * data = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void update2DTexture(const UpdateTextureDataParams & _params);
|
||||||
|
|
||||||
struct TexParameters {
|
struct TexParameters {
|
||||||
ObjectHandle handle;
|
ObjectHandle handle;
|
||||||
u32 textureUnitIndex = 0;
|
u32 textureUnitIndex = 0;
|
||||||
|
@ -81,8 +98,14 @@ namespace graphics {
|
||||||
|
|
||||||
void addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params);
|
void addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params);
|
||||||
|
|
||||||
|
PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes);
|
||||||
|
|
||||||
CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key);
|
CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key);
|
||||||
|
|
||||||
|
ShaderProgram * createDepthFogShader();
|
||||||
|
|
||||||
|
ShaderProgram * createMonochromeShader();
|
||||||
|
|
||||||
bool isMultisamplingSupported() const;
|
bool isMultisamplingSupported() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,13 +15,17 @@ namespace graphics {
|
||||||
virtual ObjectHandle createTexture(Parameter _target) = 0;
|
virtual ObjectHandle createTexture(Parameter _target) = 0;
|
||||||
virtual void deleteTexture(ObjectHandle _name) = 0;
|
virtual void deleteTexture(ObjectHandle _name) = 0;
|
||||||
virtual void init2DTexture(const Context::InitTextureParams & _params) = 0;
|
virtual void init2DTexture(const Context::InitTextureParams & _params) = 0;
|
||||||
|
virtual void update2DTexture(const Context::UpdateTextureDataParams & _params) = 0;
|
||||||
virtual void setTextureParameters(const Context::TexParameters & _parameters) = 0;
|
virtual void setTextureParameters(const Context::TexParameters & _parameters) = 0;
|
||||||
virtual ObjectHandle createFramebuffer() = 0;
|
virtual ObjectHandle createFramebuffer() = 0;
|
||||||
virtual void deleteFramebuffer(ObjectHandle _name) = 0;
|
virtual void deleteFramebuffer(ObjectHandle _name) = 0;
|
||||||
virtual void addFrameBufferRenderTarget(const Context::FrameBufferRenderTarget & _params) = 0;
|
virtual void addFrameBufferRenderTarget(const Context::FrameBufferRenderTarget & _params) = 0;
|
||||||
virtual ObjectHandle createRenderbuffer() = 0;
|
virtual ObjectHandle createRenderbuffer() = 0;
|
||||||
virtual void initRenderbuffer(const Context::InitRenderbufferParams & _params) = 0;
|
virtual void initRenderbuffer(const Context::InitRenderbufferParams & _params) = 0;
|
||||||
|
virtual PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes) = 0;
|
||||||
virtual CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key) = 0;
|
virtual CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key) = 0;
|
||||||
|
virtual ShaderProgram * createDepthFogShader() = 0;
|
||||||
|
virtual ShaderProgram * createMonochromeShader() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,7 +373,7 @@ public:
|
||||||
if (config.frameBufferEmulation.nativeResFactor == 0)
|
if (config.frameBufferEmulation.nativeResFactor == 0)
|
||||||
// TODO fix me
|
// TODO fix me
|
||||||
//uScreenScale.set(video().getScaleX(), video().getScaleY(), _force);
|
//uScreenScale.set(video().getScaleX(), video().getScaleY(), _force);
|
||||||
uScreenScale.set(1.0f, 1.0f, _force);
|
uScreenScale.set(2.0f, 2.0f, _force);
|
||||||
else
|
else
|
||||||
uScreenScale.set(float(config.frameBufferEmulation.nativeResFactor), float(config.frameBufferEmulation.nativeResFactor), _force);
|
uScreenScale.set(float(config.frameBufferEmulation.nativeResFactor), float(config.frameBufferEmulation.nativeResFactor), _force);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,109 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*---------------CreatePixelWriteBuffer-------------*/
|
||||||
|
|
||||||
|
class PBOWriteBuffer : public graphics::PixelWriteBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PBOWriteBuffer(CachedBindBuffer * _bind, size_t _size)
|
||||||
|
: m_bind(_bind)
|
||||||
|
, m_size(_size)
|
||||||
|
{
|
||||||
|
glGenBuffers(1, &m_PBO);
|
||||||
|
m_bind->bind(graphics::Parameter(GL_PIXEL_UNPACK_BUFFER), graphics::ObjectHandle(m_PBO));
|
||||||
|
glBufferData(GL_PIXEL_UNPACK_BUFFER, m_size, nullptr, GL_DYNAMIC_DRAW);
|
||||||
|
m_bind->bind(graphics::Parameter(GL_PIXEL_UNPACK_BUFFER), graphics::ObjectHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
~PBOWriteBuffer() {
|
||||||
|
glDeleteBuffers(1, &m_PBO);
|
||||||
|
m_PBO = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void * getWriteBuffer(size_t _size) override
|
||||||
|
{
|
||||||
|
if (_size > m_size)
|
||||||
|
_size = m_size;
|
||||||
|
return glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, _size, GL_MAP_WRITE_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeWriteBuffer() override
|
||||||
|
{
|
||||||
|
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void * getData() override {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bind() override {
|
||||||
|
m_bind->bind(graphics::Parameter(GL_PIXEL_UNPACK_BUFFER), graphics::ObjectHandle(m_PBO));
|
||||||
|
}
|
||||||
|
|
||||||
|
void unbind() override {
|
||||||
|
m_bind->bind(graphics::Parameter(GL_PIXEL_UNPACK_BUFFER), graphics::ObjectHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CachedBindBuffer * m_bind;
|
||||||
|
size_t m_size;
|
||||||
|
GLuint m_PBO;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MemoryWriteBuffer : public graphics::PixelWriteBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MemoryWriteBuffer(CachedBindBuffer * _bind, size_t _size)
|
||||||
|
: m_size(_size)
|
||||||
|
, m_pData(new GLubyte[_size])
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~MemoryWriteBuffer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void * getWriteBuffer(size_t _size) override
|
||||||
|
{
|
||||||
|
return m_pData.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeWriteBuffer() override
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void * getData() override {
|
||||||
|
return m_pData.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void bind() override {
|
||||||
|
}
|
||||||
|
|
||||||
|
void unbind() override {
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t m_size;
|
||||||
|
std::unique_ptr<GLubyte[]> m_pData;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class CreatePixelWriteBufferT : public CreatePixelWriteBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CreatePixelWriteBufferT(CachedBindBuffer * _bind)
|
||||||
|
: m_bind(_bind) {
|
||||||
|
}
|
||||||
|
|
||||||
|
graphics::PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes) override
|
||||||
|
{
|
||||||
|
return new T(m_bind, _sizeInBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CachedBindBuffer * m_bind;
|
||||||
|
};
|
||||||
|
|
||||||
/*---------------BufferManipulationObjectFactory-------------*/
|
/*---------------BufferManipulationObjectFactory-------------*/
|
||||||
|
|
||||||
BufferManipulationObjectFactory::BufferManipulationObjectFactory(const GLInfo & _info,
|
BufferManipulationObjectFactory::BufferManipulationObjectFactory(const GLInfo & _info,
|
||||||
|
@ -157,3 +260,11 @@ AddFramebufferRenderTarget * BufferManipulationObjectFactory::getAddFramebufferR
|
||||||
|
|
||||||
return new AddFramebufferTexture2D(m_cachedFunctions.geCachedBindFramebuffer());
|
return new AddFramebufferTexture2D(m_cachedFunctions.geCachedBindFramebuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CreatePixelWriteBuffer * BufferManipulationObjectFactory::createPixelWriteBuffer() const
|
||||||
|
{
|
||||||
|
if (m_glInfo.isGLES2)
|
||||||
|
return new CreatePixelWriteBufferT<MemoryWriteBuffer>(nullptr);
|
||||||
|
|
||||||
|
return new CreatePixelWriteBufferT<PBOWriteBuffer>(m_cachedFunctions.geCachedBindBuffer());
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <Graphics/ObjectHandle.h>
|
#include <Graphics/ObjectHandle.h>
|
||||||
#include <Graphics/Parameter.h>
|
#include <Graphics/Parameter.h>
|
||||||
#include <Graphics/Context.h>
|
#include <Graphics/Context.h>
|
||||||
|
#include <Graphics/PixelBuffer.h>
|
||||||
#include "opengl_GLInfo.h"
|
#include "opengl_GLInfo.h"
|
||||||
|
|
||||||
namespace opengl {
|
namespace opengl {
|
||||||
|
@ -37,6 +38,12 @@ namespace opengl {
|
||||||
virtual void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) = 0;
|
virtual void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CreatePixelWriteBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~CreatePixelWriteBuffer() {};
|
||||||
|
virtual graphics::PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class BufferManipulationObjectFactory
|
class BufferManipulationObjectFactory
|
||||||
{
|
{
|
||||||
|
@ -52,6 +59,8 @@ namespace opengl {
|
||||||
|
|
||||||
AddFramebufferRenderTarget * getAddFramebufferRenderTarget() const;
|
AddFramebufferRenderTarget * getAddFramebufferRenderTarget() const;
|
||||||
|
|
||||||
|
CreatePixelWriteBuffer * createPixelWriteBuffer() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const GLInfo & m_glInfo;
|
const GLInfo & m_glInfo;
|
||||||
CachedFunctions & m_cachedFunctions;
|
CachedFunctions & m_cachedFunctions;
|
||||||
|
|
|
@ -72,7 +72,8 @@ void CachedActiveTexture::setActiveTexture(u32 _index) {
|
||||||
|
|
||||||
CachedFunctions::CachedFunctions()
|
CachedFunctions::CachedFunctions()
|
||||||
: m_bindFramebuffer(glBindFramebuffer)
|
: m_bindFramebuffer(glBindFramebuffer)
|
||||||
, m_bindRenderbuffer(glBindRenderbuffer) {
|
, m_bindRenderbuffer(glBindRenderbuffer)
|
||||||
|
, m_bindBuffer(glBindBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,3 +121,7 @@ CachedBindRenderbuffer * CachedFunctions::geCachedBindRenderbuffer()
|
||||||
{
|
{
|
||||||
return &m_bindRenderbuffer;
|
return &m_bindRenderbuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CachedBindBuffer * CachedFunctions::geCachedBindBuffer() {
|
||||||
|
return &m_bindBuffer;
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ namespace opengl {
|
||||||
|
|
||||||
typedef CachedBind<decltype(glBindRenderbuffer)> CachedBindRenderbuffer;
|
typedef CachedBind<decltype(glBindRenderbuffer)> CachedBindRenderbuffer;
|
||||||
|
|
||||||
|
typedef CachedBind<decltype(glBindBuffer)> CachedBindBuffer;
|
||||||
|
|
||||||
class CachedBindTexture
|
class CachedBindTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -91,6 +93,8 @@ namespace opengl {
|
||||||
|
|
||||||
CachedBindRenderbuffer * geCachedBindRenderbuffer();
|
CachedBindRenderbuffer * geCachedBindRenderbuffer();
|
||||||
|
|
||||||
|
CachedBindBuffer * geCachedBindBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::unordered_map<u32, CachedEnable> EnableParameters;
|
typedef std::unordered_map<u32, CachedEnable> EnableParameters;
|
||||||
|
|
||||||
|
@ -99,6 +103,7 @@ namespace opengl {
|
||||||
CachedActiveTexture m_activeTexture;
|
CachedActiveTexture m_activeTexture;
|
||||||
CachedBindFramebuffer m_bindFramebuffer;
|
CachedBindFramebuffer m_bindFramebuffer;
|
||||||
CachedBindRenderbuffer m_bindRenderbuffer;
|
CachedBindRenderbuffer m_bindRenderbuffer;
|
||||||
|
CachedBindBuffer m_bindBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ void ContextImpl::init()
|
||||||
TextureManipulationObjectFactory textureObjectsFactory(m_glInfo, *m_cachedFunctions.get());
|
TextureManipulationObjectFactory textureObjectsFactory(m_glInfo, *m_cachedFunctions.get());
|
||||||
m_createTexture.reset(textureObjectsFactory.getCreate2DTexture());
|
m_createTexture.reset(textureObjectsFactory.getCreate2DTexture());
|
||||||
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
|
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
|
||||||
|
m_update2DTexture.reset(textureObjectsFactory.getUpdate2DTexture());
|
||||||
m_set2DTextureParameters.reset(textureObjectsFactory.getSet2DTextureParameters());
|
m_set2DTextureParameters.reset(textureObjectsFactory.getSet2DTextureParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ void ContextImpl::init()
|
||||||
m_createRenderbuffer.reset(bufferObjectFactory.getCreateRenderbuffer());
|
m_createRenderbuffer.reset(bufferObjectFactory.getCreateRenderbuffer());
|
||||||
m_initRenderbuffer.reset(bufferObjectFactory.getInitRenderbuffer());
|
m_initRenderbuffer.reset(bufferObjectFactory.getInitRenderbuffer());
|
||||||
m_addFramebufferRenderTarget.reset(bufferObjectFactory.getAddFramebufferRenderTarget());
|
m_addFramebufferRenderTarget.reset(bufferObjectFactory.getAddFramebufferRenderTarget());
|
||||||
|
m_createPixelWriteBuffer.reset(bufferObjectFactory.createPixelWriteBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_combinerProgramBuilder.reset(new glsl::CombinerProgramBuilder(m_glInfo));
|
m_combinerProgramBuilder.reset(new glsl::CombinerProgramBuilder(m_glInfo));
|
||||||
|
@ -70,13 +72,16 @@ void ContextImpl::deleteTexture(graphics::ObjectHandle _name)
|
||||||
|
|
||||||
void ContextImpl::init2DTexture(const graphics::Context::InitTextureParams & _params)
|
void ContextImpl::init2DTexture(const graphics::Context::InitTextureParams & _params)
|
||||||
{
|
{
|
||||||
assert(m_init2DTexture);
|
|
||||||
m_init2DTexture->init2DTexture(_params);
|
m_init2DTexture->init2DTexture(_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContextImpl::update2DTexture(const graphics::Context::UpdateTextureDataParams & _params)
|
||||||
|
{
|
||||||
|
m_update2DTexture->update2DTexture(_params);
|
||||||
|
}
|
||||||
|
|
||||||
void ContextImpl::setTextureParameters(const graphics::Context::TexParameters & _parameters)
|
void ContextImpl::setTextureParameters(const graphics::Context::TexParameters & _parameters)
|
||||||
{
|
{
|
||||||
assert(m_set2DTextureParameters);
|
|
||||||
m_set2DTextureParameters->setTextureParameters(_parameters);
|
m_set2DTextureParameters->setTextureParameters(_parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +112,22 @@ void ContextImpl::addFrameBufferRenderTarget(const graphics::Context::FrameBuffe
|
||||||
m_addFramebufferRenderTarget->addFrameBufferRenderTarget(_params);
|
m_addFramebufferRenderTarget->addFrameBufferRenderTarget(_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graphics::PixelWriteBuffer * ContextImpl::createPixelWriteBuffer(size_t _sizeInBytes)
|
||||||
|
{
|
||||||
|
return m_createPixelWriteBuffer->createPixelWriteBuffer(_sizeInBytes);
|
||||||
|
}
|
||||||
|
|
||||||
graphics::CombinerProgram * ContextImpl::createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key)
|
graphics::CombinerProgram * ContextImpl::createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key)
|
||||||
{
|
{
|
||||||
return m_combinerProgramBuilder->buildCombinerProgram(_color, _alpha, _key);
|
return m_combinerProgramBuilder->buildCombinerProgram(_color, _alpha, _key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graphics::ShaderProgram * ContextImpl::createDepthFogShader()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
graphics::ShaderProgram * ContextImpl::createMonochromeShader()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ namespace opengl {
|
||||||
|
|
||||||
void init2DTexture(const graphics::Context::InitTextureParams & _params) override;
|
void init2DTexture(const graphics::Context::InitTextureParams & _params) override;
|
||||||
|
|
||||||
|
void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) override;
|
||||||
|
|
||||||
void setTextureParameters(const graphics::Context::TexParameters & _parameters) override;
|
void setTextureParameters(const graphics::Context::TexParameters & _parameters) override;
|
||||||
|
|
||||||
graphics::ObjectHandle createFramebuffer() override;
|
graphics::ObjectHandle createFramebuffer() override;
|
||||||
|
@ -40,18 +42,26 @@ namespace opengl {
|
||||||
|
|
||||||
void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) override;
|
void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) override;
|
||||||
|
|
||||||
|
graphics::PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes) override;
|
||||||
|
|
||||||
graphics::CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key) override;
|
graphics::CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key) override;
|
||||||
|
|
||||||
|
graphics::ShaderProgram * createDepthFogShader() override;
|
||||||
|
|
||||||
|
graphics::ShaderProgram * createMonochromeShader() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<CachedFunctions> m_cachedFunctions;
|
std::unique_ptr<CachedFunctions> m_cachedFunctions;
|
||||||
std::unique_ptr<Create2DTexture> m_createTexture;
|
std::unique_ptr<Create2DTexture> m_createTexture;
|
||||||
std::unique_ptr<Init2DTexture> m_init2DTexture;
|
std::unique_ptr<Init2DTexture> m_init2DTexture;
|
||||||
|
std::unique_ptr<Update2DTexture> m_update2DTexture;
|
||||||
std::unique_ptr<Set2DTextureParameters> m_set2DTextureParameters;
|
std::unique_ptr<Set2DTextureParameters> m_set2DTextureParameters;
|
||||||
|
|
||||||
std::unique_ptr<CreateFramebufferObject> m_createFramebuffer;
|
std::unique_ptr<CreateFramebufferObject> m_createFramebuffer;
|
||||||
std::unique_ptr<CreateRenderbuffer> m_createRenderbuffer;
|
std::unique_ptr<CreateRenderbuffer> m_createRenderbuffer;
|
||||||
std::unique_ptr<InitRenderbuffer> m_initRenderbuffer;
|
std::unique_ptr<InitRenderbuffer> m_initRenderbuffer;
|
||||||
std::unique_ptr<AddFramebufferRenderTarget> m_addFramebufferRenderTarget;
|
std::unique_ptr<AddFramebufferRenderTarget> m_addFramebufferRenderTarget;
|
||||||
|
std::unique_ptr<CreatePixelWriteBuffer> m_createPixelWriteBuffer;
|
||||||
|
|
||||||
std::unique_ptr<glsl::CombinerProgramBuilder> m_combinerProgramBuilder;
|
std::unique_ptr<glsl::CombinerProgramBuilder> m_combinerProgramBuilder;
|
||||||
GLInfo m_glInfo;
|
GLInfo m_glInfo;
|
||||||
|
|
|
@ -190,6 +190,60 @@ namespace opengl {
|
||||||
graphics::ObjectHandle m_handle;
|
graphics::ObjectHandle m_handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*---------------Update2DTexture-------------*/
|
||||||
|
|
||||||
|
class Update2DTexSubImage : public Update2DTexture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Update2DTexSubImage(CachedActiveTexture * _activeTexture, CachedBindTexture* _bind)
|
||||||
|
: m_activeTexture(_activeTexture)
|
||||||
|
, m_bind(_bind) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) override
|
||||||
|
{
|
||||||
|
m_activeTexture->setActiveTexture(_params.textureUnitIndex);
|
||||||
|
m_bind->bind(GL_TEXTURE_2D, _params.handle);
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D,
|
||||||
|
_params.mipMapLevel,
|
||||||
|
_params.x,
|
||||||
|
_params.y,
|
||||||
|
_params.width,
|
||||||
|
_params.height,
|
||||||
|
GLuint(_params.format),
|
||||||
|
GLenum(_params.dataType),
|
||||||
|
_params.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CachedActiveTexture * m_activeTexture;
|
||||||
|
CachedBindTexture* m_bind;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Update2DTextureSubImage : public Update2DTexture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool Check(const GLInfo & _glinfo) {
|
||||||
|
#ifdef ENABLE_GL_4_5
|
||||||
|
return (_glinfo.majorVersion > 4) || (_glinfo.majorVersion == 4 && _glinfo.minorVersion >= 5);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) override
|
||||||
|
{
|
||||||
|
glTextureSubImage2D(GLuint(_params.handle),
|
||||||
|
_params.mipMapLevel,
|
||||||
|
_params.x,
|
||||||
|
_params.y,
|
||||||
|
_params.width,
|
||||||
|
_params.height,
|
||||||
|
GLuint(_params.format),
|
||||||
|
GLenum(_params.dataType),
|
||||||
|
_params.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/*---------------Set2DTextureParameters-------------*/
|
/*---------------Set2DTextureParameters-------------*/
|
||||||
|
|
||||||
|
@ -302,6 +356,15 @@ namespace opengl {
|
||||||
return new Init2DTexImage(m_cachedFunctions.getCachedBindTexture());
|
return new Init2DTexImage(m_cachedFunctions.getCachedBindTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Update2DTexture * TextureManipulationObjectFactory::getUpdate2DTexture() const
|
||||||
|
{
|
||||||
|
if (Update2DTextureSubImage::Check(m_glInfo))
|
||||||
|
return new Update2DTextureSubImage;
|
||||||
|
|
||||||
|
return new Update2DTexSubImage(m_cachedFunctions.geCachedActiveTexture(),
|
||||||
|
m_cachedFunctions.getCachedBindTexture());
|
||||||
|
}
|
||||||
|
|
||||||
Set2DTextureParameters * TextureManipulationObjectFactory::getSet2DTextureParameters() const
|
Set2DTextureParameters * TextureManipulationObjectFactory::getSet2DTextureParameters() const
|
||||||
{
|
{
|
||||||
if (SetTextureParameters::Check(m_glInfo))
|
if (SetTextureParameters::Check(m_glInfo))
|
||||||
|
|
|
@ -23,6 +23,13 @@ namespace opengl {
|
||||||
virtual void reset(graphics::ObjectHandle _deleted) = 0;
|
virtual void reset(graphics::ObjectHandle _deleted) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Update2DTexture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~Update2DTexture() {};
|
||||||
|
virtual void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class Set2DTextureParameters
|
class Set2DTextureParameters
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -40,6 +47,8 @@ namespace opengl {
|
||||||
|
|
||||||
Init2DTexture * getInit2DTexture() const;
|
Init2DTexture * getInit2DTexture() const;
|
||||||
|
|
||||||
|
Update2DTexture * getUpdate2DTexture() const;
|
||||||
|
|
||||||
Set2DTextureParameters * getSet2DTextureParameters() const;
|
Set2DTextureParameters * getSet2DTextureParameters() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
33
src/Graphics/PixelBuffer.h
Normal file
33
src/Graphics/PixelBuffer.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace graphics {
|
||||||
|
|
||||||
|
class PixelWriteBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~PixelWriteBuffer() {}
|
||||||
|
virtual void * getWriteBuffer(size_t _size) = 0;
|
||||||
|
virtual void closeWriteBuffer() = 0;
|
||||||
|
virtual void * getData() = 0;
|
||||||
|
virtual void bind() = 0;
|
||||||
|
virtual void unbind() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class PixelBufferBinder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PixelBufferBinder(T * _buffer)
|
||||||
|
: m_buffer(_buffer) {
|
||||||
|
m_buffer->bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
~PixelBufferBinder() {
|
||||||
|
m_buffer->unbind();
|
||||||
|
m_buffer = nullptr;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
T * m_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
13
src/Graphics/ShaderProgram.h
Normal file
13
src/Graphics/ShaderProgram.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace graphics {
|
||||||
|
|
||||||
|
class ShaderProgram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~ShaderProgram() {};
|
||||||
|
virtual void activate() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ NoiseTexture g_noiseTexture;
|
||||||
|
|
||||||
NoiseTexture::NoiseTexture()
|
NoiseTexture::NoiseTexture()
|
||||||
: m_pTexture(nullptr)
|
: m_pTexture(nullptr)
|
||||||
, m_PBO(0)
|
|
||||||
, m_DList(0)
|
, m_DList(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -54,44 +53,47 @@ void NoiseTexture::init()
|
||||||
gfxContext.setTextureParameters(params);
|
gfxContext.setTextureParameters(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO rewrite in GL independent way
|
|
||||||
// Generate Pixel Buffer Object. Initialize it with max buffer size.
|
// Generate Pixel Buffer Object. Initialize it with max buffer size.
|
||||||
glGenBuffers(1, &m_PBO);
|
m_pbuf.reset(gfxContext.createPixelWriteBuffer(640 * 580));
|
||||||
PBOBinder binder(GL_PIXEL_UNPACK_BUFFER, m_PBO);
|
|
||||||
glBufferData(GL_PIXEL_UNPACK_BUFFER, 640 * 580, nullptr, GL_DYNAMIC_DRAW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseTexture::destroy()
|
void NoiseTexture::destroy()
|
||||||
{
|
{
|
||||||
if (m_pTexture != nullptr) {
|
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
m_pTexture = nullptr;
|
||||||
m_pTexture = nullptr;
|
m_pbuf.reset();
|
||||||
}
|
|
||||||
glDeleteBuffers(1, &m_PBO);
|
|
||||||
m_PBO = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseTexture::update()
|
void NoiseTexture::update()
|
||||||
{
|
{
|
||||||
if (m_PBO == 0 || m_pTexture == nullptr)
|
if (!m_pbuf || m_pTexture == nullptr)
|
||||||
return;
|
return;
|
||||||
if (m_DList == video().getBuffersSwapCount() || config.generalEmulation.enableNoise == 0)
|
if (m_DList == video().getBuffersSwapCount() || config.generalEmulation.enableNoise == 0)
|
||||||
return;
|
return;
|
||||||
const u32 dataSize = VI.width*VI.height;
|
const u32 dataSize = VI.width*VI.height;
|
||||||
if (dataSize == 0)
|
if (dataSize == 0)
|
||||||
return;
|
return;
|
||||||
PBOBinder binder(GL_PIXEL_UNPACK_BUFFER, m_PBO);
|
|
||||||
GLubyte* ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, dataSize, GL_MAP_WRITE_BIT);
|
graphics::PixelBufferBinder<graphics::PixelWriteBuffer> binder(m_pbuf.get());
|
||||||
if (ptr == nullptr)
|
GLubyte* ptr = (GLubyte*)m_pbuf->getWriteBuffer(dataSize);
|
||||||
|
if (ptr == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
for (u32 y = 0; y < VI.height; ++y) {
|
for (u32 y = 0; y < VI.height; ++y) {
|
||||||
for (u32 x = 0; x < VI.width; ++x)
|
for (u32 x = 0; x < VI.width; ++x)
|
||||||
ptr[x + y*VI.width] = rand() & 0xFF;
|
ptr[x + y*VI.width] = rand() & 0xFF;
|
||||||
}
|
}
|
||||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); // release the mapped buffer
|
m_pbuf->closeWriteBuffer();
|
||||||
|
|
||||||
|
graphics::Context::UpdateTextureDataParams params;
|
||||||
|
params.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||||
|
params.textureUnitIndex = g_noiseTexIndex;
|
||||||
|
params.width = VI.width;
|
||||||
|
params.height = VI.height;
|
||||||
|
params.format = graphics::color::RED;
|
||||||
|
params.dataType = graphics::datatype::UNSIGNED_BYTE;
|
||||||
|
params.data = m_pbuf->getData();
|
||||||
|
gfxContext.update2DTexture(params);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + g_noiseTexIndex);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_pTexture->glName);
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VI.width, VI.height, GL_RED, GL_UNSIGNED_BYTE, 0);
|
|
||||||
m_DList = video().getBuffersSwapCount();
|
m_DList = video().getBuffersSwapCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
|
namespace graphics {
|
||||||
|
class PixelWriteBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
struct CachedTexture;
|
struct CachedTexture;
|
||||||
|
|
||||||
class NoiseTexture
|
class NoiseTexture
|
||||||
|
@ -14,7 +19,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CachedTexture * m_pTexture;
|
CachedTexture * m_pTexture;
|
||||||
GLuint m_PBO;
|
std::unique_ptr<graphics::PixelWriteBuffer> m_pbuf;
|
||||||
u32 m_DList;
|
u32 m_DList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user