Skip to content

Commit 9ca0118

Browse files
committed
implement weighted blended order independent transparency
1 parent 9b72023 commit 9ca0118

25 files changed

+683
-262
lines changed

src/appleseed.studio/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ set (utility_sources
365365
utility/doubleslider.h
366366
utility/foldablepanelwidget.cpp
367367
utility/foldablepanelwidget.h
368+
utility/gl.cpp
369+
utility/gl.h
368370
utility/inputwidgetproxies.cpp
369371
utility/inputwidgetproxies.h
370372
utility/interop.h

src/appleseed.studio/main/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ int main(int argc, char* argv[])
329329
// Set default surface format before creating application instance. This is
330330
// required on macOS in order to use an OpenGL Core profile context.
331331
QSurfaceFormat default_format;
332-
default_format.setVersion(3, 3);
332+
default_format.setVersion(4, 1);
333333
default_format.setProfile(QSurfaceFormat::CoreProfile);
334334
QSurfaceFormat::setDefaultFormat(default_format);
335335

src/appleseed.studio/mainwindow/rendering/glscenelayer.cpp

Lines changed: 8 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "glscenelayer.h"
3131

3232
// appleseed.studio headers.
33-
#include "utility/miscellaneous.h"
33+
#include "utility/gl.h"
3434

3535
// appleseed.renderer headers.
3636
#include "renderer/api/camera.h"
@@ -50,7 +50,7 @@
5050

5151
// Qt headers.
5252
#include <QKeyEvent>
53-
#include <QOpenGLFunctions_3_3_Core>
53+
#include <QOpenGLFunctions_4_1_Core>
5454
#include <QGLFormat>
5555
#include <QSurfaceFormat>
5656
#include <QString>
@@ -137,7 +137,12 @@ GLSceneLayer::GLSceneLayer(
137137
set_transform(m_camera.transform_sequence().evaluate(time));
138138
}
139139

140-
void GLSceneLayer::set_gl_functions(QOpenGLFunctions_3_3_Core* functions)
140+
GLSceneLayer::~GLSceneLayer()
141+
{
142+
cleanup_gl_data();
143+
}
144+
145+
void GLSceneLayer::set_gl_functions(QOpenGLFunctions_4_1_Core* functions)
141146
{
142147
m_gl = functions;
143148
}
@@ -364,100 +369,6 @@ void GLSceneLayer::load_scene_data()
364369
load_assembly_instance(assembly_instance, time);
365370
}
366371

367-
namespace {
368-
const string shader_kind_to_string(const GLint shader_kind)
369-
{
370-
switch (shader_kind) {
371-
case GL_VERTEX_SHADER:
372-
return "Vertex";
373-
case GL_FRAGMENT_SHADER:
374-
return "Fragment";
375-
default:
376-
return "Unknown Kind";
377-
}
378-
}
379-
380-
void compile_shader(
381-
QOpenGLFunctions_3_3_Core* f,
382-
const GLuint shader,
383-
const GLsizei count,
384-
const GLchar** src_string,
385-
const GLint* length)
386-
{
387-
f->glShaderSource(shader, count, src_string, length);
388-
f->glCompileShader(shader);
389-
GLint success;
390-
f->glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
391-
392-
if (!success)
393-
{
394-
char info_log[1024];
395-
f->glGetShaderInfoLog(shader, 1024, NULL, info_log);
396-
397-
GLint shader_kind;
398-
f->glGetShaderiv(shader, GL_SHADER_TYPE, &shader_kind);
399-
string shader_kind_string = shader_kind_to_string(shader_kind);
400-
401-
RENDERER_LOG_ERROR("opengl: %s shader compilation failed:\n%s", shader_kind_string.c_str(), info_log);
402-
}
403-
}
404-
405-
void link_shader_program(
406-
QOpenGLFunctions_3_3_Core* f,
407-
const GLuint program,
408-
const GLuint vert,
409-
const GLuint frag)
410-
{
411-
f->glAttachShader(program, vert);
412-
413-
if (frag != 0)
414-
f->glAttachShader(program, frag);
415-
416-
f->glLinkProgram(program);
417-
418-
GLint success;
419-
f->glGetProgramiv(program, GL_LINK_STATUS, &success);
420-
421-
if (!success)
422-
{
423-
char info_log[1024];
424-
f->glGetProgramInfoLog(program, 1024, NULL, info_log);
425-
RENDERER_LOG_ERROR("opengl: shader program linking failed:\n%s", info_log);
426-
}
427-
}
428-
429-
void create_shader_program(
430-
QOpenGLFunctions_3_3_Core* f,
431-
GLuint& program,
432-
const QByteArray* vert_source,
433-
const QByteArray* frag_source)
434-
{
435-
bool has_frag_shader = frag_source != nullptr;
436-
437-
GLuint vert = f->glCreateShader(GL_VERTEX_SHADER);
438-
GLuint frag = has_frag_shader ? f->glCreateShader(GL_FRAGMENT_SHADER) : 0;
439-
440-
auto gl_vert_source = static_cast<const GLchar*>(vert_source->constData());
441-
auto gl_vert_source_length = static_cast<const GLint>(vert_source->size());
442-
443-
compile_shader(f, vert, 1, &gl_vert_source, &gl_vert_source_length);
444-
445-
if (has_frag_shader)
446-
{
447-
auto gl_frag_source = static_cast<const GLchar*>(frag_source->constData());
448-
auto gl_frag_source_length = static_cast<const GLint>(frag_source->size());
449-
compile_shader(f, frag, 1, &gl_frag_source, &gl_frag_source_length);
450-
}
451-
452-
program = f->glCreateProgram();
453-
link_shader_program(f, program, vert, frag);
454-
455-
f->glDeleteShader(vert);
456-
if (has_frag_shader)
457-
f->glDeleteShader(frag);
458-
}
459-
}
460-
461372
void GLSceneLayer::init_gl(QSurfaceFormat format)
462373
{
463374
// If there was already previous data, clean up

src/appleseed.studio/mainwindow/rendering/glscenelayer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace renderer { class ObjectInstance; }
5858
namespace renderer { class Project; }
5959
class QKeyEvent;
6060
class QImage;
61-
class QOpenGLFunctions_3_3_Core;
61+
class QOpenGLFunctions_4_1_Core;
6262
class QSurfaceFormat;
6363

6464
namespace appleseed {
@@ -79,14 +79,16 @@ class GLSceneLayer
7979
const size_t width,
8080
const size_t height);
8181

82+
~GLSceneLayer();
83+
8284
void init_gl(
8385
QSurfaceFormat format);
8486

8587
void set_transform(
8688
const foundation::Transformd& transform);
8789

8890
void set_gl_functions(
89-
QOpenGLFunctions_3_3_Core* functions);
91+
QOpenGLFunctions_4_1_Core* functions);
9092

9193
void draw();
9294
void draw_depth_only();
@@ -103,7 +105,7 @@ class GLSceneLayer
103105

104106
bool m_backface_culling_enabled;
105107

106-
QOpenGLFunctions_3_3_Core* m_gl;
108+
QOpenGLFunctions_4_1_Core* m_gl;
107109

108110
std::vector<GLuint> m_scene_object_data_vbos;
109111
std::vector<GLsizei> m_scene_object_data_index_counts;
@@ -125,7 +127,6 @@ class GLSceneLayer
125127
bool m_initialized;
126128

127129
void render_scene();
128-
129130
void cleanup_gl_data();
130131
void load_scene_data();
131132

src/appleseed.studio/mainwindow/rendering/lightpathslayer.cpp

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "lightpathslayer.h"
3131

3232
// appleseed.studio headers.
33-
#include "utility/miscellaneous.h"
33+
#include "utility/gl.h"
3434

3535
// appleseed.renderer headers.
3636
#include "renderer/api/camera.h"
@@ -50,7 +50,7 @@
5050

5151
// Qt headers.
5252
#include <QKeyEvent>
53-
#include <QOpenGLFunctions_3_3_Core>
53+
#include <QOpenGLFunctions_4_1_Core>
5454
#include <QSurfaceFormat>
5555
#include <QString>
5656

@@ -105,7 +105,7 @@ void LightPathsLayer::resize(const size_t width, const size_t height)
105105
m_height = height;
106106
}
107107

108-
void LightPathsLayer::set_gl_functions(QOpenGLFunctions_3_3_Core* functions)
108+
void LightPathsLayer::set_gl_functions(QOpenGLFunctions_4_1_Core* functions)
109109
{
110110
m_gl = functions;
111111
}
@@ -341,91 +341,6 @@ void LightPathsLayer::load_light_paths_data()
341341
}
342342
}
343343

344-
namespace {
345-
const string shader_kind_to_string(const GLint shader_kind)
346-
{
347-
switch (shader_kind) {
348-
case GL_VERTEX_SHADER:
349-
return "Vertex";
350-
case GL_FRAGMENT_SHADER:
351-
return "Fragment";
352-
default:
353-
return "Unknown Kind";
354-
}
355-
}
356-
357-
void compile_shader(
358-
QOpenGLFunctions_3_3_Core* f,
359-
const GLuint shader,
360-
const GLsizei count,
361-
const GLchar** src_string,
362-
const GLint* length)
363-
{
364-
f->glShaderSource(shader, count, src_string, length);
365-
f->glCompileShader(shader);
366-
GLint success;
367-
f->glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
368-
369-
if (!success)
370-
{
371-
char info_log[1024];
372-
f->glGetShaderInfoLog(shader, 1024, NULL, info_log);
373-
374-
GLint shader_kind;
375-
f->glGetShaderiv(shader, GL_SHADER_TYPE, &shader_kind);
376-
string shader_kind_string = shader_kind_to_string(shader_kind);
377-
378-
RENDERER_LOG_ERROR("opengl: %s shader compilation failed:\n%s", shader_kind_string.c_str(), info_log);
379-
}
380-
}
381-
382-
void link_shader_program(
383-
QOpenGLFunctions_3_3_Core* f,
384-
const GLuint program,
385-
const GLuint vert,
386-
const GLuint frag)
387-
{
388-
f->glAttachShader(program, vert);
389-
f->glAttachShader(program, frag);
390-
f->glLinkProgram(program);
391-
392-
GLint success;
393-
f->glGetProgramiv(program, GL_LINK_STATUS, &success);
394-
395-
if (!success)
396-
{
397-
char info_log[1024];
398-
f->glGetProgramInfoLog(program, 1024, NULL, info_log);
399-
RENDERER_LOG_ERROR("opengl: shader program linking failed:\n%s", info_log);
400-
}
401-
}
402-
403-
void create_shader_program(
404-
QOpenGLFunctions_3_3_Core* f,
405-
GLuint& program,
406-
const QByteArray& vert_source,
407-
const QByteArray& frag_source)
408-
{
409-
GLuint vert = f->glCreateShader(GL_VERTEX_SHADER);
410-
GLuint frag = f->glCreateShader(GL_FRAGMENT_SHADER);
411-
412-
auto gl_vert_source = static_cast<const GLchar*>(vert_source.constData());
413-
auto gl_vert_source_length = static_cast<const GLint>(vert_source.size());
414-
415-
auto gl_frag_source = static_cast<const GLchar*>(frag_source.constData());
416-
auto gl_frag_source_length = static_cast<const GLint>(frag_source.size());
417-
418-
compile_shader(f, vert, 1, &gl_vert_source, &gl_vert_source_length);
419-
compile_shader(f, frag, 1, &gl_frag_source, &gl_frag_source_length);
420-
421-
program = f->glCreateProgram();
422-
link_shader_program(f, program, vert, frag);
423-
424-
f->glDeleteShader(vert);
425-
f->glDeleteShader(frag);
426-
}
427-
}
428-
429344
void LightPathsLayer::init_gl(QSurfaceFormat format)
430345
{
431346
// If there was already previous data, clean up
@@ -441,8 +356,8 @@ void LightPathsLayer::init_gl(QSurfaceFormat format)
441356
create_shader_program(
442357
m_gl,
443358
m_shader_program,
444-
vertex_shader,
445-
fragment_shader);
359+
&vertex_shader,
360+
&fragment_shader);
446361

447362
m_view_mat_loc = m_gl->glGetUniformLocation(m_shader_program, "u_view");
448363
m_proj_mat_loc = m_gl->glGetUniformLocation(m_shader_program, "u_proj");
@@ -586,20 +501,14 @@ void LightPathsLayer::draw_render_camera() const
586501
{
587502
auto gl_view_matrix = const_cast<const GLfloat*>(&m_gl_render_view_matrix[0]);
588503

589-
m_gl->glEnable(GL_BLEND);
590-
m_gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
591504
render_scene(gl_view_matrix);
592-
m_gl->glDisable(GL_BLEND);
593505
}
594506

595507
void LightPathsLayer::draw() const
596508
{
597509
auto gl_view_matrix = const_cast<const GLfloat*>(&m_gl_view_matrix[0]);
598510

599-
m_gl->glEnable(GL_BLEND);
600-
m_gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
601511
render_scene(gl_view_matrix);
602-
m_gl->glDisable(GL_BLEND);
603512
}
604513

605514
void LightPathsLayer::render_scene(const GLfloat* gl_view_matrix) const

src/appleseed.studio/mainwindow/rendering/lightpathslayer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace renderer { class ObjectInstance; }
5858
namespace renderer { class Project; }
5959
class QKeyEvent;
6060
class QImage;
61-
class QOpenGLFunctions_3_3_Core;
61+
class QOpenGLFunctions_4_1_Core;
6262

6363
namespace appleseed {
6464
namespace studio {
@@ -91,7 +91,7 @@ class LightPathsLayer: public QObject
9191
const int selected_light_path_index);
9292

9393
void set_gl_functions(
94-
QOpenGLFunctions_3_3_Core* functions);
94+
QOpenGLFunctions_4_1_Core* functions);
9595

9696
void init_gl(QSurfaceFormat format);
9797

@@ -127,7 +127,7 @@ class LightPathsLayer: public QObject
127127
size_t m_width;
128128
size_t m_height;
129129

130-
QOpenGLFunctions_3_3_Core* m_gl;
130+
QOpenGLFunctions_4_1_Core* m_gl;
131131

132132
GLuint m_positions_vbo;
133133
GLuint m_others_vbo;

0 commit comments

Comments
 (0)