OpenGLRenderer: Use generic DeviceObject

This commit is contained in:
Lynix
2020-04-26 16:26:08 +02:00
parent b4b15f826d
commit 1c23949608
6 changed files with 137 additions and 215 deletions

View File

@@ -8,38 +8,6 @@
namespace Nz::GL
{
inline Texture::~Texture()
{
Destroy();
}
inline bool Texture::Create(OpenGLDevice& device)
{
Destroy();
m_device = &device;
const Context& context = EnsureDeviceContext();
context.glGenTextures(1U, &m_texture.Get());
if (!m_texture)
return false; //< TODO: Handle error messages
return true;
}
inline void Texture::Destroy()
{
if (m_texture)
{
const Context& context = EnsureDeviceContext();
context.glDeleteTextures(1U, &m_texture.Get());
m_device->NotifyTextureDestruction(m_texture);
m_texture = 0;
}
}
inline void Texture::TexImage2D(GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border)
{
return TexImage2D(level, internalFormat, width, height, border, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
@@ -48,7 +16,7 @@ namespace Nz::GL
inline void Texture::TexImage2D(GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* data)
{
const Context& context = EnsureDeviceContext();
context.BindTexture(TextureTarget::Target2D, m_texture);
context.BindTexture(TextureTarget::Target2D, m_objectId);
context.glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, border, format, type, data);
//< TODO: Handle errors
@@ -57,27 +25,25 @@ namespace Nz::GL
inline void Texture::TexSubImage2D(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* data)
{
const Context& context = EnsureDeviceContext();
context.BindTexture(TextureTarget::Target2D, m_texture);
context.BindTexture(TextureTarget::Target2D, m_objectId);
context.glTexSubImage2D(GL_TEXTURE_2D, level, xoffset, yoffset, width, height, format, type, data);
//< TODO: Handle errors
}
inline const Context& Texture::EnsureDeviceContext()
inline GLuint Texture::CreateHelper(OpenGLDevice& device, const Context& context)
{
assert(m_device);
GLuint sampler = 0;
context.glGenTextures(1U, &sampler);
const Context* activeContext = Context::GetCurrentContext();
if (!activeContext || activeContext->GetDevice() != m_device)
{
const Context& referenceContext = m_device->GetReferenceContext();
if (!Context::SetCurrentContext(&referenceContext))
throw std::runtime_error("failed to activate context");
return sampler;
}
return referenceContext;
}
inline void Texture::DestroyHelper(OpenGLDevice& device, const Context& context, GLuint objectId)
{
context.glDeleteTextures(1U, &objectId);
return *activeContext;
device.NotifyTextureDestruction(objectId);
}
}