Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
GL41/GLES/RIF: Cleanups, fix gl4 samplers init/term
Browse files Browse the repository at this point in the history
  • Loading branch information
skmp committed Jan 30, 2020
1 parent 1525af6 commit ab9d476
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 74 deletions.
4 changes: 3 additions & 1 deletion libswirl/hw/pvr/Renderer_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,12 @@ static void rend_cancel_emu_wait()

}


//called always on vlbank, even before rend_init_renderer
void rend_resize(int width, int height) {
screen_width = width;
screen_height = height;
//renderer->Resize(width, height);
if (renderer) renderer->Resize(width, height);
}


Expand Down
3 changes: 3 additions & 0 deletions libswirl/rend/gl4/gl4.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ extern const char *gl4PixelPipelineShader;
bool gl4CompilePipelineShader(gl4PipelineShader* s, bool rotate_90, const char *source = gl4PixelPipelineShader);
void gl4_delete_shaders();

void gl4_CreateSamplers();
void gl4_DestroySamplers();

extern GLuint stencilTexId;
extern GLuint depthTexId;
extern GLuint opaqueTexId;
Expand Down
12 changes: 10 additions & 2 deletions libswirl/rend/gl4/gl4draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ static GLuint texSamplers[2];
static GLuint depth_fbo;
GLuint depthSaveTexId;

void gl4_CreateSamplers() {
glGenSamplers(2, texSamplers);
}

void gl4_DestroySamplers() {
glDeleteSamplers(2, texSamplers);
memset(texSamplers, 0, sizeof(texSamplers));
}


static gl4PipelineShader *gl4GetProgram(u32 cp_AlphaTest, u32 pp_ClipTestMode,
u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset,
u32 pp_FogCtrl, bool pp_TwoVolumes, u32 pp_DepthFunc, bool pp_Gouraud, bool pp_BumpMap, bool fog_clamping, int pass)
Expand Down Expand Up @@ -450,8 +460,6 @@ void gl4DrawStrips(GLuint output_fbo)
if (stencilTexId == 0)
CreateTextures(scaled_width, scaled_height);
}
if (texSamplers[0] == 0)
glGenSamplers(2, texSamplers);

glcache.DepthMask(GL_TRUE);
glStencilMask(0xFF);
Expand Down
130 changes: 65 additions & 65 deletions libswirl/rend/gl4/gl4rend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ void gl4_delete_shaders()
gl4.modvol_shader.program = 0;
}

static void gles_term(void)
static void gl41_term(void)
{
glDeleteBuffers(1, &gl4.vbo.geometry);
gl4.vbo.geometry = 0;
Expand All @@ -517,7 +517,7 @@ static void create_modvol_shader()
gl4.modvol_shader.extra_depth_scale = glGetUniformLocation(gl4.modvol_shader.program, "extra_depth_scale");
}

static bool gl_create_resources()
static bool gl4_create_resources()
{
if (gl4.vbo.geometry != 0)
// Assume the resources have already been created
Expand Down Expand Up @@ -554,7 +554,7 @@ static bool gl_create_resources()
//setup
extern void initABuffer();

static bool gles_init()
static bool gl41_init()
{
int major = 0;
int minor = 0;
Expand All @@ -567,24 +567,21 @@ static bool gles_init()
}
printf("Per-pixel sorting enabled\n");

glcache.DisableCache();
glcache.EnableCache();

if (!gl_create_resources())
if (!gl4_create_resources())
return false;

// glEnable(GL_DEBUG_OUTPUT);
// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
// glDebugMessageCallback(gl_DebugOutput, NULL);
// glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
// glEnable(GL_DEBUG_OUTPUT);
// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
// glDebugMessageCallback(gl_DebugOutput, NULL);
// glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);


//clean up the buffer
glcache.ClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
os_gl_swap();

initABuffer();

gl4_CreateSamplers();

if (settings.rend.TextureUpscale > 1)
{
// Trick to preload the tables used by xBRZ
Expand All @@ -599,13 +596,6 @@ static bool gles_init()

static bool RenderFrame(u8* vram, bool isRenderFramebuffer)
{
static int old_screen_width, old_screen_height, old_screen_scaling;
if (screen_width != old_screen_width || screen_height != old_screen_height || settings.rend.ScreenScaling != old_screen_scaling) {
rend_resize(screen_width, screen_height);
old_screen_width = screen_width;
old_screen_height = screen_height;
old_screen_scaling = settings.rend.ScreenScaling;
}
DoCleanup();
create_modvol_shader();

Expand Down Expand Up @@ -972,14 +962,59 @@ struct gl4rend : Renderer
{
u8* vram;
bool hasInited = false;
int old_screen_width = -1, old_screen_height = -1 , old_screen_scaling = -1;

gl4rend(u8* vram) : vram(vram) { }

bool Init() { return (hasInited = gles_init()); }
bool Init() { return (hasInited = gl41_init()); }
void Resize(int w, int h)
{
screen_width=w;
screen_height=h;

if (w != old_screen_width || h != old_screen_height || settings.rend.ScreenScaling != old_screen_scaling) {

if (stencilTexId != 0)
{
glcache.DeleteTextures(1, &stencilTexId);
stencilTexId = 0;
}
if (depthTexId != 0)
{
glcache.DeleteTextures(1, &depthTexId);
depthTexId = 0;
}
if (opaqueTexId != 0)
{
glcache.DeleteTextures(1, &opaqueTexId);
opaqueTexId = 0;
}
if (depthSaveTexId != 0)
{
glcache.DeleteTextures(1, &depthSaveTexId);
depthSaveTexId = 0;
}
reshapeABuffer(w, h);

old_screen_width = w;
old_screen_height = h;
old_screen_scaling = settings.rend.ScreenScaling;
}
}

void SetFBScale(float x, float y)
{
fb_scale_x = x;
fb_scale_y = y;
}

~gl4rend()
{
if (!hasInited)
return;

gl4_DestroySamplers();

termABuffer();

if (stencilTexId != 0)
{
glcache.DeleteTextures(1, &stencilTexId);
Expand All @@ -1000,49 +1035,14 @@ struct gl4rend : Renderer
glcache.DeleteTextures(1, &depthSaveTexId);
depthSaveTexId = 0;
}
reshapeABuffer(w, h);
}
if (KillTex)
killtex();

void SetFBScale(float x, float y)
{
fb_scale_x = x;
fb_scale_y = y;
}
CollectCleanup();

~gl4rend()
{
if (!hasInited)
return;

termABuffer();
if (stencilTexId != 0)
{
glcache.DeleteTextures(1, &stencilTexId);
stencilTexId = 0;
}
if (depthTexId != 0)
{
glcache.DeleteTextures(1, &depthTexId);
depthTexId = 0;
}
if (opaqueTexId != 0)
{
glcache.DeleteTextures(1, &opaqueTexId);
opaqueTexId = 0;
}
if (depthSaveTexId != 0)
{
glcache.DeleteTextures(1, &depthSaveTexId);
depthSaveTexId = 0;
}
if (KillTex)
killtex();

CollectCleanup();

gl_free_osd_resources();
free_output_framebuffer();
gles_term();
gl_free_osd_resources();
free_output_framebuffer();
gl41_term();
}

bool Process(TA_context* ctx) { return ProcessFrame(this, vram, ctx); }
Expand Down
7 changes: 1 addition & 6 deletions libswirl/rend/gles/glesrend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,6 @@ bool gles_init()
// glDebugMessageCallback(gl_DebugOutput, NULL);
// glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);

//clean up the buffer
glcache.ClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
os_gl_swap();

#ifdef GL_GENERATE_MIPMAP_HINT
if (gl.is_gles)
glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
Expand Down Expand Up @@ -1524,7 +1519,7 @@ struct glesrend final : Renderer
fb_scale_y = y;
}

void Resize(int w, int h) { screen_width=w; screen_height=h; }
void Resize(int w, int h) { /* do nothing */ }
~glesrend()
{
if (wasInit) {
Expand Down

0 comments on commit ab9d476

Please sign in to comment.