diff --git a/projects/msvc12/GLideN64.vcxproj b/projects/msvc12/GLideN64.vcxproj
index d89ee58c..29c67845 100644
--- a/projects/msvc12/GLideN64.vcxproj
+++ b/projects/msvc12/GLideN64.vcxproj
@@ -456,6 +456,8 @@
+
+
diff --git a/projects/msvc12/GLideN64.vcxproj.filters b/projects/msvc12/GLideN64.vcxproj.filters
index 86d9a86e..d3ddd25b 100644
--- a/projects/msvc12/GLideN64.vcxproj.filters
+++ b/projects/msvc12/GLideN64.vcxproj.filters
@@ -601,5 +601,11 @@
Header Files
+
+ Header Files\Graphics
+
+
+ Header Files\Graphics
+
\ No newline at end of file
diff --git a/src/Graphics/Context.cpp b/src/Graphics/Context.cpp
index 3a93bc13..9231ce20 100644
--- a/src/Graphics/Context.cpp
+++ b/src/Graphics/Context.cpp
@@ -38,6 +38,11 @@ void Context::init2DTexture(const InitTextureParams & _params)
m_impl->init2DTexture(_params);
}
+void Context::update2DTexture(const UpdateTextureDataParams & _params)
+{
+ m_impl->update2DTexture(_params);
+}
+
void Context::setTextureParameters(const TexParameters & _parameters)
{
m_impl->setTextureParameters(_parameters);
@@ -68,10 +73,14 @@ void Context::addFrameBufferRenderTarget(const FrameBufferRenderTarget & _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)
{
return m_impl->createCombinerProgram(_color, _alpha, _key);
-
}
bool Context::isMultisamplingSupported() const
diff --git a/src/Graphics/Context.h b/src/Graphics/Context.h
index 8a736bdc..8f8e9ec0 100644
--- a/src/Graphics/Context.h
+++ b/src/Graphics/Context.h
@@ -5,6 +5,8 @@
#include "ObjectHandle.h"
#include "Parameter.h"
#include "CombinerProgram.h"
+#include "ShaderProgram.h"
+#include "PixelBuffer.h"
#define GRAPHICS_CONTEXT
@@ -41,6 +43,21 @@ namespace graphics {
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 {
ObjectHandle handle;
u32 textureUnitIndex = 0;
@@ -81,8 +98,14 @@ namespace graphics {
void addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params);
+ PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes);
+
CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key);
+ ShaderProgram * createDepthFogShader();
+
+ ShaderProgram * createMonochromeShader();
+
bool isMultisamplingSupported() const;
private:
diff --git a/src/Graphics/ContextImpl.h b/src/Graphics/ContextImpl.h
index 1c0ebc68..0e0a1e48 100644
--- a/src/Graphics/ContextImpl.h
+++ b/src/Graphics/ContextImpl.h
@@ -15,13 +15,17 @@ namespace graphics {
virtual ObjectHandle createTexture(Parameter _target) = 0;
virtual void deleteTexture(ObjectHandle _name) = 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 ObjectHandle createFramebuffer() = 0;
virtual void deleteFramebuffer(ObjectHandle _name) = 0;
virtual void addFrameBufferRenderTarget(const Context::FrameBufferRenderTarget & _params) = 0;
virtual ObjectHandle createRenderbuffer() = 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 ShaderProgram * createDepthFogShader() = 0;
+ virtual ShaderProgram * createMonochromeShader() = 0;
};
}
diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp
index b73b6198..6c3cc0b0 100644
--- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp
+++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp
@@ -373,7 +373,7 @@ public:
if (config.frameBufferEmulation.nativeResFactor == 0)
// TODO fix me
//uScreenScale.set(video().getScaleX(), video().getScaleY(), _force);
- uScreenScale.set(1.0f, 1.0f, _force);
+ uScreenScale.set(2.0f, 2.0f, _force);
else
uScreenScale.set(float(config.frameBufferEmulation.nativeResFactor), float(config.frameBufferEmulation.nativeResFactor), _force);
}
diff --git a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp
index eb848038..164b1d0d 100644
--- a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp
+++ b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp
@@ -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 m_pData;
+};
+
+template
+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(const GLInfo & _info,
@@ -157,3 +260,11 @@ AddFramebufferRenderTarget * BufferManipulationObjectFactory::getAddFramebufferR
return new AddFramebufferTexture2D(m_cachedFunctions.geCachedBindFramebuffer());
}
+
+CreatePixelWriteBuffer * BufferManipulationObjectFactory::createPixelWriteBuffer() const
+{
+ if (m_glInfo.isGLES2)
+ return new CreatePixelWriteBufferT(nullptr);
+
+ return new CreatePixelWriteBufferT(m_cachedFunctions.geCachedBindBuffer());
+}
diff --git a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.h b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.h
index 47374af3..32d2c621 100644
--- a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.h
+++ b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.h
@@ -2,6 +2,7 @@
#include
#include
#include
+#include
#include "opengl_GLInfo.h"
namespace opengl {
@@ -37,6 +38,12 @@ namespace opengl {
virtual void addFrameBufferRenderTarget(const graphics::Context::FrameBufferRenderTarget & _params) = 0;
};
+ class CreatePixelWriteBuffer
+ {
+ public:
+ virtual ~CreatePixelWriteBuffer() {};
+ virtual graphics::PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes) = 0;
+ };
class BufferManipulationObjectFactory
{
@@ -52,6 +59,8 @@ namespace opengl {
AddFramebufferRenderTarget * getAddFramebufferRenderTarget() const;
+ CreatePixelWriteBuffer * createPixelWriteBuffer() const;
+
private:
const GLInfo & m_glInfo;
CachedFunctions & m_cachedFunctions;
diff --git a/src/Graphics/OpenGLContext/opengl_CachedFunctions.cpp b/src/Graphics/OpenGLContext/opengl_CachedFunctions.cpp
index a5f95870..19172fe5 100644
--- a/src/Graphics/OpenGLContext/opengl_CachedFunctions.cpp
+++ b/src/Graphics/OpenGLContext/opengl_CachedFunctions.cpp
@@ -72,7 +72,8 @@ void CachedActiveTexture::setActiveTexture(u32 _index) {
CachedFunctions::CachedFunctions()
: m_bindFramebuffer(glBindFramebuffer)
-, m_bindRenderbuffer(glBindRenderbuffer) {
+, m_bindRenderbuffer(glBindRenderbuffer)
+, m_bindBuffer(glBindBuffer) {
}
@@ -120,3 +121,7 @@ CachedBindRenderbuffer * CachedFunctions::geCachedBindRenderbuffer()
{
return &m_bindRenderbuffer;
}
+
+CachedBindBuffer * CachedFunctions::geCachedBindBuffer() {
+ return &m_bindBuffer;
+}
diff --git a/src/Graphics/OpenGLContext/opengl_CachedFunctions.h b/src/Graphics/OpenGLContext/opengl_CachedFunctions.h
index 709ceee6..f6eaf8e8 100644
--- a/src/Graphics/OpenGLContext/opengl_CachedFunctions.h
+++ b/src/Graphics/OpenGLContext/opengl_CachedFunctions.h
@@ -46,6 +46,8 @@ namespace opengl {
typedef CachedBind CachedBindRenderbuffer;
+ typedef CachedBind CachedBindBuffer;
+
class CachedBindTexture
{
public:
@@ -91,6 +93,8 @@ namespace opengl {
CachedBindRenderbuffer * geCachedBindRenderbuffer();
+ CachedBindBuffer * geCachedBindBuffer();
+
private:
typedef std::unordered_map EnableParameters;
@@ -99,6 +103,7 @@ namespace opengl {
CachedActiveTexture m_activeTexture;
CachedBindFramebuffer m_bindFramebuffer;
CachedBindRenderbuffer m_bindRenderbuffer;
+ CachedBindBuffer m_bindBuffer;
};
}
diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp
index 5c9140df..cf9544e2 100644
--- a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp
+++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp
@@ -26,6 +26,7 @@ void ContextImpl::init()
TextureManipulationObjectFactory textureObjectsFactory(m_glInfo, *m_cachedFunctions.get());
m_createTexture.reset(textureObjectsFactory.getCreate2DTexture());
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
+ m_update2DTexture.reset(textureObjectsFactory.getUpdate2DTexture());
m_set2DTextureParameters.reset(textureObjectsFactory.getSet2DTextureParameters());
}
@@ -35,6 +36,7 @@ void ContextImpl::init()
m_createRenderbuffer.reset(bufferObjectFactory.getCreateRenderbuffer());
m_initRenderbuffer.reset(bufferObjectFactory.getInitRenderbuffer());
m_addFramebufferRenderTarget.reset(bufferObjectFactory.getAddFramebufferRenderTarget());
+ m_createPixelWriteBuffer.reset(bufferObjectFactory.createPixelWriteBuffer());
}
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)
{
- assert(m_init2DTexture);
m_init2DTexture->init2DTexture(_params);
}
+void ContextImpl::update2DTexture(const graphics::Context::UpdateTextureDataParams & _params)
+{
+ m_update2DTexture->update2DTexture(_params);
+}
+
void ContextImpl::setTextureParameters(const graphics::Context::TexParameters & _parameters)
{
- assert(m_set2DTextureParameters);
m_set2DTextureParameters->setTextureParameters(_parameters);
}
@@ -107,7 +112,22 @@ void ContextImpl::addFrameBufferRenderTarget(const graphics::Context::FrameBuffe
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)
{
return m_combinerProgramBuilder->buildCombinerProgram(_color, _alpha, _key);
}
+
+graphics::ShaderProgram * ContextImpl::createDepthFogShader()
+{
+ return nullptr;
+}
+
+graphics::ShaderProgram * ContextImpl::createMonochromeShader()
+{
+ return nullptr;
+}
diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.h b/src/Graphics/OpenGLContext/opengl_ContextImpl.h
index 7c7bf1c6..9e2db66e 100644
--- a/src/Graphics/OpenGLContext/opengl_ContextImpl.h
+++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.h
@@ -28,6 +28,8 @@ namespace opengl {
void init2DTexture(const graphics::Context::InitTextureParams & _params) override;
+ void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) override;
+
void setTextureParameters(const graphics::Context::TexParameters & _parameters) override;
graphics::ObjectHandle createFramebuffer() override;
@@ -40,18 +42,26 @@ namespace opengl {
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::ShaderProgram * createDepthFogShader() override;
+
+ graphics::ShaderProgram * createMonochromeShader() override;
+
private:
std::unique_ptr m_cachedFunctions;
std::unique_ptr m_createTexture;
std::unique_ptr m_init2DTexture;
+ std::unique_ptr m_update2DTexture;
std::unique_ptr m_set2DTextureParameters;
std::unique_ptr m_createFramebuffer;
std::unique_ptr m_createRenderbuffer;
std::unique_ptr m_initRenderbuffer;
std::unique_ptr m_addFramebufferRenderTarget;
+ std::unique_ptr m_createPixelWriteBuffer;
std::unique_ptr m_combinerProgramBuilder;
GLInfo m_glInfo;
diff --git a/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp b/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp
index 97025ea6..06440f9b 100644
--- a/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp
+++ b/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.cpp
@@ -190,6 +190,60 @@ namespace opengl {
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-------------*/
@@ -302,6 +356,15 @@ namespace opengl {
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
{
if (SetTextureParameters::Check(m_glInfo))
diff --git a/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.h b/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.h
index 35078b6e..1f8aaeaa 100644
--- a/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.h
+++ b/src/Graphics/OpenGLContext/opengl_TextureManipulationObjectFactory.h
@@ -23,6 +23,13 @@ namespace opengl {
virtual void reset(graphics::ObjectHandle _deleted) = 0;
};
+ class Update2DTexture
+ {
+ public:
+ virtual ~Update2DTexture() {};
+ virtual void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) = 0;
+ };
+
class Set2DTextureParameters
{
public:
@@ -40,6 +47,8 @@ namespace opengl {
Init2DTexture * getInit2DTexture() const;
+ Update2DTexture * getUpdate2DTexture() const;
+
Set2DTextureParameters * getSet2DTextureParameters() const;
private:
diff --git a/src/Graphics/PixelBuffer.h b/src/Graphics/PixelBuffer.h
new file mode 100644
index 00000000..a6488211
--- /dev/null
+++ b/src/Graphics/PixelBuffer.h
@@ -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 PixelBufferBinder
+ {
+ public:
+ PixelBufferBinder(T * _buffer)
+ : m_buffer(_buffer) {
+ m_buffer->bind();
+ }
+
+ ~PixelBufferBinder() {
+ m_buffer->unbind();
+ m_buffer = nullptr;
+ }
+ private:
+ T * m_buffer;
+ };
+
+}
diff --git a/src/Graphics/ShaderProgram.h b/src/Graphics/ShaderProgram.h
new file mode 100644
index 00000000..035421d8
--- /dev/null
+++ b/src/Graphics/ShaderProgram.h
@@ -0,0 +1,13 @@
+#pragma once
+
+namespace graphics {
+
+ class ShaderProgram
+ {
+ public:
+ virtual ~ShaderProgram() {};
+ virtual void activate() = 0;
+ };
+
+}
+
diff --git a/src/NoiseTexture.cpp b/src/NoiseTexture.cpp
index c32684dc..e27dc462 100644
--- a/src/NoiseTexture.cpp
+++ b/src/NoiseTexture.cpp
@@ -11,7 +11,6 @@ NoiseTexture g_noiseTexture;
NoiseTexture::NoiseTexture()
: m_pTexture(nullptr)
- , m_PBO(0)
, m_DList(0)
{
}
@@ -54,44 +53,47 @@ void NoiseTexture::init()
gfxContext.setTextureParameters(params);
}
- // TODO rewrite in GL independent way
// Generate Pixel Buffer Object. Initialize it with max buffer size.
- glGenBuffers(1, &m_PBO);
- PBOBinder binder(GL_PIXEL_UNPACK_BUFFER, m_PBO);
- glBufferData(GL_PIXEL_UNPACK_BUFFER, 640 * 580, nullptr, GL_DYNAMIC_DRAW);
+ m_pbuf.reset(gfxContext.createPixelWriteBuffer(640 * 580));
}
void NoiseTexture::destroy()
{
- if (m_pTexture != nullptr) {
- textureCache().removeFrameBufferTexture(m_pTexture);
- m_pTexture = nullptr;
- }
- glDeleteBuffers(1, &m_PBO);
- m_PBO = 0;
+ textureCache().removeFrameBufferTexture(m_pTexture);
+ m_pTexture = nullptr;
+ m_pbuf.reset();
}
void NoiseTexture::update()
{
- if (m_PBO == 0 || m_pTexture == nullptr)
+ if (!m_pbuf || m_pTexture == nullptr)
return;
if (m_DList == video().getBuffersSwapCount() || config.generalEmulation.enableNoise == 0)
return;
const u32 dataSize = VI.width*VI.height;
if (dataSize == 0)
return;
- PBOBinder binder(GL_PIXEL_UNPACK_BUFFER, m_PBO);
- GLubyte* ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, dataSize, GL_MAP_WRITE_BIT);
- if (ptr == nullptr)
+
+ graphics::PixelBufferBinder binder(m_pbuf.get());
+ GLubyte* ptr = (GLubyte*)m_pbuf->getWriteBuffer(dataSize);
+ if (ptr == nullptr) {
return;
+ }
for (u32 y = 0; y < VI.height; ++y) {
for (u32 x = 0; x < VI.width; ++x)
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();
}
diff --git a/src/NoiseTexture.h b/src/NoiseTexture.h
index fc7a1e78..4c32bd1f 100644
--- a/src/NoiseTexture.h
+++ b/src/NoiseTexture.h
@@ -1,6 +1,11 @@
#pragma once
+#include
#include "Types.h"
+namespace graphics {
+ class PixelWriteBuffer;
+}
+
struct CachedTexture;
class NoiseTexture
@@ -14,7 +19,7 @@ public:
private:
CachedTexture * m_pTexture;
- GLuint m_PBO;
+ std::unique_ptr m_pbuf;
u32 m_DList;
};