citra-emu
/
citra
Archived
1
0
Fork 0

gl_rasterizer: add clipping plane z<=0 defined in PICA

This commit is contained in:
wwylele 2017-08-17 10:46:59 +03:00
parent 46d1ca768d
commit 1eca380886
4 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,9 @@ MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100)); MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) { RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) {
// Clipping plane 0 is always enabled for PICA fixed clip plane z <= 0
state.clip_distance[0] = true;
// Create sampler objects // Create sampler objects
for (size_t i = 0; i < texture_samplers.size(); ++i) { for (size_t i = 0; i < texture_samplers.size(); ++i) {
texture_samplers[i].Create(); texture_samplers[i].Create();

View File

@ -1196,6 +1196,8 @@ void main() {
normquat = vert_normquat; normquat = vert_normquat;
view = vert_view; view = vert_view;
gl_Position = vec4(vert_position.x, vert_position.y, -vert_position.z, vert_position.w); gl_Position = vec4(vert_position.x, vert_position.y, -vert_position.z, vert_position.w);
gl_ClipDistance[0] = -vert_position.z; // fixed PICA clipping plane z <= 0
// TODO (wwylele): calculate gl_ClipDistance[1] from user-defined clipping plane
} }
)"; )";

View File

@ -68,6 +68,8 @@ OpenGLState::OpenGLState() {
draw.vertex_buffer = 0; draw.vertex_buffer = 0;
draw.uniform_buffer = 0; draw.uniform_buffer = 0;
draw.shader_program = 0; draw.shader_program = 0;
clip_distance = {};
} }
void OpenGLState::Apply() const { void OpenGLState::Apply() const {
@ -261,6 +263,17 @@ void OpenGLState::Apply() const {
glUseProgram(draw.shader_program); glUseProgram(draw.shader_program);
} }
// Clip distance
for (size_t i = 0; i < clip_distance.size(); ++i) {
if (clip_distance[i] != cur_state.clip_distance[i]) {
if (clip_distance[i]) {
glEnable(GL_CLIP_DISTANCE0 + i);
} else {
glDisable(GL_CLIP_DISTANCE0 + i);
}
}
}
cur_state = *this; cur_state = *this;
} }

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <array>
#include <glad/glad.h> #include <glad/glad.h>
namespace TextureUnits { namespace TextureUnits {
@ -123,6 +124,8 @@ public:
GLuint shader_program; // GL_CURRENT_PROGRAM GLuint shader_program; // GL_CURRENT_PROGRAM
} draw; } draw;
std::array<bool, 2> clip_distance; // GL_CLIP_DISTANCE
OpenGLState(); OpenGLState();
/// Get the currently active OpenGL state /// Get the currently active OpenGL state