Merge branch 'et_multivolume_models' of https://github.com/prusa3d/Slic3r

This commit is contained in:
Enrico Turri 2019-02-28 11:24:35 +01:00
commit f88cc6a5c1
6 changed files with 83 additions and 42 deletions

View File

@ -1,11 +1,12 @@
#version 110 #version 110
attribute vec4 v_position;
attribute vec2 v_tex_coords; attribute vec2 v_tex_coords;
varying vec2 tex_coords; varying vec2 tex_coords;
void main() void main()
{ {
gl_Position = ftransform(); gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * v_position;
tex_coords = v_tex_coords; tex_coords = v_tex_coords;
} }

View File

@ -516,9 +516,9 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const
if (max_anisotropy > 0.0f) if (max_anisotropy > 0.0f)
{ {
::glBindTexture(GL_TEXTURE_2D, m_texture.get_id()); glsafe(::glBindTexture(GL_TEXTURE_2D, m_texture.get_id()));
::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy); glsafe(::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy));
::glBindTexture(GL_TEXTURE_2D, 0); glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
} }
} }
@ -542,9 +542,9 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const
if (!m_model.get_filename().empty()) if (!m_model.get_filename().empty())
{ {
::glEnable(GL_LIGHTING); glsafe(::glEnable(GL_LIGHTING));
m_model.render(); m_model.render();
::glDisable(GL_LIGHTING); glsafe(::glDisable(GL_LIGHTING));
} }
} }
@ -553,39 +553,32 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const
{ {
if (m_vbo_id == 0) if (m_vbo_id == 0)
{ {
::glGenBuffers(1, &m_vbo_id); glsafe(::glGenBuffers(1, &m_vbo_id));
::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id));
::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m_triangles.get_vertices_data_size(), (const GLvoid*)m_triangles.get_vertices_data(), GL_STATIC_DRAW); glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m_triangles.get_vertices_data_size(), (const GLvoid*)m_triangles.get_vertices_data(), GL_STATIC_DRAW));
::glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_position_offset()); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
::glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_tex_coords_offset());
::glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
::glEnable(GL_DEPTH_TEST); glsafe(::glEnable(GL_DEPTH_TEST));
::glDepthMask(GL_FALSE); glsafe(::glDepthMask(GL_FALSE));
::glEnable(GL_BLEND); glsafe(::glEnable(GL_BLEND));
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
::glEnable(GL_TEXTURE_2D);
::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
if (bottom) if (bottom)
::glFrontFace(GL_CW); glsafe(::glFrontFace(GL_CW));
render_prusa_shader(triangles_vcount, bottom); render_prusa_shader(bottom);
if (bottom) if (bottom)
::glFrontFace(GL_CCW); glsafe(::glFrontFace(GL_CCW));
::glDisable(GL_TEXTURE_2D); glsafe(::glDisable(GL_BLEND));
glsafe(::glDepthMask(GL_TRUE));
::glDisable(GL_BLEND);
::glDepthMask(GL_TRUE);
} }
} }
void Bed3D::render_prusa_shader(unsigned int vertices_count, bool transparent) const void Bed3D::render_prusa_shader(bool transparent) const
{ {
if (m_shader.get_shader_program_id() == 0) if (m_shader.get_shader_program_id() == 0)
m_shader.init("printbed.vs", "printbed.fs"); m_shader.init("printbed.vs", "printbed.fs");
@ -595,15 +588,35 @@ void Bed3D::render_prusa_shader(unsigned int vertices_count, bool transparent) c
m_shader.start_using(); m_shader.start_using();
m_shader.set_uniform("transparent_background", transparent); m_shader.set_uniform("transparent_background", transparent);
::glBindTexture(GL_TEXTURE_2D, (GLuint)m_texture.get_id()); unsigned int stride = m_triangles.get_vertex_data_size();
::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id);
::glEnableVertexAttribArray(0); GLint position_id = m_shader.get_attrib_location("v_position");
::glEnableVertexAttribArray(1); GLint tex_coords_id = m_shader.get_attrib_location("v_tex_coords");
::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices_count);
::glDisableVertexAttribArray(1); glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)m_texture.get_id()));
::glDisableVertexAttribArray(0); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id));
::glBindBuffer(GL_ARRAY_BUFFER, 0);
::glBindTexture(GL_TEXTURE_2D, 0); if (position_id != -1)
{
glsafe(::glEnableVertexAttribArray(position_id));
glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)m_triangles.get_position_offset()));
}
if (tex_coords_id != -1)
{
glsafe(::glEnableVertexAttribArray(tex_coords_id));
glsafe(::glVertexAttribPointer(tex_coords_id, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*)m_triangles.get_tex_coords_offset()));
}
glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)m_triangles.get_vertices_count()));
if (tex_coords_id != -1)
glsafe(::glDisableVertexAttribArray(tex_coords_id));
if (position_id != -1)
glsafe(::glDisableVertexAttribArray(position_id));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
m_shader.stop_using(); m_shader.stop_using();
} }
@ -754,7 +767,7 @@ void Bed3D::render_custom() const
glsafe(::glColor4f(0.35f, 0.35f, 0.35f, 0.4f)); glsafe(::glColor4f(0.35f, 0.35f, 0.35f, 0.4f));
glsafe(::glNormal3d(0.0f, 0.0f, 1.0f)); glsafe(::glNormal3d(0.0f, 0.0f, 1.0f));
#if ENABLE_TEXTURES_FROM_SVG #if ENABLE_TEXTURES_FROM_SVG
::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data()); glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data()));
#else #else
glsafe(::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_triangles.get_vertices())); glsafe(::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_triangles.get_vertices()));
#endif // ENABLE_TEXTURES_FROM_SVG #endif // ENABLE_TEXTURES_FROM_SVG
@ -768,7 +781,7 @@ void Bed3D::render_custom() const
glsafe(::glLineWidth(3.0f * m_scale_factor)); glsafe(::glLineWidth(3.0f * m_scale_factor));
glsafe(::glColor4f(0.2f, 0.2f, 0.2f, 0.4f)); glsafe(::glColor4f(0.2f, 0.2f, 0.2f, 0.4f));
#if ENABLE_TEXTURES_FROM_SVG #if ENABLE_TEXTURES_FROM_SVG
::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data()); glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data()));
#else #else
glsafe(::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_gridlines.get_vertices())); glsafe(::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_gridlines.get_vertices()));
#endif // ENABLE_TEXTURES_FROM_SVG #endif // ENABLE_TEXTURES_FROM_SVG
@ -786,7 +799,7 @@ void Bed3D::reset()
{ {
if (m_vbo_id > 0) if (m_vbo_id > 0)
{ {
::glDeleteBuffers(1, &m_vbo_id); glsafe(::glDeleteBuffers(1, &m_vbo_id));
m_vbo_id = 0; m_vbo_id = 0;
} }
} }

