1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Merge pull request #1292 from vlj/gl

gl: Use factored scale offset function call
This commit is contained in:
Ivan 2015-11-16 01:44:25 +03:00
commit 60dc4abc2b
6 changed files with 25 additions and 35 deletions

View File

@ -1063,6 +1063,9 @@ void GLGSRender::oninit_thread()
m_vao.create();
m_vbo.create();
m_ebo.create();
m_scale_offset_buffer.create(16 * sizeof(float));
glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_scale_offset_buffer.id());
m_vao.array_buffer = m_vbo;
m_vao.element_array_buffer = m_ebo;
@ -1259,37 +1262,12 @@ bool GLGSRender::load_program()
(m_program.recreate() += { fp.compile(), vp.compile() }).make();
#endif
glBindBuffer(GL_UNIFORM_BUFFER, m_scale_offset_buffer.id());
int viewport_x = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] & 0xffff);
int viewport_y = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] & 0xffff);
int viewport_w = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] >> 16);
int viewport_h = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] >> 16);
void *buffer = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
fill_scale_offset_data(buffer, false);
glUnmapBuffer(GL_UNIFORM_BUFFER);
f32 viewport_offset_x = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 0];
f32 viewport_offset_y = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 1];
f32 viewport_offset_z = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 2];
f32 viewport_offset_w = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 3];
f32 viewport_scale_x = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 0];
f32 viewport_scale_y = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 1];
f32 viewport_scale_z = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 2];
f32 viewport_scale_w = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 3];
f32 width = f32(rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16);
f32 height = f32(rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16);
glm::mat4 scaleOffsetMat(1.f);
//Scale
scaleOffsetMat[0][0] = viewport_scale_x * 2.f / width;
scaleOffsetMat[1][1] = viewport_scale_y * 2.f / height;
scaleOffsetMat[2][2] = viewport_scale_z;
// Offset
scaleOffsetMat[0][3] = viewport_offset_x * 2.f / width - 1.f;
scaleOffsetMat[1][3] = viewport_offset_y * 2.f / height - 1.f;
scaleOffsetMat[2][3] = viewport_offset_z - .5f;
__glcheck m_program->uniforms["scaleOffsetMat"] = scaleOffsetMat;
for (auto &constant : transform_constants)
{

View File

@ -75,6 +75,8 @@ private:
gl::fbo m_flip_fbo;
gl::texture m_flip_tex_color;
gl::buffer m_scale_offset_buffer;
gl::buffer m_vbo;
gl::buffer m_ebo;
gl::vao m_vao;

View File

@ -163,6 +163,9 @@ OPENGL_PROC(PFNGLGETINTEGER64VPROC, GetInteger64v);
OPENGL_PROC(PFNGLCHECKFRAMEBUFFERSTATUSPROC, CheckFramebufferStatus);
OPENGL_PROC(PFNGLBINDBUFFERBASEPROC, BindBufferBase);
//KHR_debug
OPENGL_PROC(PFNGLDEBUGMESSAGECONTROLARBPROC, DebugMessageControlARB);
OPENGL_PROC(PFNGLDEBUGMESSAGEINSERTARBPROC, DebugMessageInsertARB);

View File

@ -28,8 +28,11 @@ std::string GLVertexDecompilerThread::compareFunction(COMPARE f, const std::stri
void GLVertexDecompilerThread::insertHeader(std::stringstream &OS)
{
OS << "#version 140" << std::endl << std::endl;
OS << "uniform mat4 scaleOffsetMat = mat4(1.0);" << std::endl;
OS << "#version 420" << std::endl << std::endl;
OS << "layout(std140, binding = 0) uniform ScaleOffsetBuffer" << std::endl;
OS << "{" << std::endl;
OS << " mat4 scaleOffsetMat;" << std::endl;
OS << "};" << std::endl;
}
void GLVertexDecompilerThread::insertInputs(std::stringstream & OS, const std::vector<ParamType>& inputs)

View File

@ -1100,7 +1100,7 @@ namespace rsx
onexit_thread();
}
void thread::fill_scale_offset_data(void *buffer) const noexcept
void thread::fill_scale_offset_data(void *buffer, bool is_d3d) const noexcept
{
int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16;
int clip_h = rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16;
@ -1109,12 +1109,15 @@ namespace rsx
float offset_x = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET] - (clip_w / 2.f);
offset_x /= clip_w / 2.f;
float scale_y = -(float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 1] / (clip_h / 2.f);
float offset_y = -((float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 1] - (clip_h / 2.f));
float scale_y = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 1] / (clip_h / 2.f);
float offset_y = ((float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 1] - (clip_h / 2.f));
offset_y /= clip_h / 2.f;
if (is_d3d) scale_y *= -1;
if (is_d3d) offset_y *= -1;
float scale_z = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 2];
float offset_z = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 2];
if (!is_d3d) offset_z -= .5;
float one = 1.f;

View File

@ -256,8 +256,9 @@ namespace rsx
/**
* Fill buffer with 4x4 scale offset matrix.
* Vertex shader's position is to be multiplied by this matrix.
* if is_d3d is set, the matrix is modified to use d3d convention.
*/
void fill_scale_offset_data(void *buffer) const noexcept;
void fill_scale_offset_data(void *buffer, bool is_d3d = true) const noexcept;
/**
* Fill buffer with vertex program constants.