2022-08-21 01:22:57 +02:00
|
|
|
// Copyright 2022 Citra Emulator Project
|
2015-05-19 06:21:33 +02:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-07-07 00:52:40 +02:00
|
|
|
#include <span>
|
2015-07-26 11:38:19 +02:00
|
|
|
#include <utility>
|
2018-04-09 23:26:09 +02:00
|
|
|
#include <vector>
|
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"
|
|
|
|
|
2018-11-17 08:29:10 +01:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2019-09-21 02:27:42 +02:00
|
|
|
class OGLRenderbuffer : private NonCopyable {
|
|
|
|
public:
|
|
|
|
OGLRenderbuffer() = default;
|
|
|
|
|
|
|
|
OGLRenderbuffer(OGLRenderbuffer&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
|
|
|
|
|
|
|
~OGLRenderbuffer() {
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
OGLRenderbuffer& operator=(OGLRenderbuffer&& o) noexcept {
|
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
|
|
|
void Create();
|
|
|
|
|
|
|
|
/// Deletes the internal OpenGL resource
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
GLuint handle = 0;
|
|
|
|
};
|
|
|
|
|
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-03-11 18:22:33 +01:00
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLTexture(OGLTexture&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLTexture() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLTexture& operator=(OGLTexture&& o) noexcept {
|
2018-03-11 18:22:33 +01: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
|
|
|
|
2022-08-21 21:45:08 +02:00
|
|
|
void Allocate(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width,
|
|
|
|
GLsizei height = 1, GLsizei depth = 1);
|
2022-08-21 12:32:02 +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-03-11 18:22:33 +01:00
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLSampler(OGLSampler&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLSampler() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLSampler& operator=(OGLSampler&& o) noexcept {
|
2018-03-11 18:22:33 +01: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-03-11 18:22:33 +01:00
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLShader(OGLShader&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLShader() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLShader& operator=(OGLShader&& o) noexcept {
|
2018-03-11 18:22:33 +01: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
|
|
|
|
2023-04-21 09:14:55 +02:00
|
|
|
void Create(std::string_view source, GLenum type);
|
2018-04-09 23:26:09 +02:00
|
|
|
|
2018-11-06 10:40:49 +01:00
|
|
|
void Release();
|
2018-04-09 23:26:09 +02:00
|
|
|
|
|
|
|
GLuint handle = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OGLProgram : private NonCopyable {
|
|
|
|
public:
|
|
|
|
OGLProgram() = default;
|
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLProgram(OGLProgram&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-04-09 23:26:09 +02:00
|
|
|
|
|
|
|
~OGLProgram() {
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2020-04-19 03:12:00 +02:00
|
|
|
OGLProgram& operator=(OGLProgram&& o) noexcept {
|
2018-04-09 23:26:09 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange(o.handle, 0);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new program from given shader objects
|
2023-07-07 00:52:40 +02:00
|
|
|
void Create(bool separable_program, std::span<const GLuint> shaders);
|
2018-04-09 23:26:09 +02:00
|
|
|
|
|
|
|
/// Creates a new program from given shader soruce code
|
2023-04-21 09:14:55 +02:00
|
|
|
void Create(std::string_view vert_shader, std::string_view frag_shader);
|
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-04-09 23:29:52 +02:00
|
|
|
class OGLPipeline : private NonCopyable {
|
|
|
|
public:
|
|
|
|
OGLPipeline() = default;
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLPipeline(OGLPipeline&& o) noexcept {
|
2018-04-09 23:29:52 +02:00
|
|
|
handle = std::exchange<GLuint>(o.handle, 0);
|
|
|
|
}
|
|
|
|
~OGLPipeline() {
|
|
|
|
Release();
|
|
|
|
}
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLPipeline& operator=(OGLPipeline&& o) noexcept {
|
2018-04-09 23:29:52 +02:00
|
|
|
Release();
|
|
|
|
handle = std::exchange<GLuint>(o.handle, 0);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-11-06 10:40:49 +01:00
|
|
|
/// Creates a new internal OpenGL resource and stores the handle
|
|
|
|
void Create();
|
2018-04-09 23:29:52 +02:00
|
|
|
|
2018-11-06 10:40:49 +01:00
|
|
|
/// Deletes the internal OpenGL resource
|
|
|
|
void Release();
|
2018-04-09 23:29:52 +02:00
|
|
|
|
|
|
|
GLuint handle = 0;
|
|
|
|
};
|
|
|
|
|
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-03-11 18:22:33 +01:00
|
|
|
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLBuffer(OGLBuffer&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLBuffer() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLBuffer& operator=(OGLBuffer&& o) noexcept {
|
2018-03-11 18:22:33 +01: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 OGLVertexArray : private NonCopyable {
|
2015-05-19 06:21:33 +02:00
|
|
|
public:
|
2015-07-26 11:38:19 +02:00
|
|
|
OGLVertexArray() = default;
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLVertexArray(OGLVertexArray&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLVertexArray() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLVertexArray& operator=(OGLVertexArray&& o) noexcept {
|
2018-03-11 18:22:33 +01: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-03-11 18:22:33 +01:00
|
|
|
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLFramebuffer(OGLFramebuffer&& o) noexcept : handle(std::exchange(o.handle, 0)) {}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
~OGLFramebuffer() {
|
|
|
|
Release();
|
|
|
|
}
|
2018-03-11 18:22:33 +01:00
|
|
|
|
2020-06-23 18:00:25 +02:00
|
|
|
OGLFramebuffer& operator=(OGLFramebuffer&& o) noexcept {
|
2018-03-11 18:22:33 +01: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-11-17 08:29:10 +01:00
|
|
|
|
|
|
|
} // namespace OpenGL
|