View File

@ -131,7 +131,7 @@ private:
EType detect_type(const Pointfs& shape) const; EType detect_type(const Pointfs& shape) const;
#if ENABLE_TEXTURES_FROM_SVG #if ENABLE_TEXTURES_FROM_SVG
void render_prusa(const std::string& key, bool bottom) const; void render_prusa(const std::string& key, bool bottom) const;
void render_prusa_shader(unsigned int vertices_count, bool transparent) const; void render_prusa_shader(bool transparent) const;
#else #else
void render_prusa(const std::string &key, float theta, bool useVBOs) const; void render_prusa(const std::string &key, float theta, bool useVBOs) const;
#endif // ENABLE_TEXTURES_FROM_SVG #endif // ENABLE_TEXTURES_FROM_SVG

View File

@ -225,6 +225,17 @@ bool GLShader::set_uniform(const char* name, const float* matrix) const
return false; return false;
} }
bool GLShader::set_uniform(const char* name, int value) const
{
int id = get_uniform_location(name);
if (id >= 0)
{
::glUniform1i(id, value);
return true;
}
return false;
}
/* /*
# Set shader vector # Set shader vector
sub SetVector sub SetVector
@ -306,6 +317,16 @@ void Shader::stop_using() const
m_shader->disable(); m_shader->disable();
} }
int Shader::get_attrib_location(const std::string& name) const
{
return (m_shader != nullptr) ? m_shader->get_attrib_location(name.c_str()) : -1;
}
int Shader::get_uniform_location(const std::string& name) const
{
return (m_shader != nullptr) ? m_shader->get_uniform_location(name.c_str()) : -1;
}
void Shader::set_uniform(const std::string& name, float value) const void Shader::set_uniform(const std::string& name, float value) const
{ {
if (m_shader != nullptr) if (m_shader != nullptr)
@ -321,7 +342,7 @@ void Shader::set_uniform(const std::string& name, const float* matrix) const
void Shader::set_uniform(const std::string& name, bool value) const void Shader::set_uniform(const std::string& name, bool value) const
{ {
if (m_shader != nullptr) if (m_shader != nullptr)
m_shader->set_uniform(name.c_str(), value); m_shader->set_uniform(name.c_str(), value ? 1 : 0);
} }
unsigned int Shader::get_shader_program_id() const unsigned int Shader::get_shader_program_id() const

View File

@ -26,6 +26,7 @@ public:
bool set_uniform(const char *name, float value) const; bool set_uniform(const char *name, float value) const;
bool set_uniform(const char* name, const float* matrix) const; bool set_uniform(const char* name, const float* matrix) const;
bool set_uniform(const char* name, int value) const;
void enable() const; void enable() const;
void disable() const; void disable() const;
@ -52,6 +53,9 @@ public:
bool start_using() const; bool start_using() const;
void stop_using() const; void stop_using() const;
int get_attrib_location(const std::string& name) const;
int get_uniform_location(const std::string& name) const;
void set_uniform(const std::string& name, float value) const; void set_uniform(const std::string& name, float value) const;
void set_uniform(const std::string& name, const float* matrix) const; void set_uniform(const std::string& name, const float* matrix) const;
void set_uniform(const std::string& name, bool value) const; void set_uniform(const std::string& name, bool value) const;

View File

@ -20,6 +20,8 @@
#include "nanosvg/nanosvgrast.h" #include "nanosvg/nanosvgrast.h"
#endif // ENABLE_TEXTURES_FROM_SVG #endif // ENABLE_TEXTURES_FROM_SVG
#include "libslic3r/Utils.hpp"
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {