1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +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);
}
void Context::init2DTexture(ObjectName _name, u32 _msaaLevel, u32 _width, u32 _height, u32 _mipMapLevel,
Parameter _format, Parameter _internalFormat, Parameter _dataType, const void * _data)
void Context::init2DTexture(const InitTextureParams & _params)
{
return m_impl->init2DTexture(_name, _msaaLevel, _width, _height,
_mipMapLevel, _format, _internalFormat, _dataType, _data);
return m_impl->init2DTexture(_params);
}
bool Context::isMultisamplingSupported() const

View File

@ -24,8 +24,19 @@ namespace graphics {
void deleteTexture(ObjectName _name);
void init2DTexture(ObjectName _name, u32 _msaaLevel, u32 _width, u32 _height, u32 _mipMapLevel,
Parameter _format, Parameter _internalFormat, Parameter _dataType, const void * _data);
struct InitTextureParams {
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;

View File

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

View File

@ -6,6 +6,7 @@ namespace graphics {
class ObjectName
{
public:
ObjectName() : m_name(0) {}
explicit ObjectName(u32 _name) : m_name(_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)
{
// TODO make cacheable
@ -33,6 +38,11 @@ CachedBindTexture::CachedBindTexture()
: m_name(0U) {
}
void CachedBindTexture::reset()
{
m_name = graphics::ObjectName(0U);
}
void CachedBindTexture::bind(graphics::Parameter _target, graphics::ObjectName _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)
{
const u32 key(_parameter);

View File

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

View File

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

View File

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

View File

@ -11,19 +11,30 @@ namespace opengl {
public:
Init2DTexImage(CachedBindTexture* _bind) : m_bind(_bind) {}
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel,
u32 _width, u32 _height, u32 _mipMapLevel,
graphics::Parameter _format, graphics::Parameter _internalFormat,
graphics::Parameter _dataType, const void * _data) override {
void init2DTexture(const graphics::Context::InitTextureParams & _params) override
{
if (_msaaLevel == 0) {
if (_params.msaaLevel == 0) {
//glBindTexture(GL_TEXTURE_2D, GLuint(_name));
m_bind->bind(graphics::target::TEXTURE_2D, _name);
glTexImage2D(GL_TEXTURE_2D, _mipMapLevel, GLuint(_internalFormat), _width, _height, 0, GLenum(_format), GLenum(_dataType), _data);
m_bind->bind(graphics::target::TEXTURE_2D, _params.name);
glTexImage2D(GL_TEXTURE_2D,
_params.mipMapLevel,
GLuint(_params.internalFormat),
_params.width,
_params.height,
0,
GLenum(_params.format),
GLenum(_params.dataType),
_params.data);
} else {
//glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, GLuint(_name));
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _name);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false);
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.name);
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) {}
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel,
u32 _width, u32 _height, u32 _mipMapLevel,
graphics::Parameter _format, graphics::Parameter _internalFormat,
graphics::Parameter _dataType, const void * _data) override {
if (_msaaLevel == 0) {
m_bind->bind(graphics::target::TEXTURE_2D, _name);
glTexStorage2D(GL_TEXTURE_2D, _mipMapLevel, GLenum(_internalFormat), _width, _height);
if (_data != nullptr)
glTexSubImage2D(GL_TEXTURE_2D, _mipMapLevel, 0, 0, _width, _height, GLuint(_format), GLenum(_dataType), _data);
void init2DTexture(const graphics::Context::InitTextureParams & _params) override
{
if (_params.msaaLevel == 0) {
m_bind->bind(graphics::target::TEXTURE_2D, _params.name);
glTexStorage2D(GL_TEXTURE_2D,
_params.mipMapLevel,
GLenum(_params.internalFormat),
_params.width,
_params.height);
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 {
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _name);
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false);
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.name);
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 false;
}
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel,
u32 _width, u32 _height, u32 _mipMapLevel,
graphics::Parameter _format, graphics::Parameter _internalFormat,
graphics::Parameter _dataType, const void * _data) override {
void init2DTexture(const graphics::Context::InitTextureParams & _params) override
{
if (_msaaLevel == 0) {
glTextureStorage2D(GLuint(_name), _mipMapLevel, GLenum(_internalFormat), _width, _height);
if (_data != nullptr)
glTextureSubImage2D(GLuint(_name), _mipMapLevel, 0, 0, _width, _height, GLuint(_format), GLenum(_dataType), _data);
if (_params.msaaLevel == 0) {
glTextureStorage2D(GLuint(_params.name),
_params.mipMapLevel,
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 {
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());
}
}
}

View File

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

View File

@ -6,6 +6,7 @@ namespace graphics {
class Parameter
{
public:
Parameter() : m_parameter(0U) {}
Parameter(u32 _parameter) : m_parameter(_parameter) {}
explicit operator u32() const { return 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);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, dummyTexture );
#else
gfxContext.init2DTexture(graphics::ObjectName(m_pDummy->glName), 0, m_pDummy->realWidth, m_pDummy->realHeight, 0,
graphics::color::RGBA, graphics::internalcolor::RGBA, graphics::type::UNSIGNED_BYTE, dummyTexture);
graphics::Context::InitTextureParams params;
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
m_cachedBytes = m_pDummy->textureBytes;
@ -519,9 +528,16 @@ void TextureCache::init()
m_pMSDummy = addFrameBufferTexture(); // we don't want to remove dummy texture
_initDummyTexture(m_pMSDummy);
gfxContext.init2DTexture(graphics::ObjectName(m_pMSDummy->glName), config.video.multisampling,
m_pMSDummy->realWidth, m_pMSDummy->realHeight, 0,
graphics::color::RGBA, graphics::internalcolor::RGBA, graphics::type::UNSIGNED_BYTE, nullptr);
graphics::Context::InitTextureParams params;
params.name = graphics::ObjectName(m_pMSDummy->glName);
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(1);