From e7b22a8d3b61acddf743c0911e6faef624f1afb6 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 4 Mar 2024 15:02:09 +0100 Subject: [PATCH] libvgcode - Replace 'glVertexAttribIPointer()' with 'glVertexAttribPointer()' in SegmentTemplate::init() for OpenGL ES --- src/libvgcode/CMakeLists.txt | 8 ++++---- src/libvgcode/src/SegmentTemplate.cpp | 6 +++++- src/libvgcode/src/ShadersES.hpp | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libvgcode/CMakeLists.txt b/src/libvgcode/CMakeLists.txt index c315cc2848..8bb7e46f50 100644 --- a/src/libvgcode/CMakeLists.txt +++ b/src/libvgcode/CMakeLists.txt @@ -44,10 +44,10 @@ set(LIBVGCODE_SOURCES src/ViewerImpl.cpp src/ViewRange.hpp src/ViewRange.cpp - # glad OpenGL - glad/include/glad/gl.h - glad/include/KHR/khrplatform.h - glad/src/gl.c + # glad OpenGL + glad/include/glad/gl.h + glad/include/KHR/khrplatform.h + glad/src/gl.c # # glad OpenGL ES # glad/include/glad/gles2.h # glad/include/KHR/khrplatform.h diff --git a/src/libvgcode/src/SegmentTemplate.cpp b/src/libvgcode/src/SegmentTemplate.cpp index 93779a8472..bc8a1d2001 100644 --- a/src/libvgcode/src/SegmentTemplate.cpp +++ b/src/libvgcode/src/SegmentTemplate.cpp @@ -45,7 +45,11 @@ void SegmentTemplate::init() glsafe(glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); glsafe(glBufferData(GL_ARRAY_BUFFER, VERTEX_DATA.size() * sizeof(uint8_t), VERTEX_DATA.data(), GL_STATIC_DRAW)); glsafe(glEnableVertexAttribArray(0)); - glsafe(glVertexAttribIPointer(0, 1, GL_UNSIGNED_BYTE, sizeof(uint8_t), (const void*)0)); +#if VGCODE_ENABLE_OPENGL_ES + glsafe(glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, (const void*)0)); +#else + glsafe(glVertexAttribIPointer(0, 1, GL_UNSIGNED_BYTE, 0, (const void*)0)); +#endif // VGCODE_ENABLE_OPENGL_ES glsafe(glBindBuffer(GL_ARRAY_BUFFER, curr_array_buffer)); glsafe(glBindVertexArray(curr_vertex_array)); diff --git a/src/libvgcode/src/ShadersES.hpp b/src/libvgcode/src/ShadersES.hpp index 0fa9d0f666..e688fa7b4c 100644 --- a/src/libvgcode/src/ShadersES.hpp +++ b/src/libvgcode/src/ShadersES.hpp @@ -31,7 +31,7 @@ static const char* Segments_Vertex_Shader_ES = "uniform sampler2D height_width_angle_tex;\n" "uniform sampler2D color_tex;\n" "uniform usampler2D segment_index_tex;\n" -"in int vertex_id;\n" +"in float vertex_id_float;\n" "out vec3 color;\n" "vec3 decode_color(float color) {\n" " int c = int(round(color));\n" @@ -56,6 +56,7 @@ static const char* Segments_Vertex_Shader_ES = " return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" "}\n" "void main() {\n" +" int vertex_id = int(vertex_id_float);\n" " int id_a = int(texelFetch(segment_index_tex, tex_coord_u(segment_index_tex, gl_InstanceID), 0).r);\n" " int id_b = id_a + 1;\n" " vec3 pos_a = texelFetch(position_tex, tex_coord(position_tex, id_a), 0).xyz;\n"