Final Emscripten OpenGL fixes
This commit is contained in:
parent
2e94515c05
commit
4d7926b698
8 changed files with 49 additions and 21 deletions
|
|
@ -1288,8 +1288,8 @@ namespace gl
|
||||||
|
|
||||||
// GL_EXT_texture_filter_anisotropic
|
// GL_EXT_texture_filter_anisotropic
|
||||||
|
|
||||||
constexpr GLenum TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE;
|
constexpr GLenum TEXTURE_MAX_ANISOTROPY = 0x84FE;
|
||||||
constexpr GLenum MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF;
|
constexpr GLenum MAX_TEXTURE_MAX_ANISOTROPY = 0x84FF;
|
||||||
|
|
||||||
|
|
||||||
namespace sys
|
namespace sys
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
#else
|
#else
|
||||||
#include <GL/glx.h>
|
#include <GL/glx.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -77,7 +80,14 @@ namespace gl
|
||||||
|
|
||||||
return reinterpret_cast<void*>(GetProcAddress(image, reinterpret_cast<LPCSTR>(name)));
|
return reinterpret_cast<void*>(GetProcAddress(image, reinterpret_cast<LPCSTR>(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined(__EMSCRIPTEN__)
|
||||||
|
|
||||||
|
static void * get_proc_address(const char *func)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<void *>(eglGetProcAddress(func));
|
||||||
|
}
|
||||||
|
|
||||||
#else // GLX
|
#else // GLX
|
||||||
|
|
||||||
static void * get_proc_address(const char *func)
|
static void * get_proc_address(const char *func)
|
||||||
|
|
@ -886,14 +896,14 @@ namespace gl
|
||||||
|
|
||||||
const char * shader_prefix()
|
const char * shader_prefix()
|
||||||
{
|
{
|
||||||
 return R"(#version 300 es
|
return R"(#version 300 es
|
||||||

|
|
||||||
precision highp int;
|
precision highp int;
|
||||||
precision highp float;
|
precision highp float;
|
||||||
precision highp sampler2D;
|
precision highp sampler2D;
|
||||||
precision highp usampler2D;
|
precision highp usampler2D;
|
||||||

|
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sys
|
} // namespace sys
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,23 @@ namespace psemek::gfx
|
||||||
|
|
||||||
void color(texture_2d const & tex, int attachment = 0);
|
void color(texture_2d const & tex, int attachment = 0);
|
||||||
void color(texture_2d_array const & tex, int layer, int attachment = 0);
|
void color(texture_2d_array const & tex, int layer, int attachment = 0);
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
void color(texture_cubemap const & tex, int attachment = 0);
|
void color(texture_cubemap const & tex, int attachment = 0);
|
||||||
|
#endif
|
||||||
void color(texture_cubemap const & tex, int face, int attachment = 0);
|
void color(texture_cubemap const & tex, int face, int attachment = 0);
|
||||||
void color(renderbuffer const & rb, int attachment = 0);
|
void color(renderbuffer const & rb, int attachment = 0);
|
||||||
void depth(texture_2d const & tex);
|
void depth(texture_2d const & tex);
|
||||||
void depth(texture_2d_array const & tex, int layer);
|
void depth(texture_2d_array const & tex, int layer);
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
void depth(texture_cubemap const & tex);
|
void depth(texture_cubemap const & tex);
|
||||||
|
#endif
|
||||||
void depth(texture_cubemap const & tex, int face);
|
void depth(texture_cubemap const & tex, int face);
|
||||||
void depth(renderbuffer const & rb);
|
void depth(renderbuffer const & rb);
|
||||||
void depth_stencil(texture_2d const & tex);
|
void depth_stencil(texture_2d const & tex);
|
||||||
void depth_stencil(texture_2d_array const & tex, int layer);
|
void depth_stencil(texture_2d_array const & tex, int layer);
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
void depth_stencil(texture_cubemap const & tex);
|
void depth_stencil(texture_cubemap const & tex);
|
||||||
|
#endif
|
||||||
void depth_stencil(texture_cubemap const & tex, int face);
|
void depth_stencil(texture_cubemap const & tex, int face);
|
||||||
void depth_stencil(renderbuffer const & rb);
|
void depth_stencil(renderbuffer const & rb);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,12 @@ namespace psemek::gfx
|
||||||
|
|
||||||
struct program
|
struct program
|
||||||
{
|
{
|
||||||
program(std::string_view compute_source);
|
|
||||||
program(std::string_view vertex_source, std::string_view fragment_source);
|
program(std::string_view vertex_source, std::string_view fragment_source);
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
|
program(std::string_view compute_source);
|
||||||
program(std::string_view vertex_source, std::string_view geometry_source, std::string_view fragment_source);
|
program(std::string_view vertex_source, std::string_view geometry_source, std::string_view fragment_source);
|
||||||
|
#endif
|
||||||
|
|
||||||
program(program && other);
|
program(program && other);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,13 @@ namespace psemek::gfx
|
||||||
gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0, layer);
|
gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
void framebuffer::color(texture_cubemap const & tex, int attachment)
|
void framebuffer::color(texture_cubemap const & tex, int attachment)
|
||||||
{
|
{
|
||||||
bind();
|
bind();
|
||||||
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0);
|
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void framebuffer::color(texture_cubemap const & tex, int face, int attachment)
|
void framebuffer::color(texture_cubemap const & tex, int face, int attachment)
|
||||||
{
|
{
|
||||||
|
|
@ -140,11 +142,13 @@ namespace psemek::gfx
|
||||||
gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, tex.id(), 0, layer);
|
gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, tex.id(), 0, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
void framebuffer::depth(texture_cubemap const & tex)
|
void framebuffer::depth(texture_cubemap const & tex)
|
||||||
{
|
{
|
||||||
bind();
|
bind();
|
||||||
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, tex.id(), 0);
|
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, tex.id(), 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void framebuffer::depth(texture_cubemap const & tex, int face)
|
void framebuffer::depth(texture_cubemap const & tex, int face)
|
||||||
{
|
{
|
||||||
|
|
@ -178,11 +182,13 @@ namespace psemek::gfx
|
||||||
gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, tex.id(), 0, layer);
|
gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, tex.id(), 0, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
void framebuffer::depth_stencil(texture_cubemap const & tex)
|
void framebuffer::depth_stencil(texture_cubemap const & tex)
|
||||||
{
|
{
|
||||||
bind();
|
bind();
|
||||||
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, tex.id(), 0);
|
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, tex.id(), 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void framebuffer::depth_stencil(texture_cubemap const & tex, int face)
|
void framebuffer::depth_stencil(texture_cubemap const & tex, int face)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ out vec4 out_color;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
out_color = color * texture(u_texture, texcoord);
|
out_color = color * vec4(vec3(1.0), texture(u_texture, texcoord).r);
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
|
@ -164,9 +164,6 @@ namespace psemek::gfx
|
||||||
font_texture.load(gfx::read_image<std::uint8_t>(io::memory_istream{resource::font_9x12_png.data}));
|
font_texture.load(gfx::read_image<std::uint8_t>(io::memory_istream{resource::font_9x12_png.data}));
|
||||||
|
|
||||||
font_texture.bind();
|
font_texture.bind();
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_SWIZZLE_G, gl::RED);
|
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_SWIZZLE_B, gl::RED);
|
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_SWIZZLE_A, gl::RED);
|
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST);
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST);
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST);
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST);
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE);
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE);
|
||||||
|
|
|
||||||
|
|
@ -313,20 +313,22 @@ namespace psemek::gfx
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
program::program(std::string_view compute_source)
|
|
||||||
{
|
|
||||||
program_ = create_program({{gl::COMPUTE_SHADER, compute_source}});
|
|
||||||
}
|
|
||||||
|
|
||||||
program::program(std::string_view vertex_source, std::string_view fragment_source)
|
program::program(std::string_view vertex_source, std::string_view fragment_source)
|
||||||
{
|
{
|
||||||
program_ = create_program({{gl::VERTEX_SHADER, vertex_source}, {gl::FRAGMENT_SHADER, fragment_source}});
|
program_ = create_program({{gl::VERTEX_SHADER, vertex_source}, {gl::FRAGMENT_SHADER, fragment_source}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
|
program::program(std::string_view compute_source)
|
||||||
|
{
|
||||||
|
program_ = create_program({{gl::COMPUTE_SHADER, compute_source}});
|
||||||
|
}
|
||||||
|
|
||||||
program::program(std::string_view vertex_source, std::string_view geometry_source, std::string_view fragment_source)
|
program::program(std::string_view vertex_source, std::string_view geometry_source, std::string_view fragment_source)
|
||||||
{
|
{
|
||||||
program_ = create_program({{gl::VERTEX_SHADER, vertex_source}, {gl::GEOMETRY_SHADER, geometry_source}, {gl::FRAGMENT_SHADER, fragment_source}});
|
program_ = create_program({{gl::VERTEX_SHADER, vertex_source}, {gl::GEOMETRY_SHADER, geometry_source}, {gl::FRAGMENT_SHADER, fragment_source}});
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
program::program(program && other)
|
program::program(program && other)
|
||||||
: program_(other.program_)
|
: program_(other.program_)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,11 @@ namespace psemek::gfx
|
||||||
|
|
||||||
static std::optional<float> get_max_anisotropy()
|
static std::optional<float> get_max_anisotropy()
|
||||||
{
|
{
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
if (!gl::sys::ext_EXT_texture_filter_anisotropic()) return std::nullopt;
|
||||||
|
#else
|
||||||
if (!gl::sys::ext_ARB_texture_filter_anisotropic()) return std::nullopt;
|
if (!gl::sys::ext_ARB_texture_filter_anisotropic()) return std::nullopt;
|
||||||
|
#endif
|
||||||
|
|
||||||
float level;
|
float level;
|
||||||
gl::GetFloatv(gl::MAX_TEXTURE_MAX_ANISOTROPY, &level);
|
gl::GetFloatv(gl::MAX_TEXTURE_MAX_ANISOTROPY, &level);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue