Skip to content

Commit

Permalink
Tons of bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Aug 7, 2019
1 parent 16ec8e5 commit 6b4e665
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 101 deletions.
5 changes: 3 additions & 2 deletions shaders/disable_color_buffer_f.cg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
float4 main()
float main(
uniform float depth_clear) : DEPTH
{
return 0.0f;
return depth_clear;
}
26 changes: 13 additions & 13 deletions source/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,21 @@ void glClear(GLbitfield mask){
if ((mask & GL_DEPTH_BUFFER_BIT) == GL_DEPTH_BUFFER_BIT){
invalidate_depth_test();
change_depth_write(SCE_GXM_DEPTH_WRITE_ENABLED);
depth_vertices[0].position.z = depth_value;
depth_vertices[1].position.z = depth_value;
depth_vertices[2].position.z = depth_value;
depth_vertices[3].position.z = depth_value;
sceGxmSetVertexProgram(gxm_context, disable_color_buffer_vertex_program_patched);
sceGxmSetVertexProgram(gxm_context, clear_vertex_program_patched);
sceGxmSetFragmentProgram(gxm_context, disable_color_buffer_fragment_program_patched);
sceGxmSetVertexStream(gxm_context, 0, depth_vertices);
sceGxmDraw(gxm_context, SCE_GXM_PRIMITIVE_TRIANGLE_STRIP, SCE_GXM_INDEX_FORMAT_U16, depth_clear_indices, 4);
void *depth_buffer;
sceGxmReserveFragmentDefaultUniformBuffer(gxm_context, &depth_buffer);
float temp = depth_value;
sceGxmSetUniformDataF(depth_buffer, clear_depth, 0, 1, &temp);
sceGxmSetVertexStream(gxm_context, 0, clear_vertices);
sceGxmDraw(gxm_context, SCE_GXM_PRIMITIVE_TRIANGLE_FAN, SCE_GXM_INDEX_FORMAT_U16, depth_clear_indices, 4);
validate_depth_test();
change_depth_write((depth_mask_state && orig_depth_test) ? SCE_GXM_DEPTH_WRITE_ENABLED : SCE_GXM_DEPTH_WRITE_DISABLED);
}
if ((mask & GL_STENCIL_BUFFER_BIT) == GL_STENCIL_BUFFER_BIT){
invalidate_depth_test();
change_depth_write(SCE_GXM_DEPTH_WRITE_DISABLED);
depth_vertices[0].position.z = 1.0f;
depth_vertices[1].position.z = 1.0f;
depth_vertices[2].position.z = 1.0f;
depth_vertices[3].position.z = 1.0f;
sceGxmSetVertexProgram(gxm_context, disable_color_buffer_vertex_program_patched);
sceGxmSetVertexProgram(gxm_context, clear_vertex_program_patched);
sceGxmSetFragmentProgram(gxm_context, disable_color_buffer_fragment_program_patched);
sceGxmSetFrontStencilFunc(gxm_context,
SCE_GXM_STENCIL_FUNC_NEVER,
Expand All @@ -334,8 +330,12 @@ void glClear(GLbitfield mask){
SCE_GXM_STENCIL_OP_REPLACE,
SCE_GXM_STENCIL_OP_REPLACE,
0, stencil_value * 0xFF);
void *depth_buffer;
sceGxmReserveFragmentDefaultUniformBuffer(gxm_context, &depth_buffer);
float temp = 1.0f;
sceGxmSetUniformDataF(depth_buffer, clear_depth, 0, 1, &temp);
sceGxmSetVertexStream(gxm_context, 0, clear_vertices);
sceGxmDraw(gxm_context, SCE_GXM_PRIMITIVE_TRIANGLE_STRIP, SCE_GXM_INDEX_FORMAT_U16, depth_clear_indices, 4);
sceGxmDraw(gxm_context, SCE_GXM_PRIMITIVE_TRIANGLE_FAN, SCE_GXM_INDEX_FORMAT_U16, depth_clear_indices, 4);
validate_depth_test();
change_depth_write((depth_mask_state && orig_depth_test) ? SCE_GXM_DEPTH_WRITE_ENABLED : SCE_GXM_DEPTH_WRITE_DISABLED);
change_stencil_settings();
Expand Down
7 changes: 2 additions & 5 deletions source/shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
#define _SHADERS_H_

// Disable color buffer shader
SceGxmShaderPatcherId disable_color_buffer_vertex_id;
SceGxmShaderPatcherId disable_color_buffer_fragment_id;
const SceGxmProgramParameter *disable_color_buffer_position;
const SceGxmProgramParameter *disable_color_buffer_matrix;
SceGxmVertexProgram *disable_color_buffer_vertex_program_patched;
SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched;
position_vertex *depth_vertices;
const SceGxmProgramParameter *clear_depth;

// Clear shader
SceGxmShaderPatcherId clear_vertex_id;
SceGxmShaderPatcherId clear_fragment_id;
const SceGxmProgramParameter *clear_position;
const SceGxmProgramParameter *clear_color;
SceGxmVertexProgram *clear_vertex_program_patched; // Patched vertex program for clearing screen
SceGxmVertexProgram *clear_vertex_program_patched;
SceGxmFragmentProgram *clear_fragment_program_patched;

// Color (RGBA/RGB) shader
Expand Down
31 changes: 18 additions & 13 deletions source/shaders/disable_color_buffer_f.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#ifndef __disable_color_buffer_f__
#define __disable_color_buffer_f__

static unsigned int size_disable_color_buffer_f = 192;
static unsigned int size_disable_color_buffer_f = 272;
static unsigned char disable_color_buffer_f[] __attribute__((aligned(16))) = {
0x47, 0x58, 0x50, 0x00, 0x01, 0x04, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xe8, 0xe7, 0xae, 0x19,
0xc4, 0x02, 0x2e, 0xd4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x44, 0xfa, 0x00, 0x00, 0x00, 0x45, 0x02, 0x04, 0x82, 0x38,
0x47, 0x58, 0x50, 0x00, 0x01, 0x04, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0xf4, 0x51, 0x72, 0xac,
0x53, 0xb5, 0x21, 0x1b, 0x15, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00,
0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x44, 0xfa, 0x00, 0x00, 0x00, 0xe0,
0x08, 0x00, 0x81, 0x50, 0x02, 0x01, 0x00, 0xf0, 0x00, 0x00, 0x30, 0xfb, 0x00, 0x00, 0x00, 0x00,
0x40, 0x01, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x44, 0xfa, 0x00, 0x00, 0x00, 0x00,
0x00, 0xe0, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x13, 0x00, 0x00, 0x00,
0x02, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0xe1, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x70, 0x74, 0x68, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x00,
};

#endif
4 changes: 2 additions & 2 deletions source/shaders/disable_color_buffer_v.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

static unsigned int size_disable_color_buffer_v = 264;
static unsigned char disable_color_buffer_v[] __attribute__((aligned(16))) = {
0x47, 0x58, 0x50, 0x00, 0x01, 0x04, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0xae, 0x20, 0xf7, 0x77,
0x47, 0x58, 0x50, 0x00, 0x01, 0x04, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0xef, 0x20, 0x60, 0x82,
0x46, 0x2f, 0x88, 0x9e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00,
Expand All @@ -14,7 +14,7 @@ static unsigned char disable_color_buffer_v[] __attribute__((aligned(16))) = {
0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xa0, 0x9f, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xa0, 0x9f, 0x14, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x44, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x40, 0x09, 0x00, 0xf8, 0x01, 0x00, 0x04, 0x9f,
0x84, 0x1f, 0xc5, 0x08, 0x00, 0x0f, 0x00, 0x03, 0x21, 0x05, 0x80, 0x38, 0x00, 0x0f, 0x04, 0x03,
0x59, 0x05, 0x80, 0x38, 0x00, 0x00, 0x20, 0xa0, 0x00, 0x50, 0x27, 0xfb, 0x10, 0x00, 0x00, 0x00,
Expand Down
2 changes: 1 addition & 1 deletion source/shaders/texture2d_rgba_v.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
static unsigned int size_texture2d_rgba_v = 900;
static unsigned char texture2d_rgba_v[] __attribute__((aligned(16))) = {
0x47, 0x58, 0x50, 0x00, 0x01, 0x04, 0x00, 0x00, 0x83, 0x03, 0x00, 0x00, 0x8f, 0x3b, 0x70, 0x51,
0xc7, 0x5e, 0x64, 0xf8, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x7e, 0x76, 0xab, 0xcf, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x44, 0x02, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x27, 0x00, 0x00, 0x00,
0xac, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00,
Expand Down
6 changes: 3 additions & 3 deletions source/shaders/texture2d_v.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

static unsigned int size_texture2d_v = 888;
static unsigned char texture2d_v[] __attribute__((aligned(16))) = {
0x47, 0x58, 0x50, 0x00, 0x01, 0x04, 0x00, 0x00, 0x75, 0x03, 0x00, 0x00, 0x23, 0x35, 0x1e, 0x7f,
0xda, 0x5d, 0x7d, 0x2b, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x47, 0x58, 0x50, 0x00, 0x01, 0x04, 0x00, 0x00, 0x75, 0x03, 0x00, 0x00, 0x21, 0x35, 0x5a, 0x7c,
0xee, 0x18, 0xf8, 0x04, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x02, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0x08, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x28, 0x00, 0x00, 0x00,
0xac, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00,
Expand All @@ -14,7 +14,7 @@ static unsigned char texture2d_v[] __attribute__((aligned(16))) = {
0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x01, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x12, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x68, 0x41, 0x0a, 0x05, 0x82, 0x38,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x68, 0x41, 0x0a, 0x05, 0x82, 0x38,
0x14, 0x15, 0x04, 0xa5, 0xa6, 0x10, 0xa4, 0x08, 0x02, 0x0a, 0x20, 0x82, 0x02, 0x00, 0x80, 0x30,
0x11, 0x85, 0x68, 0xa6, 0x86, 0x10, 0xc0, 0x08, 0x10, 0x06, 0x04, 0xa5, 0xa6, 0x00, 0xa4, 0x08,
0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
18 changes: 6 additions & 12 deletions source/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ typedef enum texEnvMode{
REPLACE = 4
} texEnvMode;

// 2D vertex for 2D canvas struct
typedef struct clear_vertex{
vector2f position;
} clear_vertex;

// 3D vertex for position struct
typedef struct position_vertex{
vector3f position;
} position_vertex;

// 3D vertex for position + 4D vertex for RGBA color struct
typedef struct rgba_vertex{
vector3f position;
Expand Down Expand Up @@ -118,15 +108,16 @@ extern GLboolean vblank; // Current setting for VSync

extern GLenum orig_depth_test; // Original depth test state (used for depth test invalidation)

// Scissor test shaders
extern SceGxmFragmentProgram *scissor_test_fragment_program; // Scissor test fragment program
extern clear_vertex *scissor_test_vertices; // Scissor test region vertices
extern vector2f *scissor_test_vertices; // Scissor test region vertices
extern SceUID scissor_test_vertices_uid; // Scissor test vertices memblock id

extern uint16_t *depth_clear_indices; // Memblock starting address for clear screen indices

// Clear screen shaders
extern SceGxmVertexProgram *clear_vertex_program_patched; // Patched vertex program for clearing screen
extern clear_vertex *clear_vertices; // Memblock starting address for clear screen vertices
extern vector2f *clear_vertices; // Memblock starting address for clear screen vertices

/* gxm.c */
void initGxm(void); // Inits sceGxm
Expand Down Expand Up @@ -164,4 +155,7 @@ void changeCustomShadersBlend(SceGxmBlendInfo *blend_info); // Change SceGxmBlen
void reloadCustomShader(void); // Reloads in use custom shader inside sceGxm
void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean implicit_wvp); // vglDrawObjects implementation for rendering with custom shaders

/* misc functions */
void vector2f_convert_to_local_space(vector2f *out, int x, int y, int width, int height); // Converts screen coords to local space

#endif
11 changes: 2 additions & 9 deletions source/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GLboolean depth_mask_state = GL_TRUE; // Current state for glDepthMask
scissor_region region; // Current scissor test region setup
GLboolean scissor_test_state = GL_FALSE; // Current state for GL_SCISSOR_TEST
SceGxmFragmentProgram *scissor_test_fragment_program; // Scissor test fragment program
clear_vertex *scissor_test_vertices = NULL; // Scissor test region vertices
vector2f *scissor_test_vertices = NULL; // Scissor test region vertices
SceUID scissor_test_vertices_uid; // Scissor test vertices memblock id

// Stencil Test
Expand Down Expand Up @@ -236,14 +236,7 @@ void update_scissor_test(){

// Calculating scissor test region vertices
if (scissor_test_state){
scissor_test_vertices[0].position.x = ((2.0f * region.x) / DISPLAY_WIDTH_FLOAT) - 1.0f;
scissor_test_vertices[0].position.y = 1.0f - (2.0f * (region.y + region.h)) / DISPLAY_HEIGHT_FLOAT;
scissor_test_vertices[1].position.x = ((2.0f * (region.x + region.w)) / DISPLAY_WIDTH_FLOAT) - 1.0f;
scissor_test_vertices[1].position.y = 1.0f - (2.0f * (region.y + region.h)) / DISPLAY_HEIGHT_FLOAT;
scissor_test_vertices[2].position.x = ((2.0f * (region.x + region.w)) / DISPLAY_WIDTH_FLOAT) - 1.0f;
scissor_test_vertices[2].position.y = 1.0f - (2.0f * region.y) / DISPLAY_HEIGHT_FLOAT;
scissor_test_vertices[3].position.x = ((2.0f * region.x) / DISPLAY_WIDTH_FLOAT) - 1.0f;
scissor_test_vertices[3].position.y = 1.0f - (2.0f * region.y) / DISPLAY_HEIGHT_FLOAT;
vector2f_convert_to_local_space(scissor_test_vertices, region.x, region.y, region.w, region.h);
}

// Setting current vertex program to clear screen one and fragment program to scissor test one
Expand Down
Loading

0 comments on commit 6b4e665

Please sign in to comment.