1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-04 10:03:36 +00:00

Use InitTextureParams struct instead of separate parameters.

This commit is contained in:
Sergey Lipskiy 2016-12-29 17:51:38 +07:00
parent 62e7fcf580
commit eb7b640aa0
12 changed files with 157 additions and 70 deletions

View File

@ -33,11 +33,9 @@ void Context::deleteTexture(ObjectName _name)
return m_impl->deleteTexture(_name); return m_impl->deleteTexture(_name);
} }
void Context::init2DTexture(ObjectName _name, u32 _msaaLevel, u32 _width, u32 _height, u32 _mipMapLevel, void Context::init2DTexture(const InitTextureParams & _params)
Parameter _format, Parameter _internalFormat, Parameter _dataType, const void * _data)
{ {
return m_impl->init2DTexture(_name, _msaaLevel, _width, _height, return m_impl->init2DTexture(_params);
_mipMapLevel, _format, _internalFormat, _dataType, _data);
} }
bool Context::isMultisamplingSupported() const bool Context::isMultisamplingSupported() const

View File

@ -24,8 +24,19 @@ namespace graphics {
void deleteTexture(ObjectName _name); void deleteTexture(ObjectName _name);
void init2DTexture(ObjectName _name, u32 _msaaLevel, u32 _width, u32 _height, u32 _mipMapLevel, struct InitTextureParams {
Parameter _format, Parameter _internalFormat, Parameter _dataType, const void * _data); ObjectName name;
u32 msaaLevel = 0;
u32 width = 0;
u32 height = 0;
u32 mipMapLevel = 0;
Parameter format;
Parameter internalFormat;
Parameter dataType;
const void * data;
};
void init2DTexture(const InitTextureParams & _params);
bool isMultisamplingSupported() const; bool isMultisamplingSupported() const;

View File

@ -2,6 +2,8 @@
#include "ObjectName.h" #include "ObjectName.h"
#include "Parameter.h" #include "Parameter.h"
#include "Context.h"
namespace graphics { namespace graphics {
class ContextImpl class ContextImpl
@ -12,8 +14,7 @@ namespace graphics {
virtual void destroy() = 0; virtual void destroy() = 0;
virtual ObjectName createTexture() = 0; virtual ObjectName createTexture() = 0;
virtual void deleteTexture(ObjectName _name) = 0; virtual void deleteTexture(ObjectName _name) = 0;
virtual void init2DTexture(ObjectName _name, u32 _msaaLevel, u32 _width, u32 _height, u32 _mipMapLevel, virtual void init2DTexture(const Context::InitTextureParams & _params) = 0;
Parameter _format, Parameter _internalFormat, Parameter _dataType, const void * _data) = 0;
}; };
} }

View File

