mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 14:19:55 -06:00
Merge branch 'master' into compute-shader-renderer
# Conflicts: # src/GPU.cpp # src/GPU.h # src/GPU2D_Soft.cpp # src/GPU3D.h # src/GPU3D_OpenGL.h # src/GPU_OpenGL.cpp # src/GPU_OpenGL.h # src/NDS.cpp # src/OpenGLSupport.cpp # src/frontend/qt_sdl/OSD.cpp # src/frontend/qt_sdl/main.cpp # src/frontend/qt_sdl/main.h
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2016-2022 melonDS team
|
||||
Copyright 2016-2023 melonDS team
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
@ -28,12 +28,12 @@
|
||||
#include "OpenGLSupport.h"
|
||||
#include "GPU_OpenGL_shaders.h"
|
||||
|
||||
namespace GPU
|
||||
namespace melonDS
|
||||
{
|
||||
|
||||
using namespace OpenGL;
|
||||
|
||||
std::unique_ptr<GLCompositor> GLCompositor::New() noexcept
|
||||
std::optional<GLCompositor> GLCompositor::New() noexcept
|
||||
{
|
||||
assert(glBindAttribLocation != nullptr);
|
||||
GLuint CompShader {};
|
||||
@ -43,9 +43,9 @@ std::unique_ptr<GLCompositor> GLCompositor::New() noexcept
|
||||
"CompositorShader",
|
||||
{{"vPosition", 0}, {"vTexcoord", 1}},
|
||||
{{"oColor", 0}}))
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
|
||||
return std::unique_ptr<GLCompositor>(new GLCompositor(CompShader));
|
||||
return { GLCompositor(CompShader) };
|
||||
}
|
||||
|
||||
GLCompositor::GLCompositor(GLuint compShader) noexcept : CompShader(compShader)
|
||||
@ -87,7 +87,7 @@ GLCompositor::GLCompositor(GLuint compShader) noexcept : CompShader(compShader)
|
||||
|
||||
glGenBuffers(1, &CompVertexBufferID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, CompVertexBufferID);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(CompVertices), CompVertices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(CompVertices), &CompVertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &CompVertexArrayID);
|
||||
glBindVertexArray(CompVertexArrayID);
|
||||
@ -96,7 +96,7 @@ GLCompositor::GLCompositor(GLuint compShader) noexcept : CompShader(compShader)
|
||||
glEnableVertexAttribArray(1); // texcoord
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(CompVertex), (void*)(offsetof(CompVertex, Texcoord)));
|
||||
|
||||
glGenFramebuffers(2, CompScreenOutputFB);
|
||||
glGenFramebuffers(CompScreenOutputFB.size(), &CompScreenOutputFB[0]);
|
||||
|
||||
glGenTextures(1, &CompScreenInputTex);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
@ -107,10 +107,10 @@ GLCompositor::GLCompositor(GLuint compShader) noexcept : CompShader(compShader)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 256*3 + 1, 192*2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
glGenTextures(2, CompScreenOutputTex);
|
||||
for (int i = 0; i < 2; i++)
|
||||
glGenTextures(CompScreenOutputTex.size(), &CompScreenOutputTex[0]);
|
||||
for (GLuint i : CompScreenOutputTex)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, CompScreenOutputTex[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, i);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
@ -124,9 +124,9 @@ GLCompositor::~GLCompositor()
|
||||
{
|
||||
assert(glDeleteFramebuffers != nullptr);
|
||||
|
||||
glDeleteFramebuffers(2, CompScreenOutputFB);
|
||||
glDeleteFramebuffers(CompScreenOutputFB.size(), &CompScreenOutputFB[0]);
|
||||
glDeleteTextures(1, &CompScreenInputTex);
|
||||
glDeleteTextures(2, CompScreenOutputTex);
|
||||
glDeleteTextures(CompScreenOutputTex.size(), &CompScreenOutputTex[0]);
|
||||
|
||||
glDeleteVertexArrays(1, &CompVertexArrayID);
|
||||
glDeleteBuffers(1, &CompVertexBufferID);
|
||||
@ -134,14 +134,75 @@ GLCompositor::~GLCompositor()
|
||||
glDeleteProgram(CompShader);
|
||||
}
|
||||
|
||||
void GLCompositor::Reset()
|
||||
|
||||
GLCompositor::GLCompositor(GLCompositor&& other) noexcept :
|
||||
Scale(other.Scale),
|
||||
ScreenH(other.ScreenH),
|
||||
ScreenW(other.ScreenW),
|
||||
CompScaleLoc(other.CompScaleLoc),
|
||||
Comp3DXPosLoc(other.Comp3DXPosLoc),
|
||||
CompVertices(other.CompVertices),
|
||||
CompShader(other.CompShader),
|
||||
CompVertexBufferID(other.CompVertexBufferID),
|
||||
CompVertexArrayID(other.CompVertexArrayID),
|
||||
CompScreenInputTex(other.CompScreenInputTex),
|
||||
CompScreenOutputTex(other.CompScreenOutputTex),
|
||||
CompScreenOutputFB(other.CompScreenOutputFB)
|
||||
{
|
||||
other.CompScreenOutputFB = {};
|
||||
other.CompScreenInputTex = {};
|
||||
other.CompScreenOutputTex = {};
|
||||
other.CompVertexArrayID = {};
|
||||
other.CompVertexBufferID = {};
|
||||
other.CompShader = {};
|
||||
}
|
||||
|
||||
GLCompositor& GLCompositor::operator=(GLCompositor&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
Scale = other.Scale;
|
||||
ScreenH = other.ScreenH;
|
||||
ScreenW = other.ScreenW;
|
||||
CompScaleLoc = other.CompScaleLoc;
|
||||
Comp3DXPosLoc = other.Comp3DXPosLoc;
|
||||
CompVertices = other.CompVertices;
|
||||
|
||||
// Clean up these resources before overwriting them
|
||||
OpenGL::DeleteShaderProgram(CompShader.data());
|
||||
CompShader = other.CompShader;
|
||||
|
||||
glDeleteBuffers(1, &CompVertexBufferID);
|
||||
CompVertexBufferID = other.CompVertexBufferID;
|
||||
|
||||
glDeleteVertexArrays(1, &CompVertexArrayID);
|
||||
CompVertexArrayID = other.CompVertexArrayID;
|
||||
|
||||
glDeleteTextures(1, &CompScreenInputTex);
|
||||
CompScreenInputTex = other.CompScreenInputTex;
|
||||
|
||||
glDeleteTextures(CompScreenOutputTex.size(), &CompScreenOutputTex[0]);
|
||||
CompScreenOutputTex = other.CompScreenOutputTex;
|
||||
|
||||
glDeleteFramebuffers(CompScreenOutputFB.size(), &CompScreenOutputFB[0]);
|
||||
CompScreenOutputFB = other.CompScreenOutputFB;
|
||||
|
||||
other.CompScreenOutputFB = {};
|
||||
other.CompScreenInputTex = {};
|
||||
other.CompScreenOutputTex = {};
|
||||
other.CompVertexArrayID = {};
|
||||
other.CompVertexBufferID = {};
|
||||
other.CompShader = {};
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void GLCompositor::SetRenderSettings(RenderSettings& settings)
|
||||
void GLCompositor::SetScaleFactor(int scale) noexcept
|
||||
{
|
||||
int scale = settings.GL_ScaleFactor;
|
||||
if (scale == Scale)
|
||||
return;
|
||||
|
||||
Scale = scale;
|
||||
ScreenW = 256 * scale;
|
||||
@ -165,13 +226,12 @@ void GLCompositor::SetRenderSettings(RenderSettings& settings)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void GLCompositor::Stop()
|
||||
void GLCompositor::Stop(const GPU& gpu) noexcept
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
int frontbuf = GPU::FrontBuffer;
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB[frontbuf]);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB[gpu.FrontBuffer]);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
@ -179,9 +239,9 @@ void GLCompositor::Stop()
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void GLCompositor::RenderFrame()
|
||||
void GLCompositor::RenderFrame(const GPU& gpu, GLRenderer& renderer) noexcept
|
||||
{
|
||||
int backbuf = GPU::FrontBuffer ^ 1;
|
||||
int backbuf = gpu.FrontBuffer ^ 1;
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB[backbuf]);
|
||||
|
||||
@ -199,21 +259,21 @@ void GLCompositor::RenderFrame()
|
||||
glUniform1ui(CompScaleLoc, Scale);
|
||||
|
||||
// TODO: support setting this midframe, if ever needed
|
||||
glUniform1i(Comp3DXPosLoc, ((int)GPU3D::RenderXPos << 23) >> 23);
|
||||
glUniform1i(Comp3DXPosLoc, ((int)gpu.GPU3D.GetRenderXPos() << 23) >> 23);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, CompScreenInputTex);
|
||||
|
||||
if (GPU::Framebuffer[backbuf][0] && GPU::Framebuffer[backbuf][1])
|
||||
if (gpu.Framebuffer[backbuf][0] && gpu.Framebuffer[backbuf][1])
|
||||
{
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[backbuf][0]);
|
||||
GL_UNSIGNED_BYTE, gpu.Framebuffer[backbuf][0].get());
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[backbuf][1]);
|
||||
GL_UNSIGNED_BYTE, gpu.Framebuffer[backbuf][1].get());
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
GPU3D::CurrentRenderer->SetupAccelFrame();
|
||||
renderer.SetupAccelFrame();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, CompVertexBufferID);
|
||||
glBindVertexArray(CompVertexArrayID);
|
||||
|
Reference in New Issue
Block a user