Skip to content

Commit

Permalink
[glow] potentially fix bad glow texture (#3071)
Browse files Browse the repository at this point in the history
Might fix #3065 

fixes #3070
  • Loading branch information
ManDude authored Oct 9, 2023
1 parent bf961a3 commit 884f0ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
51 changes: 35 additions & 16 deletions game/graphics/opengl_renderer/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#endif

namespace {
std::string g_current_render;
std::string g_current_renderer;
}

/*!
Expand All @@ -51,16 +51,16 @@ void GLAPIENTRY opengl_error_callback(GLenum source,
const GLchar* message,
const void* /*userParam*/) {
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) {
lg::debug("[{}] OpenGL notification 0x{:X} S{:X} T{:X}: {}", g_current_render, id, source, type,
message);
lg::debug("[{}] OpenGL notification 0x{:X} S{:X} T{:X}: {}", g_current_renderer, id, source,
type, message);
} else if (severity == GL_DEBUG_SEVERITY_LOW) {
lg::info("[{}] OpenGL message 0x{:X} S{:X} T{:X}: {}", g_current_render, id, source, type,
lg::info("[{}] OpenGL message 0x{:X} S{:X} T{:X}: {}", g_current_renderer, id, source, type,
message);
} else if (severity == GL_DEBUG_SEVERITY_MEDIUM) {
lg::warn("[{}] OpenGL warn 0x{:X} S{:X} T{:X}: {}", g_current_render, id, source, type,
lg::warn("[{}] OpenGL warn 0x{:X} S{:X} T{:X}: {}", g_current_renderer, id, source, type,
message);
} else if (severity == GL_DEBUG_SEVERITY_HIGH) {
lg::error("[{}] OpenGL error 0x{:X} S{:X} T{:X}: {}", g_current_render, id, source, type,
lg::error("[{}] OpenGL error 0x{:X} S{:X} T{:X}: {}", g_current_renderer, id, source, type,
message);
// ASSERT(false);
}
Expand All @@ -72,10 +72,10 @@ OpenGLRenderer::OpenGLRenderer(std::shared_ptr<TexturePool> texture_pool,
: m_render_state(texture_pool, loader, version),
m_collide_renderer(version),
m_version(version) {
// setup OpenGL errors
glEnable(GL_DEBUG_OUTPUT);
// requires OpenGL 4.3
#ifndef __APPLE__
// setup OpenGL errors
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(opengl_error_callback, nullptr);
// disable specific errors
const GLuint gl_error_ignores_api_other[1] = {0x20071};
Expand Down Expand Up @@ -661,6 +661,7 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
m_render_state.offset_of_s7 = offset_of_s7();

{
g_current_renderer = "frame-setup";
auto prof = m_profiler.root()->make_scoped_child("frame-setup");
setup_frame(settings);
if (settings.gpu_sync) {
Expand All @@ -669,6 +670,7 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
}

{
g_current_renderer = "loader";
auto prof = m_profiler.root()->make_scoped_child("loader");
if (m_last_pmode_alp == 0 && settings.pmode_alp_register != 0 && m_enable_fast_blackout_loads) {
// blackout, load everything and don't worry about frame rate
Expand All @@ -692,12 +694,14 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {

// blit framebuffer so that it can be used as a texture by the game later
{
g_current_renderer = "blit-display";
auto prof = m_profiler.root()->make_scoped_child("blit-display");
blit_display();
}

// apply effects done with PCRTC registers
{
g_current_renderer = "pcrtc";
auto prof = m_profiler.root()->make_scoped_child("pcrtc");
do_pcrtc_effects(settings.pmode_alp_register, &m_render_state, prof);
if (settings.gpu_sync) {
Expand All @@ -708,6 +712,7 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
m_last_pmode_alp = settings.pmode_alp_register;

if (settings.save_screenshot) {
g_current_renderer = "screenshot";
auto prof = m_profiler.root()->make_scoped_child("screenshot");
int read_buffer;
int x, y, w, h, fbo_id;
Expand Down Expand Up @@ -740,6 +745,7 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
}

if (settings.draw_render_debug_window) {
g_current_renderer = "render-window";
auto prof = m_profiler.root()->make_scoped_child("render-window");
draw_renderer_selection_window();
// add a profile bar for the imgui stuff
Expand All @@ -750,6 +756,7 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
}

if (settings.draw_loader_window) {
g_current_renderer = "loader-window";
m_render_state.loader->draw_debug_window();
}

Expand All @@ -760,10 +767,12 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
// }

if (settings.draw_profiler_window) {
g_current_renderer = "profiler-window";
m_profiler.draw();
}

if (settings.draw_small_profiler_window) {
g_current_renderer = "small-profiler-window";
SmallProfilerStats stats;
stats.draw_calls = m_profiler.root()->stats().draw_calls;
stats.triangles = m_profiler.root()->stats().triangles;
Expand All @@ -774,18 +783,24 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
}

if (settings.draw_subtitle_editor_window) {
g_current_renderer = "subtitle-editor-window";
if (m_subtitle_editor == nullptr) {
m_subtitle_editor = new SubtitleEditor();
}
m_subtitle_editor->draw_window();
}

if (settings.draw_filters_window) {
g_current_renderer = "filters-window";
m_filters_menu.draw_window();
}

if (settings.gpu_sync) {
g_current_renderer = "gpu-sync";
glFinish();
}

g_current_renderer = "end";
}

/*!
Expand Down Expand Up @@ -972,15 +987,15 @@ void OpenGLRenderer::dispatch_buckets_jak1(DmaFollower dma,
for (size_t bucket_id = 0; bucket_id < m_bucket_renderers.size(); bucket_id++) {
auto& renderer = m_bucket_renderers[bucket_id];
auto bucket_prof = prof.make_scoped_child(renderer->name_and_id());
g_current_render = renderer->name_and_id();
// lg::info("Render: {} start", g_current_render);
g_current_renderer = renderer->name_and_id();
// lg::info("Render: {} start", g_current_renderer);
renderer->render(dma, &m_render_state, bucket_prof);
if (sync_after_buckets) {
auto pp = scoped_prof("finish");
glFinish();
}

// lg::info("Render: {} end", g_current_render);
// lg::info("Render: {} end", g_current_renderer);
// should have ended at the start of the next chain
ASSERT(dma.current_tag_offset() == m_render_state.next_bucket);
m_render_state.next_bucket += 16;
Expand All @@ -993,7 +1008,6 @@ void OpenGLRenderer::dispatch_buckets_jak1(DmaFollower dma,
m_collide_renderer.render(&m_render_state, p);
}
}
g_current_render = "";

// TODO ending data.
}
Expand All @@ -1013,15 +1027,15 @@ void OpenGLRenderer::dispatch_buckets_jak2(DmaFollower dma,
for (size_t bucket_id = 0; bucket_id < m_bucket_renderers.size(); bucket_id++) {
auto& renderer = m_bucket_renderers[bucket_id];
auto bucket_prof = prof.make_scoped_child(renderer->name_and_id());
g_current_render = renderer->name_and_id();
// lg::info("Render: {} start", g_current_render);
g_current_renderer = renderer->name_and_id();
// lg::info("Render: {} start", g_current_renderer);
renderer->render(dma, &m_render_state, bucket_prof);
if (sync_after_buckets) {
auto pp = scoped_prof("finish");
glFinish();
}

// lg::info("Render: {} end", g_current_render);
// lg::info("Render: {} end", g_current_renderer);
// should have ended at the start of the next chain
ASSERT(dma.current_tag_offset() == m_render_state.next_bucket);
m_render_state.next_bucket += 16;
Expand All @@ -1046,6 +1060,8 @@ void OpenGLRenderer::dispatch_buckets_jak2(DmaFollower dma,
void OpenGLRenderer::dispatch_buckets(DmaFollower dma,
ScopedProfilerNode& prof,
bool sync_after_buckets) {
g_current_renderer = "dispatch-buckets pre";

m_render_state.version = m_version;
m_render_state.frame_idx++;
switch (m_version) {
Expand All @@ -1058,6 +1074,8 @@ void OpenGLRenderer::dispatch_buckets(DmaFollower dma,
default:
ASSERT(false);
}

g_current_renderer = "dispatch-buckets post";
}

#ifdef _WIN32
Expand Down Expand Up @@ -1178,7 +1196,7 @@ void OpenGLRenderer::finish_screenshot(const std::string& output_name,
glReadBuffer(read_buffer);
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.data());

// set alpha. For some reason, image viewers do weird stuff with alpha.
// set alpha. our renderers mess this up in a way that isn't relevant to the final framebuffer.
for (auto& px : buffer) {
px |= 0xff000000;
}
Expand All @@ -1190,6 +1208,7 @@ void OpenGLRenderer::finish_screenshot(const std::string& output_name,
}
#else
(void)quick_screenshot;
lg::error("screenshot to clipboard NYI non-Windows");
#endif

// flip upside down in place
Expand Down
2 changes: 1 addition & 1 deletion game/graphics/opengl_renderer/sprite/GlowRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void GlowRenderer::blit_depth(SharedRenderState* render_state) {

glBindTexture(GL_TEXTURE_2D, m_ogl.probe_fbo_depth_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_ogl.probe_fbo_w, m_ogl.probe_fbo_h, 0,
GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
}

Expand Down

0 comments on commit 884f0ef

Please sign in to comment.