@ -6,6 +6,7 @@ namespace graphics {
class ObjectName class ObjectName
{ {
public: public:
ObjectName() : m_name(0) {}
explicit ObjectName(u32 _name) : m_name(_name) {} explicit ObjectName(u32 _name) : m_name(_name) {}
explicit operator u32() const { return m_name; } explicit operator u32() const { return m_name; }

View File

@ -17,6 +17,11 @@ CachedEnable::CachedEnable()
{ {
} }
void CachedEnable::reset()
{
m_enabled = false;
}
void CachedEnable::enable(bool _enable) void CachedEnable::enable(bool _enable)
{ {
// TODO make cacheable // TODO make cacheable
@ -33,6 +38,11 @@ CachedBindTexture::CachedBindTexture()
: m_name(0U) { : m_name(0U) {
} }
void CachedBindTexture::reset()
{
m_name = graphics::ObjectName(0U);
}
void CachedBindTexture::bind(graphics::Parameter _target, graphics::ObjectName _name) void CachedBindTexture::bind(graphics::Parameter _target, graphics::ObjectName _name)
{ {
m_name = _name; m_name = _name;
@ -52,6 +62,14 @@ CachedFunctions::~CachedFunctions()
{ {
} }
void CachedFunctions::reset() {
for (auto it : m_enables)
it.second.reset();
m_bindTexture.reset();
}
CachedEnable * CachedFunctions::getCachedEnable(graphics::Parameter _parameter) CachedEnable * CachedFunctions::getCachedEnable(graphics::Parameter _parameter)
{ {
const u32 key(_parameter); const u32 key(_parameter);

View File

@ -9,6 +9,9 @@ namespace opengl {
public: public:
CachedEnable(); CachedEnable();
CachedEnable(graphics::Parameter _parameter); CachedEnable(graphics::Parameter _parameter);
void reset();
void enable(bool _enable); void enable(bool _enable);
private: private:
@ -35,6 +38,9 @@ namespace opengl {
class CachedBindTexture { class CachedBindTexture {
public: public:
CachedBindTexture(); CachedBindTexture();
void reset();
void bind(graphics::Parameter _target, graphics::ObjectName _name); void bind(graphics::Parameter _target, graphics::ObjectName _name);
private: private:
@ -47,9 +53,14 @@ namespace opengl {
public: public:
CachedFunctions(); CachedFunctions();
~CachedFunctions(); ~CachedFunctions();
void reset();
CachedEnable * getCachedEnable(graphics::Parameter _parameter); CachedEnable * getCachedEnable(graphics::Parameter _parameter);
CachedBindTexture * getCachedBindTexture(); CachedBindTexture * getCachedBindTexture();
private: private:
typedef std::unordered_map<u32, CachedEnable> EnableParameters; typedef std::unordered_map<u32, CachedEnable> EnableParameters;
@ -57,4 +68,4 @@ namespace opengl {
CachedBindTexture m_bindTexture; CachedBindTexture m_bindTexture;
}; };
} }

View File

@ -1,8 +1,6 @@
#include <assert.h> #include <assert.h>
#include <Log.h> #include <Log.h>
#include "opengl_ContextImpl.h" #include "opengl_ContextImpl.h"
#include "opengl_GLVersion.h"
#include "opengl_CachedFunctions.h"
using namespace opengl; using namespace opengl;
@ -21,17 +19,13 @@ void ContextImpl::init()
{ {
initGLFunctions(); initGLFunctions();
GLVersion version; glGetIntegerv(GL_MAJOR_VERSION, &m_version.majorVersion);
glGetIntegerv(GL_MAJOR_VERSION, &version.majorVersion); LOG(LOG_VERBOSE, "OpenGL major version: %d\n", m_version.majorVersion);
LOG(LOG_VERBOSE, "OpenGL major version: %d\n", version.majorVersion); assert(m_version.majorVersion >= 3 && "Plugin requires GL version 3 or higher.");
assert(version.majorVersion >= 3 && "Plugin requires GL version 3 or higher."); glGetIntegerv(GL_MINOR_VERSION, &m_version.minorVersion);
GLint minorVersion = 0; LOG(LOG_VERBOSE, "OpenGL minor version: %d\n", m_version.minorVersion);
glGetIntegerv(GL_MINOR_VERSION, &version.minorVersion);
LOG(LOG_VERBOSE, "OpenGL minor version: %d\n", version.minorVersion);
CachedFunctions cachedFunctions; TextureManipulationObjectFactory textureObjectsFactory(m_version, m_cachedFunctions);
TextureManipulationObjectFactory textureObjectsFactory(version, cachedFunctions);
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture()); m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
} }
@ -54,11 +48,8 @@ void ContextImpl::deleteTexture(graphics::ObjectName _name)
glDeleteTextures(1, &glName); glDeleteTextures(1, &glName);
} }
void ContextImpl::init2DTexture(graphics::ObjectName _name, u32 _msaaLevel, u32 _width, u32 _height, u32 _mipMapLevel, void ContextImpl::init2DTexture(const graphics::Context::InitTextureParams & _params)
graphics::Parameter _format, graphics::Parameter _internalFormat, graphics::Parameter _dataType,
const void * _data)
{ {
assert(m_init2DTexture); assert(m_init2DTexture);
m_init2DTexture->init2DTexture(_name, _msaaLevel, _width, _height, m_init2DTexture->init2DTexture(_params);
_mipMapLevel, _format, _internalFormat, _dataType, _data);
} }

View File

@ -2,6 +2,8 @@
#include <memory> #include <memory>
#include <Graphics/ContextImpl.h> #include <Graphics/ContextImpl.h>
#include "opengl_TextureManipulationObjectFactory.h" #include "opengl_TextureManipulationObjectFactory.h"
#include "opengl_GLVersion.h"
#include "opengl_CachedFunctions.h"
namespace opengl { namespace opengl {
@ -19,12 +21,12 @@ namespace opengl {
void deleteTexture(graphics::ObjectName _name) override; void deleteTexture(graphics::ObjectName _name) override;
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel, u32 _width, u32 _height, u32 _mipMapLevel, void init2DTexture(const graphics::Context::InitTextureParams & _params) override;
graphics::Parameter _format, graphics::Parameter _internalFormat, graphics::Parameter _dataType,
const void * _data) override;
private: private:
std::unique_ptr<Init2DTexture> m_init2DTexture; std::unique_ptr<Init2DTexture> m_init2DTexture;
GLVersion m_version;
CachedFunctions m_cachedFunctions;
}; };
} }

View File

@ -11,19 +11,30 @@ namespace opengl {
public: public:
Init2DTexImage(CachedBindTexture* _bind) : m_bind(_bind) {} Init2DTexImage(CachedBindTexture* _bind) : m_bind(_bind) {}
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel, void init2DTexture(const graphics::Context::InitTextureParams & _params) override
u32 _width, u32 _height, u32 _mipMapLevel, {
graphics::Parameter _format, graphics::Parameter _internalFormat,
graphics::Parameter _dataType, const void * _data) override {
if (_msaaLevel == 0) { if (_params.msaaLevel == 0) {
//glBindTexture(GL_TEXTURE_2D, GLuint(_name)); //glBindTexture(GL_TEXTURE_2D, GLuint(_name));
m_bind->bind(graphics::target::TEXTURE_2D, _name); m_bind->bind(graphics::target::TEXTURE_2D, _params.name);
glTexImage2D(GL_TEXTURE_2D, _mipMapLevel, GLuint(_internalFormat), _width, _height, 0, GLenum(_format), GLenum(_dataType), _data); glTexImage2D(GL_TEXTURE_2D,
_params.mipMapLevel,
GLuint(_params.internalFormat),
_params.width,
_params.height,
0,
GLenum(_params.format),
GLenum(_params.dataType),
_params.data);
} else { } else {
//glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, GLuint(_name)); //glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, GLuint(_name));
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _name); m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.name);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,
_params.msaaLevel,
GLenum(_params.internalFormat),
_params.width,
_params.height,
false);
} }
} }
@ -40,19 +51,33 @@ namespace opengl {
Init2DTexStorage(CachedBindTexture* _bind) : m_bind(_bind) {} Init2DTexStorage(CachedBindTexture* _bind) : m_bind(_bind) {}
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel, void init2DTexture(const graphics::Context::InitTextureParams & _params) override
u32 _width, u32 _height, u32 _mipMapLevel, {
graphics::Parameter _format, graphics::Parameter _internalFormat, if (_params.msaaLevel == 0) {
graphics::Parameter _dataType, const void * _data) override { m_bind->bind(graphics::target::TEXTURE_2D, _params.name);
glTexStorage2D(GL_TEXTURE_2D,
if (_msaaLevel == 0) { _params.mipMapLevel,
m_bind->bind(graphics::target::TEXTURE_2D, _name); GLenum(_params.internalFormat),
glTexStorage2D(GL_TEXTURE_2D, _mipMapLevel, GLenum(_internalFormat), _width, _height); _params.width,
if (_data != nullptr) _params.height);
glTexSubImage2D(GL_TEXTURE_2D, _mipMapLevel, 0, 0, _width, _height, GLuint(_format), GLenum(_dataType), _data); if (_params.data != nullptr)
glTexSubImage2D(GL_TEXTURE_2D,
_params.mipMapLevel,
0, 0,
_params.width,
_params.height,
GLuint(_params.format),
GLenum(_params.dataType),
_params.data);
} else { } else {
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _name); m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.name);
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false); glTexStorage2DMultisample(
GL_TEXTURE_2D_MULTISAMPLE,
_params.msaaLevel,
GLenum(_params.internalFormat),
_params.width,
_params.height,
false);
} }
} }
@ -67,17 +92,31 @@ namespace opengl {
// return (_version.majorVersion > 4) || (_version.majorVersion == 4 && _version.minorVersion >= 5); // return (_version.majorVersion > 4) || (_version.majorVersion == 4 && _version.minorVersion >= 5);
return false; return false;
} }
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel, void init2DTexture(const graphics::Context::InitTextureParams & _params) override
u32 _width, u32 _height, u32 _mipMapLevel, {
graphics::Parameter _format, graphics::Parameter _internalFormat,
graphics::Parameter _dataType, const void * _data) override {
if (_msaaLevel == 0) { if (_params.msaaLevel == 0) {
glTextureStorage2D(GLuint(_name), _mipMapLevel, GLenum(_internalFormat), _width, _height); glTextureStorage2D(GLuint(_params.name),
if (_data != nullptr) _params.mipMapLevel,
glTextureSubImage2D(GLuint(_name), _mipMapLevel, 0, 0, _width, _height, GLuint(_format), GLenum(_dataType), _data); GLenum(_params.internalFormat),
_params.width,
_params.height);
if (_params.data != nullptr)
glTextureSubImage2D(GLuint(_params.name),
_params.mipMapLevel,
0, 0,
_params.width,
_params.height,
GLuint(_params.format),
GLenum(_params.dataType),
_params.data);
} else { } else {
glTexStorage2DMultisample(GLuint(_name), _msaaLevel, GLenum(_internalFormat), _width, _height, false); glTexStorage2DMultisample(GLuint(_params.name),
_params.msaaLevel,
GLenum(_params.internalFormat),
_params.width,
_params.height,
false);
} }
} }
}; };
@ -107,4 +146,4 @@ namespace opengl {
return new Init2DTexImage(m_cachedFunctions.getCachedBindTexture()); return new Init2DTexImage(m_cachedFunctions.getCachedBindTexture());
} }
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <Graphics/ObjectName.h> #include <Graphics/ObjectName.h>
#include <Graphics/Parameter.h> #include <Graphics/Parameter.h>
#include <Graphics/Context.h>
namespace opengl { namespace opengl {
@ -10,10 +11,7 @@ namespace opengl {
class Init2DTexture { class Init2DTexture {
public: public:
virtual ~Init2DTexture() {}; virtual ~Init2DTexture() {};
virtual void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel, virtual void init2DTexture(const graphics::Context::InitTextureParams & _params) = 0;
u32 _width, u32 _height, u32 _mipMapLevel,
graphics::Parameter _format, graphics::Parameter _internalFormat,
graphics::Parameter _dataType, const void * _data) = 0;
}; };
class TextureManipulationObjectFactory class TextureManipulationObjectFactory
@ -29,4 +27,4 @@ namespace opengl {
CachedFunctions & m_cachedFunctions; CachedFunctions & m_cachedFunctions;
}; };
} }

