2015-05-19 06:21:33 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
#include <utility>
|
2015-08-30 08:37:42 +02:00
|
|
|
#include <glad/glad.h>
|
2015-05-19 06:21:33 +02:00
|
|
|
#include "common/common_types.h"
|
2015-07-26 11:38:19 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
class OGLTexture : private NonCopyable {
|
2015-05-19 06:21:33 +02:00
|
|
|
public:
|
2015-07-26 11:38:19 +02:00
|
|
|
OGLTexture() = default;
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLTexture(OGLTexture&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLTexture() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLTexture& operator=(OGLTexture&& o) noexcept {
|
2018-04-07 05:53:19 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
2016-09-18 02:38:01 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
2019-01-06 22:49:23 +01:00
|
|
|
void Create(GLenum target);
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
GLuint handle = 0;
|
2015-05-19 06:21:33 +02:00
|
|
|
};
|
|
|
|
|
2015-08-30 13:41:28 +02:00
|
|
|
class OGLSampler : private NonCopyable {
|
|
|
|
public:
|
|
|
|
OGLSampler() = default;
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLSampler(OGLSampler&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLSampler() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLSampler& operator=(OGLSampler&& o) noexcept {
|
2018-04-07 05:53:19 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
2016-09-18 02:38:01 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2015-08-30 13:41:28 +02:00
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
2018-11-06 10:40:49 +01:00
|
|
|
void Create();
|
2015-08-30 13:41:28 +02:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2015-08-30 13:41:28 +02:00
|
|
|
|
|
|
|
GLuint handle = 0;
|
|
|
|
};
|
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
class OGLShader : private NonCopyable {
|
2015-05-19 06:21:33 +02:00
|
|
|
public:
|
2015-07-26 11:38:19 +02:00
|
|
|
OGLShader() = default;
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLShader(OGLShader&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLShader() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLShader& operator=(OGLShader&& o) noexcept {
|
2018-04-07 05:53:19 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
2016-09-18 02:38:01 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2018-11-06 10:40:49 +01:00
|
|
|
void Create(const char* source, GLenum type);
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2018-04-07 05:53:19 +02:00
|
|
|
|
|
|
|
GLuint handle = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OGLProgram : private NonCopyable {
|
|
|
|
public:
|
|
|
|
OGLProgram() = default;
|
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLProgram(OGLProgram&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
|
|
|
~OGLProgram() {
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLProgram& operator=(OGLProgram&& o) noexcept {
|
2018-04-07 05:53:19 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... T>
|
2018-04-14 20:09:32 +02:00
|
|
|
void Create(bool separable_program, T... shaders) {
|
2016-09-18 02:38:01 +02:00
|
|
|
if (handle != 0)
|
|
|
|
return;
|
2018-04-07 05:53:19 +02:00
|
|
|
handle = GLShader::LoadProgram(separable_program, shaders...);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
|
|
|
void CreateFromSource(const char* vert_shader, const char* geo_shader, const char* frag_shader,
|
2018-11-06 10:40:49 +01:00
|
|
|
bool separable_program = false);
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2018-03-19 22:20:49 +01:00
|
|
|
|
|
|
|
GLuint handle = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OGLPipeline : private NonCopyable {
|
|
|
|
public:
|
|
|
|
OGLPipeline() = default;
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLPipeline(OGLPipeline&& o) noexcept : handle{std::exchange<GLuint>(o.handle, 0)} {}
|
|
|
|
|
2018-03-19 22:20:49 +01:00
|
|
|
~OGLPipeline() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLPipeline& operator=(OGLPipeline&& o) noexcept {
|
2018-03-19 22:20:49 +01:00
|
|
|
handle = std::exchange<GLuint>(o.handle, 0);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
2018-11-06 10:40:49 +01:00
|
|
|
void Create();
|
2018-03-19 22:20:49 +01:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
GLuint handle = 0;
|
2015-05-19 06:21:33 +02:00
|
|
|
};
|
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
class OGLBuffer : private NonCopyable {
|
2015-05-19 06:21:33 +02:00
|
|
|
public:
|
2015-07-26 11:38:19 +02:00
|
|
|
OGLBuffer() = default;
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLBuffer(OGLBuffer&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLBuffer() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLBuffer& operator=(OGLBuffer&& o) noexcept {
|
2018-04-07 05:53:19 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
2016-09-18 02:38:01 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
2018-11-06 10:40:49 +01:00
|
|
|
void Create();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
GLuint handle = 0;
|
2015-05-19 06:21:33 +02:00
|
|
|
};
|
|
|
|
|
2018-03-19 22:20:49 +01:00
|
|
|
class OGLSync : private NonCopyable {
|
|
|
|
public:
|
|
|
|
OGLSync() = default;
|
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLSync(OGLSync&& o) noexcept : handle(std::exchange(o.handle, nullptr)) {}
|
2018-03-19 22:20:49 +01:00
|
|
|
|
|
|
|
~OGLSync() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLSync& operator=(OGLSync&& o) noexcept {
|
2018-03-19 22:20:49 +01:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
2018-11-06 10:40:49 +01:00
|
|
|
void Create();
|
2018-03-19 22:20:49 +01:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2018-03-19 22:20:49 +01:00
|
|
|
|
|
|
|
GLsync handle = 0;
|
|
|
|
};
|
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
class OGLVertexArray : private NonCopyable {
|
2015-05-19 06:21:33 +02:00
|
|
|
public:
|
2015-07-26 11:38:19 +02:00
|
|
|
OGLVertexArray() = default;
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLVertexArray(OGLVertexArray&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLVertexArray() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLVertexArray& operator=(OGLVertexArray&& o) noexcept {
|
2018-04-07 05:53:19 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
2016-09-18 02:38:01 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
2018-11-06 10:40:49 +01:00
|
|
|
void Create();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
GLuint handle = 0;
|
2015-05-19 06:21:33 +02:00
|
|
|
};
|
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
class OGLFramebuffer : private NonCopyable {
|
2015-05-19 06:21:33 +02:00
|
|
|
public:
|
2015-07-26 11:38:19 +02:00
|
|
|
OGLFramebuffer() = default;
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLFramebuffer(OGLFramebuffer&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLFramebuffer() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-04-07 05:53:19 +02:00
|
|
|
|
2018-04-21 02:03:57 +02:00
|
|
|
OGLFramebuffer& operator=(OGLFramebuffer&& o) noexcept {
|
2018-04-07 05:53:19 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
2016-09-18 02:38:01 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
2018-11-06 10:40:49 +01:00
|
|
|
void Create();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2015-07-26 11:38:19 +02:00
|
|
|
GLuint handle = 0;
|
2015-05-19 06:21:33 +02:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|