mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
implement a ping-pong framebuffer
This commit is contained in:
13
data/shaders/copyframebuffer.frag
Normal file
13
data/shaders/copyframebuffer.frag
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
uniform sampler2D uTexture;
|
||||||
|
|
||||||
|
in vec2 fPosition;
|
||||||
|
in vec2 fTextureCoordinate;
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 oColour;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
oColour = texture(uTexture, fTextureCoordinate);
|
||||||
|
}
|
||||||
42
data/shaders/copyframebuffer.vert
Normal file
42
data/shaders/copyframebuffer.vert
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
uniform ivec2 uScreenSize;
|
||||||
|
uniform ivec4 uBounds;
|
||||||
|
uniform ivec4 uTextureCoordinates;
|
||||||
|
|
||||||
|
in int vIndex;
|
||||||
|
|
||||||
|
out vec2 fPosition;
|
||||||
|
out vec2 fTextureCoordinate;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 pos;
|
||||||
|
switch (vIndex) {
|
||||||
|
case 0:
|
||||||
|
pos = uBounds.xy;
|
||||||
|
fTextureCoordinate = uTextureCoordinates.xy;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
pos = uBounds.zy;
|
||||||
|
fTextureCoordinate = uTextureCoordinates.zy;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
pos = uBounds.zw;
|
||||||
|
fTextureCoordinate = uTextureCoordinates.zw;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
pos = uBounds.xw;
|
||||||
|
fTextureCoordinate = uTextureCoordinates.xw;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fPosition = pos;
|
||||||
|
|
||||||
|
// Transform screen coordinates to viewport
|
||||||
|
pos.x = (pos.x * (2.0 / uScreenSize.x)) - 1.0;
|
||||||
|
pos.y = (pos.y * (2.0 / uScreenSize.y)) - 1.0;
|
||||||
|
pos.y *= -1;
|
||||||
|
|
||||||
|
gl_Position = vec4(pos, 0.0, 1.0);
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="curl-ca-bundle.crt" />
|
<None Include="curl-ca-bundle.crt" />
|
||||||
|
<None Include="data\shaders\copyframebuffer.frag" />
|
||||||
|
<None Include="data\shaders\copyframebuffer.vert" />
|
||||||
<None Include="data\shaders\drawimage.frag" />
|
<None Include="data\shaders\drawimage.frag" />
|
||||||
<None Include="data\shaders\drawimage.vert" />
|
<None Include="data\shaders\drawimage.vert" />
|
||||||
<None Include="data\shaders\drawimagemasked.frag" />
|
<None Include="data\shaders\drawimagemasked.frag" />
|
||||||
@@ -48,6 +50,7 @@
|
|||||||
<ClCompile Include="src\diagnostic.c" />
|
<ClCompile Include="src\diagnostic.c" />
|
||||||
<ClCompile Include="src\drawing\drawing.c" />
|
<ClCompile Include="src\drawing\drawing.c" />
|
||||||
<ClCompile Include="src\drawing\drawing_fast.cpp" />
|
<ClCompile Include="src\drawing\drawing_fast.cpp" />
|
||||||
|
<ClCompile Include="src\drawing\engines\opengl\CopyFramebufferShader.cpp" />
|
||||||
<ClCompile Include="src\drawing\engines\opengl\DrawImageMaskedShader.cpp" />
|
<ClCompile Include="src\drawing\engines\opengl\DrawImageMaskedShader.cpp" />
|
||||||
<ClCompile Include="src\drawing\engines\opengl\DrawImageShader.cpp" />
|
<ClCompile Include="src\drawing\engines\opengl\DrawImageShader.cpp" />
|
||||||
<ClCompile Include="src\drawing\engines\opengl\FillRectShader.cpp" />
|
<ClCompile Include="src\drawing\engines\opengl\FillRectShader.cpp" />
|
||||||
@@ -55,6 +58,7 @@
|
|||||||
<ClCompile Include="src\drawing\engines\opengl\OpenGLDrawingEngine.cpp" />
|
<ClCompile Include="src\drawing\engines\opengl\OpenGLDrawingEngine.cpp" />
|
||||||
<ClCompile Include="src\drawing\engines\opengl\OpenGLFramebuffer.cpp" />
|
<ClCompile Include="src\drawing\engines\opengl\OpenGLFramebuffer.cpp" />
|
||||||
<ClCompile Include="src\drawing\engines\opengl\OpenGLShaderProgram.cpp" />
|
<ClCompile Include="src\drawing\engines\opengl\OpenGLShaderProgram.cpp" />
|
||||||
|
<ClCompile Include="src\drawing\engines\opengl\SwapFramebuffer.cpp" />
|
||||||
<ClCompile Include="src\drawing\engines\SoftwareDrawingEngine.cpp" />
|
<ClCompile Include="src\drawing\engines\SoftwareDrawingEngine.cpp" />
|
||||||
<ClCompile Include="src\drawing\font.c" />
|
<ClCompile Include="src\drawing\font.c" />
|
||||||
<ClCompile Include="src\drawing\line.c" />
|
<ClCompile Include="src\drawing\line.c" />
|
||||||
@@ -349,6 +353,7 @@
|
|||||||
<ClInclude Include="src\diagnostic.h" />
|
<ClInclude Include="src\diagnostic.h" />
|
||||||
<ClInclude Include="src\drawing\drawing.h" />
|
<ClInclude Include="src\drawing\drawing.h" />
|
||||||
<ClInclude Include="src\drawing\engines\OpenGLAPI.h" />
|
<ClInclude Include="src\drawing\engines\OpenGLAPI.h" />
|
||||||
|
<ClInclude Include="src\drawing\engines\opengl\CopyFramebufferShader.h" />
|
||||||
<ClInclude Include="src\drawing\engines\opengl\DrawImageMaskedShader.h" />
|
<ClInclude Include="src\drawing\engines\opengl\DrawImageMaskedShader.h" />
|
||||||
<ClInclude Include="src\drawing\engines\opengl\DrawImageShader.h" />
|
<ClInclude Include="src\drawing\engines\opengl\DrawImageShader.h" />
|
||||||
<ClInclude Include="src\drawing\engines\opengl\FillRectShader.h" />
|
<ClInclude Include="src\drawing\engines\opengl\FillRectShader.h" />
|
||||||
@@ -356,6 +361,7 @@
|
|||||||
<ClInclude Include="src\drawing\engines\opengl\OpenGLAPI.h" />
|
<ClInclude Include="src\drawing\engines\opengl\OpenGLAPI.h" />
|
||||||
<ClInclude Include="src\drawing\engines\opengl\OpenGLFramebuffer.h" />
|
<ClInclude Include="src\drawing\engines\opengl\OpenGLFramebuffer.h" />
|
||||||
<ClInclude Include="src\drawing\engines\opengl\OpenGLShaderProgram.h" />
|
<ClInclude Include="src\drawing\engines\opengl\OpenGLShaderProgram.h" />
|
||||||
|
<ClInclude Include="src\drawing\engines\opengl\SwapFramebuffer.h" />
|
||||||
<ClInclude Include="src\drawing\font.h" />
|
<ClInclude Include="src\drawing\font.h" />
|
||||||
<ClInclude Include="src\drawing\IDrawingContext.h" />
|
<ClInclude Include="src\drawing\IDrawingContext.h" />
|
||||||
<ClInclude Include="src\drawing\IDrawingEngine.h" />
|
<ClInclude Include="src\drawing\IDrawingEngine.h" />
|
||||||
|
|||||||
86
src/drawing/engines/opengl/CopyFramebufferShader.cpp
Normal file
86
src/drawing/engines/opengl/CopyFramebufferShader.cpp
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||||
|
/*****************************************************************************
|
||||||
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||||
|
*
|
||||||
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||||
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* A full copy of the GNU General Public License can be found in licence.txt
|
||||||
|
*****************************************************************************/
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#ifndef DISABLE_OPENGL
|
||||||
|
|
||||||
|
#include "CopyFramebufferShader.h"
|
||||||
|
|
||||||
|
CopyFramebufferShader::CopyFramebufferShader() : OpenGLShaderProgram("copyframebuffer")
|
||||||
|
{
|
||||||
|
GetLocations();
|
||||||
|
|
||||||
|
glGenBuffers(1, &_vbo);
|
||||||
|
glGenVertexArrays(1, &_vao);
|
||||||
|
|
||||||
|
vec2i vertices[] = { 0, 1, 2, 3 };
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glBindVertexArray(_vao);
|
||||||
|
glEnableVertexAttribArray(vIndex);
|
||||||
|
glVertexAttribIPointer(vIndex, 1, GL_INT, 0, nullptr);
|
||||||
|
|
||||||
|
Use();
|
||||||
|
SetTextureCoordinates(0, 0, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyFramebufferShader::~CopyFramebufferShader()
|
||||||
|
{
|
||||||
|
glDeleteBuffers(1, &_vbo);
|
||||||
|
glDeleteVertexArrays(1, &_vao);
|
||||||
|
|
||||||
|
glBindVertexArray(_vao);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyFramebufferShader::GetLocations()
|
||||||
|
{
|
||||||
|
uScreenSize = GetUniformLocation("uScreenSize");
|
||||||
|
uBounds = GetUniformLocation("uBounds");
|
||||||
|
uTextureCoordinates = GetUniformLocation("uTextureCoordinates");
|
||||||
|
uTexture = GetUniformLocation("uTexture");
|
||||||
|
|
||||||
|
vIndex = GetAttributeLocation("vIndex");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyFramebufferShader::SetScreenSize(sint32 width, sint32 height)
|
||||||
|
{
|
||||||
|
glUniform2i(uScreenSize, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyFramebufferShader::SetBounds(sint32 left, sint32 top, sint32 right, sint32 bottom)
|
||||||
|
{
|
||||||
|
glUniform4i(uBounds, left, top, right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyFramebufferShader::SetTextureCoordinates(sint32 left, sint32 top, sint32 right, sint32 bottom)
|
||||||
|
{
|
||||||
|
glUniform4i(uTextureCoordinates, left, top, right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyFramebufferShader::SetTexture(GLuint texture)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
glUniform1i(uTexture, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyFramebufferShader::Draw()
|
||||||
|
{
|
||||||
|
glBindVertexArray(_vao);
|
||||||
|
glDrawArrays(GL_QUADS, 0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DISABLE_OPENGL */
|
||||||
48
src/drawing/engines/opengl/CopyFramebufferShader.h
Normal file
48
src/drawing/engines/opengl/CopyFramebufferShader.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||||
|
/*****************************************************************************
|
||||||
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||||
|
*
|
||||||
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||||
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* A full copy of the GNU General Public License can be found in licence.txt
|
||||||
|
*****************************************************************************/
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GLSLTypes.h"
|
||||||
|
#include "OpenGLShaderProgram.h"
|
||||||
|
|
||||||
|
class CopyFramebufferShader : public OpenGLShaderProgram
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
GLuint uScreenSize;
|
||||||
|
GLuint uBounds;
|
||||||
|
GLuint uTextureCoordinates;
|
||||||
|
GLuint uTexture;
|
||||||
|
|
||||||
|
GLuint vIndex;
|
||||||
|
|
||||||
|
GLuint _vbo;
|
||||||
|
GLuint _vao;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CopyFramebufferShader();
|
||||||
|
~CopyFramebufferShader() override;
|
||||||
|
|
||||||
|
void SetScreenSize(sint32 width, sint32 height);
|
||||||
|
void SetBounds(sint32 left, sint32 top, sint32 right, sint32 bottom);
|
||||||
|
void SetTextureCoordinates(sint32 left, sint32 top, sint32 right, sint32 bottom);
|
||||||
|
void SetTexture(GLuint texture);
|
||||||
|
|
||||||
|
void Draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void GetLocations();
|
||||||
|
};
|
||||||
@@ -27,7 +27,7 @@ DrawImageMaskedShader::DrawImageMaskedShader() : OpenGLShaderProgram("drawimagem
|
|||||||
|
|
||||||
vec2i vertices[] = { 0, 1, 2, 3 };
|
vec2i vertices[] = { 0, 1, 2, 3 };
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
glBindVertexArray(_vao);
|
glBindVertexArray(_vao);
|
||||||
glEnableVertexAttribArray(vIndex);
|
glEnableVertexAttribArray(vIndex);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ DrawImageShader::DrawImageShader() : OpenGLShaderProgram("drawimage")
|
|||||||
|
|
||||||
vec2i vertices[] = { 0, 1, 2, 3 };
|
vec2i vertices[] = { 0, 1, 2, 3 };
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
glBindVertexArray(_vao);
|
glBindVertexArray(_vao);
|
||||||
glEnableVertexAttribArray(vIndex);
|
glEnableVertexAttribArray(vIndex);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ FillRectShader::FillRectShader() : OpenGLShaderProgram("fillrect")
|
|||||||
|
|
||||||
vec2i vertices[] = { 0, 1, 2, 3 };
|
vec2i vertices[] = { 0, 1, 2, 3 };
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
glBindVertexArray(_vao);
|
glBindVertexArray(_vao);
|
||||||
glEnableVertexAttribArray(vIndex);
|
glEnableVertexAttribArray(vIndex);
|
||||||
|
|||||||
@@ -32,9 +32,11 @@ IDrawingEngine * DrawingEngineFactory::CreateOpenGL()
|
|||||||
#include "GLSLTypes.h"
|
#include "GLSLTypes.h"
|
||||||
#include "OpenGLAPI.h"
|
#include "OpenGLAPI.h"
|
||||||
#include "OpenGLFramebuffer.h"
|
#include "OpenGLFramebuffer.h"
|
||||||
|
#include "CopyFramebufferShader.h"
|
||||||
#include "DrawImageShader.h"
|
#include "DrawImageShader.h"
|
||||||
#include "DrawImageMaskedShader.h"
|
#include "DrawImageMaskedShader.h"
|
||||||
#include "FillRectShader.h"
|
#include "FillRectShader.h"
|
||||||
|
#include "SwapFramebuffer.h"
|
||||||
|
|
||||||
#include "../../../core/Console.hpp"
|
#include "../../../core/Console.hpp"
|
||||||
#include "../../../core/Exception.hpp"
|
#include "../../../core/Exception.hpp"
|
||||||
@@ -221,9 +223,9 @@ private:
|
|||||||
|
|
||||||
OpenGLDrawingContext * _drawingContext;
|
OpenGLDrawingContext * _drawingContext;
|
||||||
|
|
||||||
DrawImageShader * _drawImageShader = nullptr;
|
CopyFramebufferShader * _copyFramebufferShader = nullptr;
|
||||||
OpenGLFramebuffer * _screenFramebuffer = nullptr;
|
OpenGLFramebuffer * _screenFramebuffer = nullptr;
|
||||||
OpenGLFramebuffer * _canvasFramebuffer = nullptr;
|
SwapFramebuffer * _swapFramebuffer = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SDL_Color Palette[256];
|
SDL_Color Palette[256];
|
||||||
@@ -236,7 +238,7 @@ public:
|
|||||||
|
|
||||||
~OpenGLDrawingEngine() override
|
~OpenGLDrawingEngine() override
|
||||||
{
|
{
|
||||||
delete _drawImageShader;
|
delete _copyFramebufferShader;
|
||||||
|
|
||||||
delete _drawingContext;
|
delete _drawingContext;
|
||||||
delete [] _bits;
|
delete [] _bits;
|
||||||
@@ -265,7 +267,7 @@ public:
|
|||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_FRONT);
|
glCullFace(GL_FRONT);
|
||||||
|
|
||||||
_drawImageShader = new DrawImageShader();
|
_copyFramebufferShader = new CopyFramebufferShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resize(uint32 width, uint32 height) override
|
void Resize(uint32 width, uint32 height) override
|
||||||
@@ -296,9 +298,9 @@ public:
|
|||||||
void Draw() override
|
void Draw() override
|
||||||
{
|
{
|
||||||
assert(_screenFramebuffer != nullptr);
|
assert(_screenFramebuffer != nullptr);
|
||||||
assert(_canvasFramebuffer != nullptr);
|
assert(_swapFramebuffer != nullptr);
|
||||||
|
|
||||||
_canvasFramebuffer->Bind();
|
_swapFramebuffer->Bind();
|
||||||
|
|
||||||
if (gIntroState != INTRO_STATE_NONE) {
|
if (gIntroState != INTRO_STATE_NONE) {
|
||||||
intro_draw(&_bitsDPI);
|
intro_draw(&_bitsDPI);
|
||||||
@@ -308,6 +310,8 @@ public:
|
|||||||
window_update_all();
|
window_update_all();
|
||||||
|
|
||||||
gfx_draw_pickedup_peep(&_bitsDPI);
|
gfx_draw_pickedup_peep(&_bitsDPI);
|
||||||
|
|
||||||
|
_swapFramebuffer->SwapCopy();
|
||||||
|
|
||||||
rct2_draw(&_bitsDPI);
|
rct2_draw(&_bitsDPI);
|
||||||
}
|
}
|
||||||
@@ -317,20 +321,20 @@ public:
|
|||||||
|
|
||||||
sint32 width = _screenFramebuffer->GetWidth();
|
sint32 width = _screenFramebuffer->GetWidth();
|
||||||
sint32 height = _screenFramebuffer->GetHeight();
|
sint32 height = _screenFramebuffer->GetHeight();
|
||||||
_drawImageShader->Use();
|
_copyFramebufferShader->Use();
|
||||||
_drawImageShader->SetScreenSize(width, height);
|
_copyFramebufferShader->SetTexture(_swapFramebuffer->GetTargetFramebuffer()
|
||||||
_drawImageShader->SetClip(0, 0, width, height);
|
->GetTexture());
|
||||||
_drawImageShader->SetTexture(_canvasFramebuffer->GetTexture());
|
_copyFramebufferShader->Draw();
|
||||||
_drawImageShader->SetTextureCoordinates(0, 1, 1, 0);
|
|
||||||
_drawImageShader->Draw(0, 0, width, height);
|
|
||||||
|
|
||||||
Display();
|
Display();
|
||||||
}
|
}
|
||||||
|
|
||||||
sint32 Screenshot() override
|
sint32 Screenshot() override
|
||||||
{
|
{
|
||||||
_canvasFramebuffer->Bind();
|
const OpenGLFramebuffer * framebuffer = _swapFramebuffer->GetTargetFramebuffer();
|
||||||
void * pixels = _canvasFramebuffer->GetPixels();
|
framebuffer->Bind();
|
||||||
|
void * pixels = framebuffer->GetPixels();
|
||||||
|
|
||||||
int result = screenshot_dump_png_32bpp(_width, _height, pixels);
|
int result = screenshot_dump_png_32bpp(_width, _height, pixels);
|
||||||
Memory::Free(pixels);
|
Memory::Free(pixels);
|
||||||
return result;
|
return result;
|
||||||
@@ -425,13 +429,13 @@ private:
|
|||||||
_screenFramebuffer = new OpenGLFramebuffer(_window);
|
_screenFramebuffer = new OpenGLFramebuffer(_window);
|
||||||
|
|
||||||
// Re-create canvas framebuffer
|
// Re-create canvas framebuffer
|
||||||
delete _canvasFramebuffer;
|
delete _swapFramebuffer;
|
||||||
_canvasFramebuffer = new OpenGLFramebuffer(_width, _height);
|
_swapFramebuffer = new SwapFramebuffer(_width, _height);
|
||||||
|
|
||||||
_drawImageShader->Use();
|
_copyFramebufferShader->Use();
|
||||||
_drawImageShader->SetScreenSize(_width, _height);
|
_copyFramebufferShader->SetScreenSize(_width, _height);
|
||||||
_drawImageShader->SetClip(0, 0, _width, _height);
|
_copyFramebufferShader->SetBounds(0, 0, _width, _height);
|
||||||
_drawImageShader->SetTexture(_canvasFramebuffer->GetTexture());
|
_copyFramebufferShader->SetTextureCoordinates(0, 1, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display()
|
void Display()
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ OpenGLFramebuffer::~OpenGLFramebuffer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLFramebuffer::Bind()
|
void OpenGLFramebuffer::Bind() const
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, _id);
|
glBindFramebuffer(GL_FRAMEBUFFER, _id);
|
||||||
glViewport(0, 0, (GLsizei)_width, (GLsizei)_height);
|
glViewport(0, 0, (GLsizei)_width, (GLsizei)_height);
|
||||||
|
|||||||
@@ -38,6 +38,6 @@ public:
|
|||||||
GLuint GetHeight() const { return _height; }
|
GLuint GetHeight() const { return _height; }
|
||||||
GLuint GetTexture() const { return _texture; }
|
GLuint GetTexture() const { return _texture; }
|
||||||
|
|
||||||
void Bind();
|
void Bind() const;
|
||||||
void * GetPixels() const;
|
void * GetPixels() const;
|
||||||
};
|
};
|
||||||
|
|||||||
68
src/drawing/engines/opengl/SwapFramebuffer.cpp
Normal file
68
src/drawing/engines/opengl/SwapFramebuffer.cpp
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||||
|
/*****************************************************************************
|
||||||
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||||
|
*
|
||||||
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||||
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* A full copy of the GNU General Public License can be found in licence.txt
|
||||||
|
*****************************************************************************/
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#ifndef DISABLE_OPENGL
|
||||||
|
|
||||||
|
#include "CopyFramebufferShader.h"
|
||||||
|
#include "OpenGLFramebuffer.h"
|
||||||
|
#include "SwapFramebuffer.h"
|
||||||
|
|
||||||
|
SwapFramebuffer::SwapFramebuffer(sint32 width, sint32 height)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_targetFramebufferIndex = 0;
|
||||||
|
_framebuffer[0] = new OpenGLFramebuffer(width, height);
|
||||||
|
_framebuffer[1] = new OpenGLFramebuffer(width, height);
|
||||||
|
_targetFramebuffer = _framebuffer[0];
|
||||||
|
|
||||||
|
_copyFramebufferShader = new CopyFramebufferShader();
|
||||||
|
_copyFramebufferShader->Use();
|
||||||
|
_copyFramebufferShader->SetScreenSize(_width, _height);
|
||||||
|
_copyFramebufferShader->SetBounds(0, 0, _width, _height);
|
||||||
|
_copyFramebufferShader->SetTextureCoordinates(0, 1, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SwapFramebuffer::~SwapFramebuffer()
|
||||||
|
{
|
||||||
|
delete _framebuffer[0];
|
||||||
|
delete _framebuffer[1];
|
||||||
|
delete _copyFramebufferShader;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint SwapFramebuffer::GetSourceTexture() const
|
||||||
|
{
|
||||||
|
return _sourceFramebuffer->GetTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapFramebuffer::SwapCopy()
|
||||||
|
{
|
||||||
|
_sourceFramebuffer = _targetFramebuffer;
|
||||||
|
_targetFramebufferIndex = (_targetFramebufferIndex + 1) & 1;
|
||||||
|
_targetFramebuffer = _framebuffer[_targetFramebufferIndex];
|
||||||
|
_targetFramebuffer->Bind();
|
||||||
|
|
||||||
|
_copyFramebufferShader->Use();
|
||||||
|
_copyFramebufferShader->SetTexture(GetSourceTexture());
|
||||||
|
_copyFramebufferShader->Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapFramebuffer::Bind()
|
||||||
|
{
|
||||||
|
_targetFramebuffer->Bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DISABLE_OPENGL */
|
||||||
70
src/drawing/engines/opengl/SwapFramebuffer.h
Normal file
70
src/drawing/engines/opengl/SwapFramebuffer.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||||
|
/*****************************************************************************
|
||||||
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||||
|
*
|
||||||
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||||
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* A full copy of the GNU General Public License can be found in licence.txt
|
||||||
|
*****************************************************************************/
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../../common.h"
|
||||||
|
#include "OpenGLAPI.h"
|
||||||
|
|
||||||
|
class CopyFramebufferShader;
|
||||||
|
class OpenGLFramebuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to maintain two different framebuffers where the active framebuffer
|
||||||
|
* will swap between the two, copying the other's pixels in the process for
|
||||||
|
* performing pre-processing filters.
|
||||||
|
*
|
||||||
|
* When you need to bind the current frame to a shader, call SwapCopy and
|
||||||
|
* then bind the value of GetSourceTexture to your shader.
|
||||||
|
*/
|
||||||
|
class SwapFramebuffer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
sint32 _width;
|
||||||
|
sint32 _height;
|
||||||
|
uint8 _targetFramebufferIndex;
|
||||||
|
OpenGLFramebuffer * _targetFramebuffer;
|
||||||
|
OpenGLFramebuffer * _sourceFramebuffer;
|
||||||
|
OpenGLFramebuffer * _framebuffer[2];
|
||||||
|
|
||||||
|
CopyFramebufferShader * _copyFramebufferShader = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SwapFramebuffer(sint32 width, sint32 height);
|
||||||
|
~SwapFramebuffer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current target framebuffer.
|
||||||
|
*/
|
||||||
|
const OpenGLFramebuffer * GetTargetFramebuffer() const { return _targetFramebuffer; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the texture ID for the source framebuffer.
|
||||||
|
*/
|
||||||
|
GLuint GetSourceTexture() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps the target framebuffer, binds it and then draws the previous
|
||||||
|
* framebuffer resulting in the two buffers matching and ready for
|
||||||
|
* pre-processing.
|
||||||
|
*/
|
||||||
|
void SwapCopy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds the current target framebuffer.
|
||||||
|
*/
|
||||||
|
void Bind();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user