fix shader for Apple devices

This commit is contained in:
2019-07-21 08:47:26 +02:00
parent 85d9c057f8
commit 97d9ca717a
3 changed files with 19 additions and 11 deletions

View File

@@ -24,15 +24,21 @@ void main()
highp vec4 bg = texture(tex_bg, uv); highp vec4 bg = texture(tex_bg, uv);
if (bg.a == 0.0) if (bg.a == 0.0)
{ {
highp ivec2 sz = textureSize(tex_bg, 0);
highp ivec2 uv_raster = ivec2(uv * vec2(sz));
highp vec4 sum = vec4(0.0); highp vec4 sum = vec4(0.0);
for (int y = -1; y <= 1; y++) highp vec4 c;
{ c = texelFetch(tex_bg, uv_raster + ivec2(-1, -1), 0); sum += vec4(c.rgb * c.a, c.a);
for (int x = -1; x <= 1; x++) c = texelFetch(tex_bg, uv_raster + ivec2(-1, 0), 0); sum += vec4(c.rgb * c.a, c.a);
{ c = texelFetch(tex_bg, uv_raster + ivec2(-1, 1), 0); sum += vec4(c.rgb * c.a, c.a);
highp vec4 c = textureOffset(tex_bg, uv, ivec2(x, y));
sum += vec4(c.rgb * c.a, c.a); c = texelFetch(tex_bg, uv_raster + ivec2( 0, -1), 0); sum += vec4(c.rgb * c.a, c.a);
} c = texelFetch(tex_bg, uv_raster + ivec2( 0, 1), 0); sum += vec4(c.rgb * c.a, c.a);
}
c = texelFetch(tex_bg, uv_raster + ivec2( 1, -1), 0); sum += vec4(c.rgb * c.a, c.a);
c = texelFetch(tex_bg, uv_raster + ivec2( 1, 0), 0); sum += vec4(c.rgb * c.a, c.a);
c = texelFetch(tex_bg, uv_raster + ivec2( 1, 1), 0); sum += vec4(c.rgb * c.a, c.a);
frag = sum.a > 0.0 ? vec4(sum.rgb / sum.a, 0.0) : bg; frag = sum.a > 0.0 ? vec4(sum.rgb / sum.a, 0.0) : bg;
} }
else else

View File

@@ -259,7 +259,7 @@ void RTT::clear_mask(glm::bool4 mask, glm::vec4 color)
{ {
// save old state // save old state
std::array<GLboolean, 4> old_mask; std::array<GLboolean, 4> old_mask;
glGetBooleanv(GL_COLOR_WRITEMASK, std::data(old_mask)); glGetBooleanv(GL_COLOR_WRITEMASK, old_mask.data());
// clear with mask // clear with mask
glColorMask(mask.r, mask.g, mask.b, mask.a); glColorMask(mask.r, mask.g, mask.b, mask.a);

View File

@@ -15,7 +15,8 @@ std::string Shader::read(const std::string& path)
if (a.open(path.c_str())) if (a.open(path.c_str()))
{ {
struct stat tmp_info; struct stat tmp_info;
if (stat(path.c_str(), &tmp_info) == 0) std::string abs_path = Asset::absolute(path);
if (stat(abs_path.c_str(), &tmp_info) == 0)
m_deps[path] = tmp_info; m_deps[path] = tmp_info;
std::regex reg_include(R"!(#include "([^"]+)")!"); std::regex reg_include(R"!(#include "([^"]+)")!");
@@ -133,7 +134,8 @@ bool Shader::reload()
struct stat tmp_info; struct stat tmp_info;
for (auto& d : m_deps) for (auto& d : m_deps)
{ {
if (stat(d.first.c_str(), &tmp_info) != 0) std::string abs_path = Asset::absolute(d.first);
if (stat(abs_path.c_str(), &tmp_info) != 0)
continue; continue;
if (tmp_info.st_mtime > d.second.st_mtime) if (tmp_info.st_mtime > d.second.st_mtime)
{ {