Tech ENABLE_OPENGL_ES - 1st installment
This commit is contained in:
parent
ac7c4b342b
commit
bb36f0df0c
17 changed files with 385 additions and 69 deletions
src/slic3r/GUI
|
@ -125,6 +125,22 @@ void GLModel::Geometry::add_vertex(const Vec3f& position, const Vec3f& normal, c
|
|||
vertices.emplace_back(tex_coord.y());
|
||||
}
|
||||
|
||||
#if ENABLE_OPENGL_ES
|
||||
void GLModel::Geometry::add_vertex(const Vec3f& position, const Vec3f& normal, const Vec3f& extra)
|
||||
{
|
||||
assert(format.vertex_layout == EVertexLayout::P3N3E3);
|
||||
vertices.emplace_back(position.x());
|
||||
vertices.emplace_back(position.y());
|
||||
vertices.emplace_back(position.z());
|
||||
vertices.emplace_back(normal.x());
|
||||
vertices.emplace_back(normal.y());
|
||||
vertices.emplace_back(normal.z());
|
||||
vertices.emplace_back(extra.x());
|
||||
vertices.emplace_back(extra.y());
|
||||
vertices.emplace_back(extra.z());
|
||||
}
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
|
||||
void GLModel::Geometry::add_vertex(const Vec4f& position)
|
||||
{
|
||||
assert(format.vertex_layout == EVertexLayout::P4);
|
||||
|
@ -272,6 +288,9 @@ size_t GLModel::Geometry::vertex_stride_floats(const Format& format)
|
|||
case EVertexLayout::P3T2: { return 5; }
|
||||
case EVertexLayout::P3N3: { return 6; }
|
||||
case EVertexLayout::P3N3T2: { return 8; }
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3E3: { return 9; }
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P4: { return 4; }
|
||||
default: { assert(false); return 0; }
|
||||
};
|
||||
|
@ -286,7 +305,12 @@ size_t GLModel::Geometry::position_stride_floats(const Format& format)
|
|||
case EVertexLayout::P3:
|
||||
case EVertexLayout::P3T2:
|
||||
case EVertexLayout::P3N3:
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3T2:
|
||||
case EVertexLayout::P3N3E3: { return 3; }
|
||||
#else
|
||||
case EVertexLayout::P3N3T2: { return 3; }
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P4: { return 4; }
|
||||
default: { assert(false); return 0; }
|
||||
};
|
||||
|
@ -302,6 +326,9 @@ size_t GLModel::Geometry::position_offset_floats(const Format& format)
|
|||
case EVertexLayout::P3T2:
|
||||
case EVertexLayout::P3N3:
|
||||
case EVertexLayout::P3N3T2:
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3E3:
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P4: { return 0; }
|
||||
default: { assert(false); return 0; }
|
||||
};
|
||||
|
@ -312,7 +339,12 @@ size_t GLModel::Geometry::normal_stride_floats(const Format& format)
|
|||
switch (format.vertex_layout)
|
||||
{
|
||||
case EVertexLayout::P3N3:
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3T2:
|
||||
case EVertexLayout::P3N3E3: { return 3; }
|
||||
#else
|
||||
case EVertexLayout::P3N3T2: { return 3; }
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
default: { assert(false); return 0; }
|
||||
};
|
||||
}
|
||||
|
@ -322,7 +354,12 @@ size_t GLModel::Geometry::normal_offset_floats(const Format& format)
|
|||
switch (format.vertex_layout)
|
||||
{
|
||||
case EVertexLayout::P3N3:
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3T2:
|
||||
case EVertexLayout::P3N3E3: { return 3; }
|
||||
#else
|
||||
case EVertexLayout::P3N3T2: { return 3; }
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
default: { assert(false); return 0; }
|
||||
};
|
||||
}
|
||||
|
@ -349,6 +386,26 @@ size_t GLModel::Geometry::tex_coord_offset_floats(const Format& format)
|
|||
};
|
||||
}
|
||||
|
||||
#if ENABLE_OPENGL_ES
|
||||
size_t GLModel::Geometry::extra_stride_floats(const Format& format)
|
||||
{
|
||||
switch (format.vertex_layout)
|
||||
{
|
||||
case EVertexLayout::P3N3E3: { return 3; }
|
||||
default: { assert(false); return 0; }
|
||||
};
|
||||
}
|
||||
|
||||
size_t GLModel::Geometry::extra_offset_floats(const Format& format)
|
||||
{
|
||||
switch (format.vertex_layout)
|
||||
{
|
||||
case EVertexLayout::P3N3E3: { return 6; }
|
||||
default: { assert(false); return 0; }
|
||||
};
|
||||
}
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
|
||||
size_t GLModel::Geometry::index_stride_bytes(const Geometry& data)
|
||||
{
|
||||
switch (data.index_type)
|
||||
|
@ -370,6 +427,9 @@ bool GLModel::Geometry::has_position(const Format& format)
|
|||
case EVertexLayout::P3T2:
|
||||
case EVertexLayout::P3N3:
|
||||
case EVertexLayout::P3N3T2:
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3E3:
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P4: { return true; }
|
||||
default: { assert(false); return false; }
|
||||
};
|
||||
|
@ -385,7 +445,12 @@ bool GLModel::Geometry::has_normal(const Format& format)
|
|||
case EVertexLayout::P3T2:
|
||||
case EVertexLayout::P4: { return false; }
|
||||
case EVertexLayout::P3N3:
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3T2:
|
||||
case EVertexLayout::P3N3E3: { return true; }
|
||||
#else
|
||||
case EVertexLayout::P3N3T2: { return true; }
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
default: { assert(false); return false; }
|
||||
};
|
||||
}
|
||||
|
@ -400,10 +465,31 @@ bool GLModel::Geometry::has_tex_coord(const Format& format)
|
|||
case EVertexLayout::P2:
|
||||
case EVertexLayout::P3:
|
||||
case EVertexLayout::P3N3:
|
||||
#if ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P3N3E3:
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
case EVertexLayout::P4: { return false; }
|
||||
default: { assert(false); return false; }
|
||||
};
|
||||
}
|
||||
|
||||
#if ENABLE_OPENGL_ES
|
||||
bool GLModel::Geometry::has_extra(const Format& format)
|
||||
{
|
||||
switch (format.vertex_layout)
|
||||
{
|
||||
case EVertexLayout::P3N3E3: { return true; }
|
||||
case EVertexLayout::P2:
|
||||
case EVertexLayout::P2T2:
|
||||
case EVertexLayout::P3:
|
||||
case EVertexLayout::P3T2:
|
||||
case EVertexLayout::P3N3:
|
||||
case EVertexLayout::P3N3T2:
|
||||
case EVertexLayout::P4: { return false; }
|
||||
default: { assert(false); return false; }
|
||||
};
|
||||
}
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
#else
|
||||
size_t GLModel::Geometry::vertices_count() const
|
||||
{
|
||||
|
@ -890,6 +976,9 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
|
|||
const bool position = Geometry::has_position(data.format);
|
||||
const bool normal = Geometry::has_normal(data.format);
|
||||
const bool tex_coord = Geometry::has_tex_coord(data.format);
|
||||
#if ENABLE_OPENGL_ES
|
||||
const bool extra = Geometry::has_extra(data.format);
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
|
||||
|
@ -898,9 +987,12 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
|
|||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_render_data.vbo_id));
|
||||
|
||||
int position_id = -1;
|
||||
int normal_id = -1;
|
||||
int position_id = -1;
|
||||
int normal_id = -1;
|
||||
int tex_coord_id = -1;
|
||||
#if ENABLE_OPENGL_ES
|
||||
int extra_id = -1;
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
|
||||
if (position) {
|
||||
position_id = shader->get_attrib_location("v_position");
|
||||
|
@ -923,6 +1015,15 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
|
|||
glsafe(::glEnableVertexAttribArray(tex_coord_id));
|
||||
}
|
||||
}
|
||||
#if ENABLE_OPENGL_ES
|
||||
if (extra) {
|
||||
extra_id = shader->get_attrib_location("v_extra");
|
||||
if (extra_id != -1) {
|
||||
glsafe(::glVertexAttribPointer(extra_id, Geometry::extra_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (const void*)Geometry::extra_offset_bytes(data.format)));
|
||||
glsafe(::glEnableVertexAttribArray(extra_id));
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
|
||||
shader->set_uniform("uniform_color", data.color);
|
||||
|
||||
|
@ -935,6 +1036,10 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
|
|||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
|
||||
#if ENABLE_OPENGL_ES
|
||||
if (extra_id != -1)
|
||||
glsafe(::glDisableVertexAttribArray(extra_id));
|
||||
#endif // ENABLE_OPENGL_ES
|
||||
if (tex_coord_id != -1)
|
||||
glsafe(::glDisableVertexAttribArray(tex_coord_id));
|
||||
if (normal_id != -1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue