mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Add cached GL functions.
This commit is contained in:
parent
c1c09d4d56
commit
62e7fcf580
|
@ -303,6 +303,7 @@
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\Graphics\Context.cpp" />
|
<ClCompile Include="..\..\src\Graphics\Context.cpp" />
|
||||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLFunctions.cpp" />
|
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLFunctions.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_CachedFunctions.cpp" />
|
||||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.cpp" />
|
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.cpp" />
|
||||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Parameters.cpp" />
|
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Parameters.cpp" />
|
||||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.cpp" />
|
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.cpp" />
|
||||||
|
@ -431,6 +432,7 @@
|
||||||
<ClInclude Include="..\..\src\Graphics\ContextImpl.h" />
|
<ClInclude Include="..\..\src\Graphics\ContextImpl.h" />
|
||||||
<ClInclude Include="..\..\src\Graphics\ObjectName.h" />
|
<ClInclude Include="..\..\src\Graphics\ObjectName.h" />
|
||||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLFunctions.h" />
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLFunctions.h" />
|
||||||
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_CachedFunctions.h" />
|
||||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.h" />
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.h" />
|
||||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GLVersion.h" />
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GLVersion.h" />
|
||||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.h" />
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.h" />
|
||||||
|
|
|
@ -296,6 +296,9 @@
|
||||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.cpp">
|
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.cpp">
|
||||||
<Filter>Source Files\Graphics\OpenGL</Filter>
|
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_CachedFunctions.cpp">
|
||||||
|
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\3DMath.h">
|
<ClInclude Include="..\..\src\3DMath.h">
|
||||||
|
@ -535,5 +538,8 @@
|
||||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GLVersion.h">
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GLVersion.h">
|
||||||
<Filter>Header Files\Graphics\OpenGL</Filter>
|
<Filter>Header Files\Graphics\OpenGL</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_CachedFunctions.h">
|
||||||
|
<Filter>Header Files\Graphics\OpenGL</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
71
src/Graphics/OpenGLContext/opengl_CachedFunctions.cpp
Normal file
71
src/Graphics/OpenGLContext/opengl_CachedFunctions.cpp
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
#include "GLFunctions.h"
|
||||||
|
#include "opengl_CachedFunctions.h"
|
||||||
|
|
||||||
|
using namespace opengl;
|
||||||
|
|
||||||
|
/*---------------CachedEnable-------------*/
|
||||||
|
|
||||||
|
CachedEnable::CachedEnable(graphics::Parameter _parameter)
|
||||||
|
: m_parameter(_parameter)
|
||||||
|
, m_enabled(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CachedEnable::CachedEnable()
|
||||||
|
: m_parameter(0U)
|
||||||
|
, m_enabled(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CachedEnable::enable(bool _enable)
|
||||||
|
{
|
||||||
|
// TODO make cacheable
|
||||||
|
if (_enable) {
|
||||||
|
glEnable(GLenum(m_parameter));
|
||||||
|
} else {
|
||||||
|
glDisable(GLenum(m_parameter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------CachedBindTexture-------------*/
|
||||||
|
|
||||||
|
CachedBindTexture::CachedBindTexture()
|
||||||
|
: m_name(0U) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void CachedBindTexture::bind(graphics::Parameter _target, graphics::ObjectName _name)
|
||||||
|
{
|
||||||
|
m_name = _name;
|
||||||
|
// TODO make cacheable
|
||||||
|
glBindTexture(GLenum(_target), GLuint(_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------CachedFunctions-------------*/
|
||||||
|
|
||||||
|
CachedFunctions::CachedFunctions()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CachedFunctions::~CachedFunctions()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CachedEnable * CachedFunctions::getCachedEnable(graphics::Parameter _parameter)
|
||||||
|
{
|
||||||
|
const u32 key(_parameter);
|
||||||
|
auto it = m_enables.find(key);
|
||||||
|
if (it == m_enables.end()) {
|
||||||
|
auto res = m_enables.emplace(key, _parameter);
|
||||||
|
if (res.second)
|
||||||
|
return &(res.first->second);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return &(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
CachedBindTexture * CachedFunctions::getCachedBindTexture()
|
||||||
|
{
|
||||||
|
return &m_bindTexture;
|
||||||
|
}
|
60
src/Graphics/OpenGLContext/opengl_CachedFunctions.h
Normal file
60
src/Graphics/OpenGLContext/opengl_CachedFunctions.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#pragma once
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <Graphics/ObjectName.h>
|
||||||
|
#include <Graphics/Parameter.h>
|
||||||
|
|
||||||
|
namespace opengl {
|
||||||
|
|
||||||
|
class CachedEnable {
|
||||||
|
public:
|
||||||
|
CachedEnable();
|
||||||
|
CachedEnable(graphics::Parameter _parameter);
|
||||||
|
void enable(bool _enable);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const graphics::Parameter m_parameter;
|
||||||
|
bool m_enabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Bind>
|
||||||
|
class CachedBind {
|
||||||
|
public:
|
||||||
|
CachedBind(Bind * _bind) : m_bind(_bind), m_name(0U) {}
|
||||||
|
|
||||||
|
void bind(graphics::Parameter _target, graphics::ObjectName _name) {
|
||||||
|
// TODO make cacheble
|
||||||
|
m_bind(GLenum(_target), GLuint(_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
graphics::ObjectName m_name;
|
||||||
|
Bind * m_bind;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CachedBindTexture {
|
||||||
|
public:
|
||||||
|
CachedBindTexture();
|
||||||
|
void bind(graphics::Parameter _target, graphics::ObjectName _name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
graphics::ObjectName m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class CachedFunctions
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CachedFunctions();
|
||||||
|
~CachedFunctions();
|
||||||
|
CachedEnable * getCachedEnable(graphics::Parameter _parameter);
|
||||||
|
CachedBindTexture * getCachedBindTexture();
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef std::unordered_map<u32, CachedEnable> EnableParameters;
|
||||||
|
|
||||||
|
EnableParameters m_enables;
|
||||||
|
CachedBindTexture m_bindTexture;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
#include <Log.h>
|
#include <Log.h>
|
||||||
#include "opengl_ContextImpl.h"
|
#include "opengl_ContextImpl.h"
|
||||||
#include "opengl_GLVersion.h"
|
#include "opengl_GLVersion.h"
|
||||||
|
#include "opengl_CachedFunctions.h"
|
||||||
|
|
||||||
using namespace opengl;
|
using namespace opengl;
|
||||||
|
|
||||||
|
@ -28,7 +29,9 @@ void ContextImpl::init()
|
||||||
glGetIntegerv(GL_MINOR_VERSION, &version.minorVersion);
|
glGetIntegerv(GL_MINOR_VERSION, &version.minorVersion);
|
||||||
LOG(LOG_VERBOSE, "OpenGL minor version: %d\n", version.minorVersion);
|
LOG(LOG_VERBOSE, "OpenGL minor version: %d\n", version.minorVersion);
|
||||||
|
|
||||||
TextureManipulationObjectFactory textureObjectsFactory(version);
|
CachedFunctions cachedFunctions;
|
||||||
|
|
||||||
|
TextureManipulationObjectFactory textureObjectsFactory(version, cachedFunctions);
|
||||||
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
|
m_init2DTexture.reset(textureObjectsFactory.getInit2DTexture());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,20 @@ namespace graphics {
|
||||||
Parameter FLOAT(GL_FLOAT);
|
Parameter FLOAT(GL_FLOAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace target {
|
||||||
|
Parameter TEXTURE_2D(GL_TEXTURE_2D);
|
||||||
|
Parameter TEXTURE_2D_MULTISAMPLE(GL_TEXTURE_2D_MULTISAMPLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace enable {
|
||||||
|
Parameter BLEND(GL_BLEND);
|
||||||
|
Parameter CULL_FACE(GL_CULL_FACE);
|
||||||
|
Parameter DEPTH_TEST(GL_DEPTH_TEST);
|
||||||
|
Parameter DEPTH_CLAMP(GL_DEPTH_CLAMP);
|
||||||
|
Parameter CLIP_DISTANCE0(GL_CLIP_DISTANCE0);
|
||||||
|
Parameter DITHER(GL_DITHER);
|
||||||
|
Parameter POLYGON_OFFSET_FILL(GL_POLYGON_OFFSET_FILL);
|
||||||
|
Parameter SCISSOR_TEST(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,34 @@
|
||||||
|
#include <Graphics/Parameters.h>
|
||||||
#include "opengl_GLVersion.h"
|
#include "opengl_GLVersion.h"
|
||||||
|
#include "opengl_CachedFunctions.h"
|
||||||
#include "opengl_TextureManipulationObjectFactory.h"
|
#include "opengl_TextureManipulationObjectFactory.h"
|
||||||
|
|
||||||
namespace opengl {
|
namespace opengl {
|
||||||
|
|
||||||
TextureManipulationObjectFactory::TextureManipulationObjectFactory(const GLVersion & _version)
|
|
||||||
: m_version(_version)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureManipulationObjectFactory::~TextureManipulationObjectFactory()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------Init2DTexture-------------*/
|
/*---------------Init2DTexture-------------*/
|
||||||
|
|
||||||
class Init2DTexImage : public Init2DTexture {
|
class Init2DTexImage : public Init2DTexture {
|
||||||
public:
|
public:
|
||||||
|
Init2DTexImage(CachedBindTexture* _bind) : m_bind(_bind) {}
|
||||||
|
|
||||||
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel,
|
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel,
|
||||||
u32 _width, u32 _height, u32 _mipMapLevel,
|
u32 _width, u32 _height, u32 _mipMapLevel,
|
||||||
graphics::Parameter _format, graphics::Parameter _internalFormat,
|
graphics::Parameter _format, graphics::Parameter _internalFormat,
|
||||||
graphics::Parameter _dataType, const void * _data) override {
|
graphics::Parameter _dataType, const void * _data) override {
|
||||||
|
|
||||||
if (_msaaLevel == 0) {
|
if (_msaaLevel == 0) {
|
||||||
glBindTexture(GL_TEXTURE_2D, GLuint(_name));
|
//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);
|
glTexImage2D(GL_TEXTURE_2D, _mipMapLevel, GLuint(_internalFormat), _width, _height, 0, GLenum(_format), GLenum(_dataType), _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);
|
||||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false);
|
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CachedBindTexture* m_bind;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Init2DTexStorage : public Init2DTexture {
|
class Init2DTexStorage : public Init2DTexture {
|
||||||
|
@ -39,22 +38,27 @@ namespace opengl {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Init2DTexStorage(CachedBindTexture* _bind) : m_bind(_bind) {}
|
||||||
|
|
||||||
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel,
|
void init2DTexture(graphics::ObjectName _name, u32 _msaaLevel,
|
||||||
u32 _width, u32 _height, u32 _mipMapLevel,
|
u32 _width, u32 _height, u32 _mipMapLevel,
|
||||||
graphics::Parameter _format, graphics::Parameter _internalFormat,
|
graphics::Parameter _format, graphics::Parameter _internalFormat,
|
||||||
graphics::Parameter _dataType, const void * _data) override {
|
graphics::Parameter _dataType, const void * _data) override {
|
||||||
|
|
||||||
if (_msaaLevel == 0) {
|
if (_msaaLevel == 0) {
|
||||||
glBindTexture(GL_TEXTURE_2D, GLuint(_name));
|
m_bind->bind(graphics::target::TEXTURE_2D, _name);
|
||||||
glTexStorage2D(GL_TEXTURE_2D, _mipMapLevel, GLenum(_internalFormat), _width, _height);
|
glTexStorage2D(GL_TEXTURE_2D, _mipMapLevel, GLenum(_internalFormat), _width, _height);
|
||||||
if (_data != nullptr)
|
if (_data != nullptr)
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, _mipMapLevel, 0, 0, _width, _height, GLuint(_format), GLenum(_dataType), _data);
|
glTexSubImage2D(GL_TEXTURE_2D, _mipMapLevel, 0, 0, _width, _height, GLuint(_format), GLenum(_dataType), _data);
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, GLuint(_name));
|
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _name);
|
||||||
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false);
|
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, _msaaLevel, GLenum(_internalFormat), _width, _height, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CachedBindTexture* m_bind;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Init2DTextureStorage : public Init2DTexture {
|
class Init2DTextureStorage : public Init2DTexture {
|
||||||
|
@ -79,15 +83,28 @@ namespace opengl {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------TextureManipulationObjectFactory-------------*/
|
||||||
|
|
||||||
|
TextureManipulationObjectFactory::TextureManipulationObjectFactory(const GLVersion & _version,
|
||||||
|
CachedFunctions & _cachedFunctions)
|
||||||
|
: m_version(_version)
|
||||||
|
, m_cachedFunctions(_cachedFunctions)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureManipulationObjectFactory::~TextureManipulationObjectFactory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Init2DTexture * TextureManipulationObjectFactory::getInit2DTexture() const
|
Init2DTexture * TextureManipulationObjectFactory::getInit2DTexture() const
|
||||||
{
|
{
|
||||||
if (Init2DTextureStorage::Check(m_version))
|
if (Init2DTextureStorage::Check(m_version))
|
||||||
return new Init2DTextureStorage;
|
return new Init2DTextureStorage;
|
||||||
|
|
||||||
if (Init2DTexStorage::Check(m_version))
|
if (Init2DTexStorage::Check(m_version))
|
||||||
return new Init2DTexStorage;
|
return new Init2DTexStorage(m_cachedFunctions.getCachedBindTexture());
|
||||||
|
|
||||||
return new Init2DTexImage;
|
return new Init2DTexImage(m_cachedFunctions.getCachedBindTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
namespace opengl {
|
namespace opengl {
|
||||||
|
|
||||||
struct GLVersion;
|
struct GLVersion;
|
||||||
|
class CachedFunctions;
|
||||||
|
|
||||||
class Init2DTexture {
|
class Init2DTexture {
|
||||||
public:
|
public:
|
||||||
|
@ -18,13 +19,14 @@ namespace opengl {
|
||||||
class TextureManipulationObjectFactory
|
class TextureManipulationObjectFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextureManipulationObjectFactory(const GLVersion & _version);
|
TextureManipulationObjectFactory(const GLVersion & _version, CachedFunctions & _cachedFunctions);
|
||||||
~TextureManipulationObjectFactory();
|
~TextureManipulationObjectFactory();
|
||||||
|
|
||||||
Init2DTexture * getInit2DTexture() const;
|
Init2DTexture * getInit2DTexture() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const GLVersion & m_version;
|
const GLVersion & m_version;
|
||||||
|
CachedFunctions & m_cachedFunctions;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,4 +24,19 @@ namespace graphics {
|
||||||
extern Parameter FLOAT;
|
extern Parameter FLOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace target {
|
||||||
|
extern Parameter TEXTURE_2D;
|
||||||
|
extern Parameter TEXTURE_2D_MULTISAMPLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace enable {
|
||||||
|
extern Parameter BLEND;
|
||||||
|
extern Parameter CULL_FACE;
|
||||||
|
extern Parameter DEPTH_TEST;
|
||||||
|
extern Parameter DEPTH_CLAMP;
|
||||||
|
extern Parameter CLIP_DISTANCE0;
|
||||||
|
extern Parameter DITHER;
|
||||||
|
extern Parameter POLYGON_OFFSET_FILL;
|
||||||
|
extern Parameter SCISSOR_TEST;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user