View File

@ -6,6 +6,7 @@ namespace graphics {
class Parameter class Parameter
{ {
public: public:
Parameter() : m_parameter(0U) {}
Parameter(u32 _parameter) : m_parameter(_parameter) {} Parameter(u32 _parameter) : m_parameter(_parameter) {}
explicit operator u32() const { return m_parameter; } explicit operator u32() const { return m_parameter; }
explicit operator s32() const { return static_cast<s32>(m_parameter); } explicit operator s32() const { return static_cast<s32>(m_parameter); }

View File

@ -480,8 +480,17 @@ void TextureCache::init()
glBindTexture(GL_TEXTURE_2D, m_pDummy->glName); glBindTexture(GL_TEXTURE_2D, m_pDummy->glName);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, dummyTexture ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, dummyTexture );
#else #else
gfxContext.init2DTexture(graphics::ObjectName(m_pDummy->glName), 0, m_pDummy->realWidth, m_pDummy->realHeight, 0, graphics::Context::InitTextureParams params;
graphics::color::RGBA, graphics::internalcolor::RGBA, graphics::type::UNSIGNED_BYTE, dummyTexture); params.name = graphics::ObjectName(m_pDummy->glName);
params.mipMapLevel = 0;
params.msaaLevel = 0;
params.width = m_pDummy->realWidth;
params.height = m_pDummy->realHeight;
params.format = graphics::color::RGBA;
params.internalFormat = graphics::internalcolor::RGBA;
params.dataType = graphics::type::UNSIGNED_BYTE;
params.data = dummyTexture;
gfxContext.init2DTexture(params);
#endif #endif
m_cachedBytes = m_pDummy->textureBytes; m_cachedBytes = m_pDummy->textureBytes;
@ -519,9 +528,16 @@ void TextureCache::init()
m_pMSDummy = addFrameBufferTexture(); // we don't want to remove dummy texture m_pMSDummy = addFrameBufferTexture(); // we don't want to remove dummy texture
_initDummyTexture(m_pMSDummy); _initDummyTexture(m_pMSDummy);
gfxContext.init2DTexture(graphics::ObjectName(m_pMSDummy->glName), config.video.multisampling, graphics::Context::InitTextureParams params;
m_pMSDummy->realWidth, m_pMSDummy->realHeight, 0, params.name = graphics::ObjectName(m_pMSDummy->glName);
graphics::color::RGBA, graphics::internalcolor::RGBA, graphics::type::UNSIGNED_BYTE, nullptr); params.mipMapLevel = 0;
params.msaaLevel = config.video.multisampling;
params.width = m_pMSDummy->realWidth;
params.height = m_pMSDummy->realHeight;
params.format = graphics::color::RGBA;
params.internalFormat = graphics::internalcolor::RGBA;
params.dataType = graphics::type::UNSIGNED_BYTE;
gfxContext.init2DTexture(params);
activateMSDummy(0); activateMSDummy(0);
activateMSDummy(1); activateMSDummy(1);