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

Commit

Permalink
Merge pull request #1775 from reicast/skmp/fix-nvidia-shield
Browse files Browse the repository at this point in the history
Fix GL41 renderer init, related fixes & cleanups
  • Loading branch information
skmp authored Jan 30, 2020
2 parents 090ebc1 + 2e873be commit 3813d4d
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 84 deletions.
3 changes: 3 additions & 0 deletions libswirl/gui/gui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,15 @@ struct GUIRenderer_impl : GUIRenderer {
renderer_changed = true;

ImGui_ImplOpenGL3_Init();

// rend_init_renderer(); // is lazy init on callback/rend_frame
printf("CreateContext Done\n");
return true;
}

void DestroyContext() {
printf("DestroyContext\n");
rend_term_renderer(); // also cleans texcache
ImGui_ImplOpenGL3_Shutdown();
os_gl_term();
printf("DestroyContext Done\n");
Expand Down
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
4 changes: 2 additions & 2 deletions libswirl/input/gamepad_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GamepadDevice
const std::string& unique_id() { return _unique_id; }
virtual bool gamepad_btn_input(u32 code, bool pressed);
bool gamepad_axis_input(u32 code, int value);
GamepadDevice() : settingsOpenning(false) { }

virtual ~GamepadDevice() {}

void detect_btn_input(input_detected_cb button_pressed);
Expand Down Expand Up @@ -65,7 +65,7 @@ class GamepadDevice

protected:
GamepadDevice(int maple_port, const char *api_name, bool remappable = true)
: _api_name(api_name), _maple_port(maple_port), input_mapper(NULL), _input_detected(NULL), _remappable(remappable)
: _api_name(api_name), _maple_port(maple_port), input_mapper(NULL), _input_detected(NULL), _remappable(remappable), settingsOpenning(false)
{
}
bool find_mapping(const char *custom_mapping = NULL);
Expand Down
15 changes: 13 additions & 2 deletions libswirl/linux-dist/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "linux-dist/x11.h"
#include "linux-dist/main.h"
#include "gui/gui.h"
#include "gui/gui_renderer.h"
#include "gui/gui_partials.h"

#include "input/gamepad.h"
Expand Down Expand Up @@ -120,8 +121,18 @@ void event_x11_handle()
XNextEvent((Display *)x11_disp, &event);

if (event.type == ClientMessage &&
event.xclient.data.l[0] == wmDeleteMessage)
virtualDreamcast->Stop([] {});
event.xclient.data.l[0] == wmDeleteMessage)
{
if (virtualDreamcast && sh4_cpu->IsRunning()) {
virtualDreamcast->Stop([] {
g_GUIRenderer->Stop();
});
}
else
{
g_GUIRenderer->Stop();
}
}
else if (event.type == ConfigureNotify)
{
x11_width = event.xconfigure.width;
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
160 changes: 95 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,16 +596,39 @@ 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();

{
GLuint output_fbo;

float screen_scaling = settings.rend.ScreenScaling / 100.f;
float screen_stretching = settings.rend.ScreenStretching / 100.f;


if (settings.rend.ScreenScaling != 100 || gl.swap_buffer_not_preserved)
{
output_fbo = init_output_framebuffer(screen_width * screen_scaling + 0.5f, screen_height * screen_scaling + 0.5f);
}
else
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, screen_width, screen_height);
output_fbo = 0;
}

if (isRenderFramebuffer) {
RenderFramebuffer();
glBindFramebuffer(GL_FRAMEBUFFER, output_fbo);

glcache.ClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);

gl4DrawFramebuffer(640, 480);
return true;
}
}

bool is_rtt=pvrrc.isRTT;

//if (FrameCount&7) return;
Expand Down Expand Up @@ -942,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 @@ -970,49 +1035,14 @@ struct gl4rend : Renderer
glcache.DeleteTextures(1, &depthSaveTexId);
depthSaveTexId = 0;
}
reshapeABuffer(w, h);
}

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

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

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
Loading

0 comments on commit 3813d4d

Please sign in to comment.