Add option to always use GLSL tone mapping instead of GL_FRAMEBUFFER_SRGB.

This commit is contained in:
Alberto Torres 2024-08-29 00:01:54 +02:00
parent 6636b5e595
commit 1557d59d0f
3 changed files with 9 additions and 4 deletions

View file

@ -340,4 +340,4 @@ proc newMainFramebuffer*(engine: MyouEngine): Framebuffer =
result.engine = engine result.engine = engine
result.framebuffer = 0 result.framebuffer = 0
result.is_complete = true result.is_complete = true
result.use_sRGB = true result.use_sRGB = not engine.use_glsl_tone_mapping

View file

@ -64,6 +64,7 @@ proc newMyouEngine*(
opengl_version = default_gl_version, opengl_version = default_gl_version,
opengl_es = default_gl_es, opengl_es = default_gl_es,
glsl_version = "", glsl_version = "",
use_glsl_tone_mapping = true,
): MyouEngine ): MyouEngine
proc get_builtin_shader_library*(use_cubemap_prefiltering = true): string proc get_builtin_shader_library*(use_cubemap_prefiltering = true): string
proc get_builtin_shader_textures*(): Table[string, Texture] proc get_builtin_shader_textures*(): Table[string, Texture]
@ -87,6 +88,7 @@ proc newMyouEngine*(
opengl_version = default_gl_version, opengl_version = default_gl_version,
opengl_es = default_gl_es, opengl_es = default_gl_es,
glsl_version = "", glsl_version = "",
use_glsl_tone_mapping = true,
): MyouEngine = ): MyouEngine =
## Creates a Myou Engine instance. You need to call this before you can use ## Creates a Myou Engine instance. You need to call this before you can use
## the engine. You also need to call `run <#run,MyouEngine>`_ at the end of ## the engine. You also need to call `run <#run,MyouEngine>`_ at the end of
@ -103,6 +105,10 @@ proc newMyouEngine*(
# to override it with per-camera exposure settings # to override it with per-camera exposure settings
if opengl_es: if opengl_es:
assert opengl_version >= 300, "Minimum supported OpenGL ES version is 3.0" assert opengl_version >= 300, "Minimum supported OpenGL ES version is 3.0"
else:
assert opengl_version >= 330, "Minimum supported OpenGL version is 3.3"
if opengl_es or use_glsl_tone_mapping:
result.tone_mapping_library = dedent """ result.tone_mapping_library = dedent """
float linearrgb_to_srgb(float c){ float linearrgb_to_srgb(float c){
if (c < 0.0031308) return (c < 0.0) ? 0.0 : c * 12.92; if (c < 0.0031308) return (c < 0.0) ? 0.0 : c * 12.92;
@ -119,8 +125,8 @@ proc newMyouEngine*(
#define MYOU_TONE_MAP(x) linearrgb_to_srgb(x) #define MYOU_TONE_MAP(x) linearrgb_to_srgb(x)
""" """
result.tone_mapping_function = "MYOU_TONE_MAP" result.tone_mapping_function = "MYOU_TONE_MAP"
result.use_glsl_tone_mapping = true
else: else:
assert opengl_version >= 330, "Minimum supported OpenGL version is 3.3"
result.tone_mapping_library = "\n#define MYOU_TONE_MAP(x) x\n" result.tone_mapping_library = "\n#define MYOU_TONE_MAP(x) x\n"
echo "assigning renderer" echo "assigning renderer"

View file

@ -81,9 +81,8 @@ type
renderer*: RenderManager renderer*: RenderManager
tone_mapping_library*: string tone_mapping_library*: string
tone_mapping_function*: string tone_mapping_function*: string
use_glsl_tone_mapping*: bool
loaders_by_ext*: Table[string, seq[proc(e: MyouEngine): Loader]] loaders_by_ext*: Table[string, seq[proc(e: MyouEngine): Loader]]
# TODO: remove this and query it when screen is created
width*, height*: int
glsl_version*: string glsl_version*: string
all_framebuffers*: seq[Framebuffer] ## private all_framebuffers*: seq[Framebuffer] ## private