Skip to content

Commit

Permalink
Rendering loop rewrite (#339)
Browse files Browse the repository at this point in the history
* PlatformCore: Remove erroneus OpenGL call

* PlatformCore: Add GBA screen size constants

* PlatformCore: Switch to drawing a triangle strip

Vertices' origin at the bottom left, CCW order.

* PlatformCore: Cleanup types

* PlatformCore: Extract setting texture parameters

Also set texture wrapping parameters to eliminate artifacts on the edges
of the output image when using linear sampling.

* PlatformCore: Extract setting shader uniforms

* PlatformCore: Add output size shader uniform

And use it in xBRZ shader.

* PlatformCore: Rename u_screen_map into u_input_map

* PlatformCore: Add flipped UV generic vertex shader

* PlatformCore: Adjust setting viewport

* PlatformCore: Upload texture data via glTexSubImage

* PlatformCore: Rewrite rendering loop

Introduce ShaderPass object, which holds shader program and input/output
texture indices.
  • Loading branch information
GranMinigun authored Dec 2, 2023
1 parent f94692a commit 570c333
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 154 deletions.
23 changes: 19 additions & 4 deletions src/platform/core/include/platform/device/ogl_video_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <array>
#include <nba/device/video_device.hpp>
#include <GL/glew.h>
#include <platform/config.hpp>
Expand All @@ -27,7 +28,9 @@ struct OGLVideoDevice : VideoDevice {
void ReloadConfig();

private:
void UpdateTextures();
void CreateShaderPrograms();
void UpdateShaderUniforms();
void ReleaseShaderPrograms();

auto CompileShader(
Expand All @@ -40,6 +43,19 @@ struct OGLVideoDevice : VideoDevice {
char const* fragment_src
) -> std::pair<bool, GLuint>;

static constexpr size_t input_index = 0;
static constexpr size_t output_index = 1;
static constexpr size_t history_index = 2;
static constexpr size_t xbrz_output_index = 3;

struct ShaderPass {
GLuint program = 0;
struct {
std::vector<GLuint> inputs = {input_index};
GLuint output = output_index;
} textures = {};
};

int view_x = 0;
int view_y = 0;
int view_width = 1;
Expand All @@ -49,10 +65,9 @@ struct OGLVideoDevice : VideoDevice {
GLuint quad_vao;
GLuint quad_vbo;
GLuint fbo;
GLuint texture[4];
std::vector<GLuint> programs;
GLenum texture_filter = GL_NEAREST;
bool texture_filter_invalid = false;
std::array<GLuint, 4> textures = {};
std::vector<ShaderPass> shader_passes = {};
GLint texture_filter = GL_NEAREST;

std::shared_ptr<PlatformConfig> config;
};
Expand Down
Loading

0 comments on commit 570c333

Please sign in to comment.