Skip to content

Commit e77dbab

Browse files
committed
Fix blit shader in Android
1 parent b59035e commit e77dbab

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

demo/android/app/src/main/cpp/native_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void NativeEngine::init_app_common(Pathfinder::Vec2I window_size) {
6767
// Create app.
6868
pf_app = std::make_shared<App>(pf_device, pf_queue, window_size, svg_input, img_input);
6969

70-
pf_blit = std::make_shared<Blit>(pf_device, pf_queue, pf_swapchain->get_surface_format());
70+
pf_blit = std::make_shared<Pathfinder::Blit>(pf_device, pf_queue, pf_swapchain->get_surface_format());
7171

7272
auto dst_texture = pf_device->create_texture({window_size, Pathfinder::TextureFormat::Rgba8Unorm}, "dst texture");
7373

demo/android/app/src/main/cpp/native_engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NativeEngine {
2626
android_app *mAppCtx;
2727

2828
std::shared_ptr<App> pf_app;
29-
std::shared_ptr<Blit> pf_blit;
29+
std::shared_ptr<Pathfinder::Blit> pf_blit;
3030

3131
std::shared_ptr<Pathfinder::WindowBuilder> window_builder;
3232
std::shared_ptr<Pathfinder::Window> pf_window;

pathfinder/gpu/gl/shader_module.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Pathfinder {
1515

16-
bool replace(std::string &str, const std::string &from, const std::string &to) {
16+
bool replaceFirst(std::string &str, const std::string &from, const std::string &to) {
1717
size_t start_pos = str.find(from);
1818
if (start_pos == std::string::npos) {
1919
return false;
@@ -22,6 +22,15 @@ bool replace(std::string &str, const std::string &from, const std::string &to) {
2222
return true;
2323
}
2424

25+
void replaceAll(std::string &str, const std::string &from, const std::string &to) {
26+
if (from.empty()) return;
27+
size_t start_pos = 0;
28+
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
29+
str.replace(start_pos, from.length(), to);
30+
start_pos += to.length();
31+
}
32+
}
33+
2534
ShaderModuleGl::ShaderModuleGl(const std::vector<char> &source_code,
2635
ShaderStage shader_stage,
2736
const std::string &label) {
@@ -48,9 +57,22 @@ ShaderModuleGl::ShaderModuleGl(const std::vector<char> &source_code,
4857

4958
#ifdef PATHFINDER_MINIMUM_SHADER_VERSION_SUPPORT
5059
if (shader_stage == ShaderStage::Compute) {
51-
replace(code_string, "#version 430", "#version 310 es");
60+
replaceFirst(code_string, "#version 430", "#version 310 es");
5261
} else {
53-
replace(code_string, "#version 310 es", "#version 300 es");
62+
replaceFirst(code_string, "#version 310 es", "#version 300 es");
63+
}
64+
65+
if (shader_stage == ShaderStage::Vertex) {
66+
// 1. Find where "#version" is
67+
size_t ver_pos = code_string.find("#version");
68+
if (ver_pos != std::string::npos) {
69+
// 2. Find the following line break
70+
size_t nl_pos = code_string.find('\n', ver_pos);
71+
if (nl_pos != std::string::npos) {
72+
// 3. Add a new line
73+
code_string.insert(nl_pos + 1, "#define gl_VertexIndex gl_VertexID\n");
74+
}
75+
}
5476
}
5577
#endif
5678

pathfinder/gpu/gl/swap_chain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SwapChainGl::SwapChainGl(Vec2I size, EGLDisplay egl_display, EGLSurface egl_surf
1717
: SwapChain(size) {
1818
command_encoder_ = std::shared_ptr<CommandEncoderGl>(new CommandEncoderGl());
1919

20-
render_pass_ = std::shared_ptr<RenderPassGl>(new RenderPassGl(AttachmentLoadOp::Clear));
20+
render_pass_ = std::shared_ptr<RenderPassGl>(new RenderPassGl(AttachmentLoadOp::Clear, "Swapchain Render Pass"));
2121

2222
egl_display_ = egl_display;
2323
egl_surface_ = egl_surface;

0 commit comments

Comments
 (0)