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
|
||||
|
||||
constexpr GLenum TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE;
|
||||
constexpr GLenum MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF;
|
||||
constexpr GLenum TEXTURE_MAX_ANISOTROPY = 0x84FE;
|
||||
constexpr GLenum MAX_TEXTURE_MAX_ANISOTROPY = 0x84FF;
|
||||
|
||||
|
||||
namespace sys
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
#include <stdio.h>
|
||||
#elif defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/glx.h>
|
||||
#endif
|
||||
|
|
@ -77,7 +80,14 @@ namespace gl
|
|||
|
||||
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
|
||||
|
||||
static void * get_proc_address(const char *func)
|
||||
|
|
@ -886,14 +896,14 @@ namespace gl
|
|||
|
||||
const char * shader_prefix()
|
||||
{
|
||||
 return R"(#version 300 es
|
||||

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

|
||||
)";
|
||||
return R"(#version 300 es
|
||||
|
||||
precision highp int;
|
||||
precision highp float;
|
||||
precision highp sampler2D;
|
||||
precision highp usampler2D;
|
||||
|
||||
)";
|
||||
}
|
||||
|
||||
} // namespace sys
|
||||
|
|
|
|||
|
|
@ -34,17 +34,23 @@ namespace psemek::gfx
|
|||
|
||||
void color(texture_2d const & tex, 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);
|
||||
#endif
|
||||
void color(texture_cubemap const & tex, int face, int attachment = 0);
|
||||
void color(renderbuffer const & rb, int attachment = 0);
|
||||
void depth(texture_2d const & tex);
|
||||
void depth(texture_2d_array const & tex, int layer);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
void depth(texture_cubemap const & tex);
|
||||
#endif
|
||||
void depth(texture_cubemap const & tex, int face);
|
||||
void depth(renderbuffer const & rb);
|
||||
void depth_stencil(texture_2d const & tex);
|
||||
void depth_stencil(texture_2d_array const & tex, int layer);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
void depth_stencil(texture_cubemap const & tex);
|
||||
#endif
|
||||
void depth_stencil(texture_cubemap const & tex, int face);
|
||||
void depth_stencil(renderbuffer const & rb);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@ namespace psemek::gfx
|
|||
|
||||
struct program
|
||||
{
|
||||
program(std::string_view compute_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);
|
||||
#endif
|
||||
|
||||
program(program && other);
|
||||
|
||||
|
|
|
|||
|
|
@ -102,11 +102,13 @@ namespace psemek::gfx
|
|||
gl::FramebufferTextureLayer(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0, layer);
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
void framebuffer::color(texture_cubemap const & tex, int attachment)
|
||||
{
|
||||
bind();
|
||||
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::COLOR_ATTACHMENT0 + attachment, tex.id(), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
void framebuffer::depth(texture_cubemap const & tex)
|
||||
{
|
||||
bind();
|
||||
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_ATTACHMENT, tex.id(), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
void framebuffer::depth_stencil(texture_cubemap const & tex)
|
||||
{
|
||||
bind();
|
||||
gl::FramebufferTexture(gl::DRAW_FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, tex.id(), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void framebuffer::depth_stencil(texture_cubemap const & tex, int face)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ out vec4 out_color;
|
|||
|
||||
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.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_MIN_FILTER, gl::NEAREST);
|
||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE);
|
||||
|
|
|
|||
|
|
@ -313,20 +313,22 @@ namespace psemek::gfx
|
|||
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_ = 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_ = create_program({{gl::VERTEX_SHADER, vertex_source}, {gl::GEOMETRY_SHADER, geometry_source}, {gl::FRAGMENT_SHADER, fragment_source}});
|
||||
}
|
||||
#endif
|
||||
|
||||
program::program(program && other)
|
||||
: program_(other.program_)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,11 @@ namespace psemek::gfx
|
|||
|
||||
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;
|
||||
#endif
|
||||
|
||||
float level;
|
||||
gl::GetFloatv(gl::MAX_TEXTURE_MAX_ANISOTROPY, &level);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue