mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-15 02:37:51 -06:00
Changed use of GL_LIGHTING logic and code cleanup
This commit is contained in:
parent
ac7d21b50a
commit
15c69a90ec
4 changed files with 7 additions and 71 deletions
|
@ -396,16 +396,10 @@ void GLVolume::render_using_layer_height() const
|
|||
GLsizei half_w = w / 2;
|
||||
GLsizei half_h = h / 2;
|
||||
|
||||
//#######################################################################################################################
|
||||
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
//#######################################################################################################################
|
||||
glBindTexture(GL_TEXTURE_2D, layer_height_texture_data.texture_id);
|
||||
//####################################################################################################################################################
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, half_w, half_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
// glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, half_w, half_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
//####################################################################################################################################################
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, layer_height_texture_data_ptr_level0());
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, half_w, half_h, GL_RGBA, GL_UNSIGNED_BYTE, layer_height_texture_data_ptr_level1());
|
||||
|
||||
|
@ -1587,23 +1581,12 @@ GUI::GLCanvas3DManager _3DScene::s_canvas_mgr;
|
|||
|
||||
unsigned int _3DScene::TextureBase::finalize()
|
||||
{
|
||||
//#######################################################################################################################
|
||||
if ((m_tex_id == 0) && !m_data.empty()) {
|
||||
// if (!m_data.empty()) {
|
||||
//#######################################################################################################################
|
||||
// sends buffer to gpu
|
||||
//#######################################################################################################################
|
||||
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
//#######################################################################################################################
|
||||
::glGenTextures(1, &m_tex_id);
|
||||
//#######################################################################################################################
|
||||
::glBindTexture(GL_TEXTURE_2D, (GLuint)m_tex_id);
|
||||
// ::glBindTexture(GL_TEXTURE_2D, m_tex_id);
|
||||
//#######################################################################################################################
|
||||
//#######################################################################################################################
|
||||
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_tex_width, (GLsizei)m_tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)m_data.data());
|
||||
// ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_tex_width, (GLsizei)m_tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)m_data.data());
|
||||
//#######################################################################################################################
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
|
||||
|
|
|
@ -498,10 +498,8 @@ void GLCanvas3D::Bed::_render_prusa(float theta) const
|
|||
::glEnable(GL_BLEND);
|
||||
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//#######################################################################################################################
|
||||
::glEnable(GL_TEXTURE_2D);
|
||||
::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
//#######################################################################################################################
|
||||
|
||||
::glEnableClientState(GL_VERTEX_ARRAY);
|
||||
::glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
@ -509,9 +507,6 @@ void GLCanvas3D::Bed::_render_prusa(float theta) const
|
|||
if (theta > 90.0f)
|
||||
::glFrontFace(GL_CW);
|
||||
|
||||
//#######################################################################################################################
|
||||
// ::glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
//#######################################################################################################################
|
||||
::glBindTexture(GL_TEXTURE_2D, (theta <= 90.0f) ? (GLuint)m_top_texture.get_id() : (GLuint)m_bottom_texture.get_id());
|
||||
::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_triangles.get_vertices());
|
||||
::glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*)m_triangles.get_tex_coords());
|
||||
|
@ -524,9 +519,7 @@ void GLCanvas3D::Bed::_render_prusa(float theta) const
|
|||
::glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
::glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
//#######################################################################################################################
|
||||
::glDisable(GL_TEXTURE_2D);
|
||||
//#######################################################################################################################
|
||||
|
||||
::glDisable(GL_BLEND);
|
||||
}
|
||||
|
@ -566,6 +559,7 @@ void GLCanvas3D::Bed::_render_custom() const
|
|||
::glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
::glDisable(GL_BLEND);
|
||||
::glDisable(GL_LIGHTING);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -590,7 +584,6 @@ GLCanvas3D::Axes::Axes()
|
|||
|
||||
void GLCanvas3D::Axes::render(bool depth_test) const
|
||||
{
|
||||
::glDisable(GL_LIGHTING);
|
||||
if (depth_test)
|
||||
::glEnable(GL_DEPTH_TEST);
|
||||
else
|
||||
|
@ -636,7 +629,6 @@ bool GLCanvas3D::CuttingPlane::set(float z, const ExPolygons& polygons)
|
|||
|
||||
void GLCanvas3D::CuttingPlane::render(const BoundingBoxf3& bb) const
|
||||
{
|
||||
::glDisable(GL_LIGHTING);
|
||||
_render_plane(bb);
|
||||
_render_contour();
|
||||
}
|
||||
|
@ -990,16 +982,10 @@ void GLCanvas3D::LayersEditing::_render_active_object_annotations(const GLCanvas
|
|||
GLsizei half_w = w / 2;
|
||||
GLsizei half_h = h / 2;
|
||||
|
||||
//#######################################################################################################################
|
||||
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
//#######################################################################################################################
|
||||
::glBindTexture(GL_TEXTURE_2D, m_z_texture_id);
|
||||
//####################################################################################################################################################
|
||||
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
::glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, half_w, half_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
// ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
// ::glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, half_w, half_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
//####################################################################################################################################################
|
||||
::glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, volume.layer_height_texture_data_ptr_level0());
|
||||
::glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, half_w, half_h, GL_RGBA, GL_UNSIGNED_BYTE, volume.layer_height_texture_data_ptr_level1());
|
||||
|
||||
|
@ -1570,10 +1556,6 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl)
|
|||
if (m_gizmos.is_enabled() && !m_gizmos.init())
|
||||
return false;
|
||||
|
||||
//#######################################################################################################################
|
||||
// ::glEnable(GL_TEXTURE_2D);
|
||||
//#######################################################################################################################
|
||||
|
||||
m_initialized = true;
|
||||
|
||||
return true;
|
||||
|
@ -3411,7 +3393,6 @@ void GLCanvas3D::_picking_pass() const
|
|||
if (m_multisample_allowed)
|
||||
::glDisable(GL_MULTISAMPLE);
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glDisable(GL_BLEND);
|
||||
|
||||
::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -3467,8 +3448,6 @@ void GLCanvas3D::_render_background() const
|
|||
|
||||
static const float COLOR[3] = { 10.0f / 255.0f, 98.0f / 255.0f, 144.0f / 255.0f };
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
|
||||
::glPushMatrix();
|
||||
::glLoadIdentity();
|
||||
::glMatrixMode(GL_PROJECTION);
|
||||
|
@ -3547,6 +3526,8 @@ void GLCanvas3D::_render_objects() const
|
|||
if (m_picking_enabled)
|
||||
::glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void GLCanvas3D::_render_cutting_plane() const
|
||||
|
@ -3655,9 +3636,7 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const
|
|||
{
|
||||
static const GLfloat INV_255 = 1.0f / 255.0f;
|
||||
|
||||
if (fake_colors)
|
||||
::glDisable(GL_LIGHTING);
|
||||
else
|
||||
if (!fake_colors)
|
||||
::glEnable(GL_LIGHTING);
|
||||
|
||||
// do not cull backfaces to show broken geometry, if any
|
||||
|
@ -3695,6 +3674,9 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const
|
|||
::glDisable(GL_BLEND);
|
||||
|
||||
::glEnable(GL_CULL_FACE);
|
||||
|
||||
if (!fake_colors)
|
||||
::glDisable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void GLCanvas3D::_render_gizmo() const
|
||||
|
|
|
@ -222,7 +222,6 @@ void GLGizmoRotate::on_update(const Pointf& mouse_pos)
|
|||
|
||||
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
const Pointf3& size = box.size();
|
||||
|
@ -244,7 +243,6 @@ void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
|||
|
||||
void GLGizmoRotate::on_render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
m_grabbers[0].color[0] = 1.0f;
|
||||
|
@ -413,7 +411,6 @@ void GLGizmoScale::on_update(const Pointf& mouse_pos)
|
|||
|
||||
void GLGizmoScale::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
coordf_t min_x = box.min.x - (coordf_t)Offset;
|
||||
|
@ -452,7 +449,6 @@ void GLGizmoScale::on_render_for_picking(const BoundingBoxf3& box) const
|
|||
{
|
||||
static const GLfloat INV_255 = 1.0f / 255.0f;
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
|
|
|
@ -73,15 +73,10 @@ bool GLTexture::load_from_file(const std::string& filename, bool generate_mipmap
|
|||
|
||||
// sends data to gpu
|
||||
|
||||
//#######################################################################################################################
|
||||
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
//#######################################################################################################################
|
||||
::glGenTextures(1, &m_id);
|
||||
::glBindTexture(GL_TEXTURE_2D, m_id);
|
||||
//####################################################################################################################################################
|
||||
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
|
||||
// ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
|
||||
//####################################################################################################################################################
|
||||
if (generate_mipmaps)
|
||||
{
|
||||
// we manually generate mipmaps because glGenerateMipmap() function is not reliable on all graphics cards
|
||||
|
@ -134,21 +129,10 @@ const std::string& GLTexture::get_source() const
|
|||
|
||||
void GLTexture::render_texture(unsigned int tex_id, float left, float right, float bottom, float top)
|
||||
{
|
||||
//#######################################################################################################################
|
||||
// ::glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
//#######################################################################################################################
|
||||
|
||||
//#######################################################################################################################
|
||||
bool lighting_enabled = ::glIsEnabled(GL_LIGHTING);
|
||||
//#######################################################################################################################
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glEnable(GL_BLEND);
|
||||
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//#######################################################################################################################
|
||||
::glEnable(GL_TEXTURE_2D);
|
||||
::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
//#######################################################################################################################
|
||||
|
||||
::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id);
|
||||
|
||||
|
@ -161,14 +145,8 @@ void GLTexture::render_texture(unsigned int tex_id, float left, float right, flo
|
|||
|
||||
::glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
//#######################################################################################################################
|
||||
::glDisable(GL_TEXTURE_2D);
|
||||
//#######################################################################################################################
|
||||
::glDisable(GL_BLEND);
|
||||
//#######################################################################################################################
|
||||
if (lighting_enabled)
|
||||
//#######################################################################################################################
|
||||
::glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void GLTexture::_generate_mipmaps(wxImage& image)
|
||||
|
@ -203,10 +181,7 @@ void GLTexture::_generate_mipmaps(wxImage& image)
|
|||
data[data_id + 3] = (img_alpha != nullptr) ? img_alpha[i] : 255;
|
||||
}
|
||||
|
||||
//####################################################################################################################################################
|
||||
::glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
|
||||
// ::glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data());
|
||||
//####################################################################################################################################################
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue