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,58 +8,32 @@
namespace Nz::GL
{
inline Shader::~Shader()
{
Destroy();
}
inline void Shader::Compile()
{
assert(m_shader);
m_device->GetReferenceContext().glCompileShader(m_shader);
}
inline bool Shader::Create(OpenGLDevice& device, GLenum type)
{
Destroy();
m_device = &device;
m_shader = device.GetReferenceContext().glCreateShader(type);
if (!m_shader)
return false; //< TODO: Handle error messages
return true;
}
inline void Shader::Destroy()
{
if (m_shader)
{
m_device->GetReferenceContext().glDeleteShader(m_shader);
m_shader = 0;
}
assert(m_objectId);
m_device->GetReferenceContext().glCompileShader(m_objectId);
}
inline bool Shader::GetCompilationStatus(std::string* error)
{
assert(m_shader);
const GL::Context& context = m_device->GetReferenceContext();
assert(m_objectId);
const Context& context = EnsureDeviceContext();
GLint success;
context.glGetShaderiv(m_shader, GL_COMPILE_STATUS, &success);
context.glGetShaderiv(m_objectId, GL_COMPILE_STATUS, &success);
if (!success)
{
if (error)
{
GLint logLength;
context.glGetShaderiv(m_shader, GL_INFO_LOG_LENGTH, &logLength);
context.glGetShaderiv(m_objectId, GL_INFO_LOG_LENGTH, &logLength);
error->resize(logLength);
if (logLength > 0)
{
GLsizei dummy;
context.glGetShaderInfoLog(m_shader, logLength, &dummy, error->data());
context.glGetShaderInfoLog(m_objectId, logLength, &dummy, error->data());
}
}
@@ -71,25 +45,35 @@ namespace Nz::GL
inline void Shader::SetBinarySource(GLenum binaryFormat, const void* binary, GLsizei length)
{
assert(m_shader);
assert(m_objectId);
m_device->GetReferenceContext().glShaderBinary(1U, &m_shader.Get(), binaryFormat, binary, length);
m_device->GetReferenceContext().glShaderBinary(1U, &m_objectId.Get(), binaryFormat, binary, length);
}
inline void Shader::SetSource(const char* source, GLint length)
{
assert(m_shader);
assert(m_objectId);
m_device->GetReferenceContext().glShaderSource(m_shader, 1U, &source, &length);
m_device->GetReferenceContext().glShaderSource(m_objectId, 1U, &source, &length);
}
inline void Shader::SpecializeShader(const GLchar* pEntryPoint, GLuint numSpecializationConstants, const GLuint* pConstantIndex, const GLuint* pConstantValue)
{
assert(m_shader);
const GL::Context& context = m_device->GetReferenceContext();
assert(m_objectId);
const Context& context = EnsureDeviceContext();
assert(context.glSpecializeShaderARB);
context.glSpecializeShaderARB(m_shader, pEntryPoint, numSpecializationConstants, pConstantIndex, pConstantValue);
context.glSpecializeShaderARB(m_objectId, pEntryPoint, numSpecializationConstants, pConstantIndex, pConstantValue);
}
inline GLuint Shader::CreateHelper(OpenGLDevice& device, const Context& context, GLenum shaderStage)
{
return context.glCreateShader(shaderStage);
}
inline void Shader::DestroyHelper(OpenGLDevice& device, const Context& context, GLuint objectId)
{
context.glDeleteShader(objectId);
}
}