OpenGL: Implement textures
This commit is contained in:
@@ -2,42 +2,82 @@
|
||||
// This file is part of the "Nazara Engine - OpenGL Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/PipelineLayout.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Texture.hpp>
|
||||
#include <cassert>
|
||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::GL
|
||||
{
|
||||
namespace Vk
|
||||
inline Texture::~Texture()
|
||||
{
|
||||
inline bool PipelineLayout::Create(Device& device, VkDescriptorSetLayout layout, VkPipelineLayoutCreateFlags flags)
|
||||
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)
|
||||
{
|
||||
return Create(device, 1U, &layout, flags);
|
||||
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);
|
||||
}
|
||||
|
||||
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.glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, border, format, type, data);
|
||||
//< TODO: Handle errors
|
||||
}
|
||||
|
||||
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.glTexSubImage2D(GL_TEXTURE_2D, level, xoffset, yoffset, width, height, format, type, data);
|
||||
//< TODO: Handle errors
|
||||
}
|
||||
|
||||
inline const Context& Texture::EnsureDeviceContext()
|
||||
{
|
||||
assert(m_device);
|
||||
|
||||
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 referenceContext;
|
||||
}
|
||||
|
||||
inline bool PipelineLayout::Create(Device& device, UInt32 layoutCount, const VkDescriptorSetLayout* layouts, VkPipelineLayoutCreateFlags flags)
|
||||
{
|
||||
VkPipelineLayoutCreateInfo createInfo = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
layoutCount,
|
||||
layouts,
|
||||
0U,
|
||||
nullptr
|
||||
};
|
||||
|
||||
return Create(device, createInfo);
|
||||
}
|
||||
|
||||
inline VkResult PipelineLayout::CreateHelper(Device& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle)
|
||||
{
|
||||
return device.vkCreatePipelineLayout(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void PipelineLayout::DestroyHelper(Device& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device.vkDestroyPipelineLayout(device, handle, allocator);
|
||||
}
|
||||
return *activeContext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user