AdamYuan / SparseVoxelOctree

A GPU SVO Builder using rasterization pipeline, a efficient SVO ray marcher and a simple SVO path tracer.
MIT License
604 stars 54 forks source link

Error when building in VS2019 #4

Closed trsh closed 4 years ago

trsh commented 4 years ago

Severity Code Description Project File Line Suppression State Error C1091 compiler limit: string exceeds 65535 bytes in length SparseVoxelOctree C:\Projects\vox\SparseVoxelOctree\dep\imgui\imgui_draw.cpp 3777

AdamYuan commented 4 years ago

Using Clang compiler can avoid this problem.

trsh commented 4 years ago

How can I set that VS 2019?

AdamYuan commented 4 years ago

https://devblogs.microsoft.com/cppblog/clang-llvm-support-in-visual-studio/

trsh commented 4 years ago

It compiled. I tried to load crytek sponza obj as scene. No errors, but screen is just black :/

AdamYuan commented 4 years ago

could you show the console output

AdamYuan commented 4 years ago

what is your graphics card?

trsh commented 4 years ago

GTX750ti 4gb

trsh commented 4 years ago
WARN: Both `d` and `Tr` parameters defined for "leaf". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "vase_round". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "Material__57". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "Material__298". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "bricks". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "arch". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "ceiling". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "column_a". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "floor". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "column_c". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "details". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "column_b". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "Material__47". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "flagpole". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "fabric_e". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "fabric_d". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "fabric_a". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "fabric_g". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "fabric_c". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "fabric_f". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "chain". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "vase_hanging". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "vase". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "Material__25". Use the value of `d` for dissolve.
WARN: Both `d` and `Tr` parameters defined for "roof". Use the value of `d` for dissolve.

[SCENE]Info: 25 meshes loaded from C:\Users\trsh\Downloads\sponza\sponza.obj
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_thorn_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\vase_round.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\vase_plant.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\background.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\spnza_bricks_a_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_arch_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_ceiling_a_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_column_a_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_floor_a_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_column_c_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_details_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_column_b_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_flagpole_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_fabric_green_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_fabric_blue_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_fabric_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_curtain_blue_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_curtain_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_curtain_green_diff.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\chain_texture.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\vase_hanging.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\vase_dif.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\lion.png
[SCENE]Info: Loaded texture C:\Users\trsh\Downloads\sponza\textures\sponza_roof_diff.png
[VOXELIZER]Info: Created fragment buffer with 10869384 voxels, 87.0 MB
[VOXELIZER]Info: Fragment buffer filled, in 200.309440 ms.
[OCTREE]Info: Alloc 43477536 nodes, 173.9MB
[OCTREE]Info: Building complete, in 381.923872 ms.
trsh commented 4 years ago

Mkay

AdamYuan commented 4 years ago

that is wierd, the octree is successfully built. Could you change PRIMARY VIEW to ITERATION and post a screenshots

trsh commented 4 years ago

Untitled

AdamYuan commented 4 years ago

that is too wierd :( . I tested it on windows with GTX 840m and it worked fine... I will try to figure it out sometime tomorrow .. (at school now)

AdamYuan commented 4 years ago

Screenshot_2020-01-13_11-55-12

Could you see a red screen like this when replacing "shaders/octreetracer.frag" with the following and recompile it_

#version 450 core
out vec4 oFragColor;
void main() {
    oFragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
}
AdamYuan commented 4 years ago

If there is a red screen, could you replace "src/OctreeBuilder.cpp" with the following and show the console output ?

#include "OctreeBuilder.hpp"
#include "Config.hpp"
#include "OglBindings.hpp"
#include "ShaderSrc.hpp"
#include <algorithm>

struct DispatchIndirectCommand {
    GLuint num_groups_x, num_groups_y, num_groups_z;
};
struct BuildInfo {
    GLuint fragment_num, voxel_resolution, alloc_begin, alloc_num;
};

inline static GLuint group_x_64(unsigned x) { return (x >> 6u) + ((x & 0x3fu) ? 1u : 0u); }

void OctreeBuilder::Initialize()
{
    m_tag_node_shader.Initialize();
    m_tag_node_shader.Load(kOctreeTagNodeCompStr, GL_COMPUTE_SHADER);

    m_alloc_node_shader.Initialize();
    m_alloc_node_shader.Load(kOctreeAllocNodeCompStr, GL_COMPUTE_SHADER);

    m_modify_arg_shader.Initialize();
    m_modify_arg_shader.Load(kOctreeModifyArgCompStr, GL_COMPUTE_SHADER);

    m_counter.Initialize();

    m_alloc_indirect_buffer.Initialize();
    m_alloc_indirect_buffer.Storage(sizeof(DispatchIndirectCommand), GL_MAP_WRITE_BIT);

    m_build_info_buffer.Initialize();
    m_build_info_buffer.Storage(sizeof(BuildInfo), GL_MAP_WRITE_BIT);
}

void OctreeBuilder::Build(Octree *octree, const Voxelizer &voxelizer, int octree_level)
{
    //set properties
    octree->m_octree_level = octree_level;

    //set alloc node indirect buffer
    DispatchIndirectCommand *cmd_map;
    cmd_map = (DispatchIndirectCommand *)
            glMapNamedBufferRange(m_alloc_indirect_buffer.Get(), 0,
                                  sizeof(DispatchIndirectCommand), GL_MAP_WRITE_BIT);
    cmd_map->num_groups_x = 0;
    cmd_map->num_groups_y = cmd_map->num_groups_z = 1;
    glUnmapNamedBuffer(m_alloc_indirect_buffer.Get());

    //set initial info buffer
    BuildInfo *info_map;
    info_map = (BuildInfo *)
            glMapNamedBufferRange(m_build_info_buffer.Get(), 0,
                                  sizeof(BuildInfo), GL_MAP_WRITE_BIT);
    info_map->fragment_num = voxelizer.GetFragmentNum();
    info_map->voxel_resolution = 1u << (GLuint)octree_level;
    info_map->alloc_begin = info_map->alloc_num = 0;
    glUnmapNamedBuffer(m_build_info_buffer.Get());

    //estimate octree buffer size and initialize octree buffer
    int octree_node_num = std::max(kOctreeNodeNumMin, voxelizer.GetFragmentNum() << 2);
    octree_node_num = std::min(octree_node_num, kOctreeNodeNumMax);
    octree->m_octree_buffer.Initialize();
    octree->m_octree_buffer.Storage(octree_node_num * sizeof(GLuint), GL_MAP_WRITE_BIT | GL_MAP_READ_BIT);

    printf("[OCTREE]Info: Alloc %d nodes, %.1fMB\n",
           octree_node_num, octree->m_octree_buffer.GetByteCount() / 1000000.0f);

    //clear the octree buffer
    GLuint *octree_map;
    octree_map = (GLuint *)
            glMapNamedBufferRange(octree->m_octree_buffer.Get(), 0, octree_node_num*sizeof(GLuint), GL_MAP_WRITE_BIT);
    std::fill(octree_map, octree_map + octree_node_num, 0u);
    glUnmapNamedBuffer(octree->m_octree_buffer.Get());

    //reset atomic counter
    m_counter.Reset();

    //bind buffers
    voxelizer.GetFragmentList().BindBase(GL_SHADER_STORAGE_BUFFER, kVoxelFragmentListSSBO);
    octree->m_octree_buffer.BindBase(GL_SHADER_STORAGE_BUFFER, kOctreeSSBO);
    m_alloc_indirect_buffer.BindBase(GL_SHADER_STORAGE_BUFFER, kOctreeAllocIndirectSSBO);
    m_alloc_indirect_buffer.Bind(GL_DISPATCH_INDIRECT_BUFFER);
    m_build_info_buffer.BindBase(GL_SHADER_STORAGE_BUFFER, kOctreeBuildInfoSSBO);
    m_counter.BindAtomicCounter(kAtomicCounterBinding);

    GLuint frag_list_group_x = group_x_64(voxelizer.GetFragmentNum());

    GLuint time_query; glGenQueries(1, &time_query);
    glBeginQuery(GL_TIME_ELAPSED, time_query);
    for(int cur = 1; cur <= octree_level; ++cur)
    {
        m_tag_node_shader.Use();
        glDispatchCompute(frag_list_group_x, 1, 1);
        glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

        if(cur != octree_level) //the last octree level doesn't has leaves
        {
            m_modify_arg_shader.Use();
            glDispatchCompute(1, 1, 1);
            glMemoryBarrier(GL_SHADER_STORAGE_BUFFER | GL_COMMAND_BARRIER_BIT);

            m_alloc_node_shader.Use();
            glDispatchComputeIndirect(0);
            glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_ATOMIC_COUNTER_BARRIER_BIT);
        }
    }
    glEndQuery(GL_TIME_ELAPSED);

    GLint done = 0; while(!done)
        glGetQueryObjectiv(time_query, GL_QUERY_RESULT_AVAILABLE, &done);
    GLuint64 time_elapsed;
    glGetQueryObjectui64v(time_query, GL_QUERY_RESULT, &time_elapsed);
    glDeleteQueries(1, &time_query);

    unsigned cnt_val = m_counter.SyncAndGetValue();

    octree_map = (GLuint *)
            glMapNamedBufferRange(octree->m_octree_buffer.Get(), 0, octree_node_num*sizeof(GLuint), GL_MAP_READ_BIT);
    for(int i = 0; i < 32; ++i)
        printf("%d %d %d\n", octree_map[i] >> 31u, (octree_map[i] >> 30u) & 1u, octree_map[i] & 0x3fffffffu);
    int lst = int(cnt_val + 1) * 8;
    for(int i = lst - 32; i < lst; ++i)
        printf("%d %d %d\n", octree_map[i] >> 31u, (octree_map[i] >> 30u) & 1u, octree_map[i] & 0x3fffffffu);
    glUnmapNamedBuffer(octree->m_octree_buffer.Get());

    printf("[OCTREE]Info: Building complete, in %f ms, used %.1f MB.\n",
           time_elapsed / 1000000.0, float(cnt_val + 1u) * 32u / 1000000.0f);
}
trsh commented 4 years ago

There isn't a red screen :/

trsh commented 4 years ago

Log when changing the file:

[VOXELIZER]Info: Created fragment buffer with 10869384 voxels, 87.0 MB
[VOXELIZER]Info: Fragment buffer filled, in 199.576992 ms.
[OCTREE]Info: Alloc 43477536 nodes, 173.9MB
1 0 8
1 0 16
1 0 24
1 0 32
1 0 40
1 0 48
1 0 56
1 0 64
0 0 0
0 0 0
1 0 72
1 0 80
0 0 0
0 0 0
1 0 88
1 0 96
0 0 0
0 0 0
1 0 104
1 0 112
0 0 0
0 0 0
1 0 120
1 0 128
1 0 136
1 0 144
0 0 0
0 0 0
1 0 152
1 0 160
0 0 0
0 0 0
1 1 24610957
1 1 24939923
1 1 25071251
1 1 25334421
0 0 0
0 0 0
0 0 0
0 0 0
1 1 24939922
1 1 24939666
1 1 25202835
1 1 24939921
0 0 0
0 0 0
0 0 0
0 0 0
1 1 24939407
1 1 25071250
1 1 24939407
1 1 24939664
0 0 0
0 0 0
0 0 0
0 0 0
1 1 25268627
1 1 25005200
1 1 25070992
1 1 25005200
0 0 0
0 0 0
0 0 0
0 0 0
[OCTREE]Info: Building complete, in 385.752832 ms, used 92.3 MB.
AdamYuan commented 4 years ago

I see, definitely the octree is correctly built, there must be something wrong with the shader..

AdamYuan commented 4 years ago

Could you post part of the console output after replacing the 2 files: src/ScreenQuad.cpp

#include "ScreenQuad.hpp"
#include "Config.hpp"
#include <cstdio>

void ScreenQuad::Initialize()
{
    constexpr GLfloat quad_vertices[] { -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f,
                                        1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f };
    m_vbo.Initialize();
    m_vbo.Storage(quad_vertices, quad_vertices + 12, 0);

    m_vao.Initialize();
    glEnableVertexArrayAttrib(m_vao.Get(), 0);
    glVertexArrayAttribFormat(m_vao.Get(), 0, 2, GL_FLOAT, GL_FALSE, 0);
    glVertexArrayAttribBinding(m_vao.Get(), 0, 0);
    glVertexArrayVertexBuffer(m_vao.Get(), 0, m_vbo.Get(), 0, 2 * sizeof(GLfloat));
}

void ScreenQuad::Render() const
{
    printf("QUAD BEGIN: %d\n", glGetError());
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    m_vao.Bind();
    glDrawArrays(GL_TRIANGLES, 0, 6);
    printf("QUAD END: %d\n", glGetError());
}

src/OctreeTracer.cpp

#include <glm/gtc/type_ptr.hpp>
#include "OctreeTracer.hpp"
#include "OglBindings.hpp"
#include "Config.hpp"
#include "ShaderSrc.hpp"

void OctreeTracer::Initialize()
{
    m_shader.Initialize();
    m_shader.Load(kQuadVertStr, GL_VERTEX_SHADER);
    m_shader.Load(kOctreeTracerFragStr, GL_FRAGMENT_SHADER);
    m_unif_view_type = m_shader.GetUniform("uViewType");
    m_unif_beam_enable = m_shader.GetUniform("uBeamEnable");

    m_beam_shader.Initialize();
    m_beam_shader.Load(kQuadVertStr, GL_VERTEX_SHADER);
    m_beam_shader.Load(kOctreeTracerBeamFragStr, GL_FRAGMENT_SHADER);
    m_beam_unif_dir_size = m_beam_shader.GetUniform("uDirSize");
    m_beam_unif_origin_size = m_beam_shader.GetUniform("uOriginSize");

    m_beam_tex.Initialize();
    m_beam_tex.Storage(kBeamWidth, kBeamHeight, GL_R32F);
    m_beam_tex.SetSizeFilter(GL_NEAREST, GL_NEAREST);
    m_beam_tex.SetWrapFilter(GL_CLAMP_TO_EDGE);

    m_beam_fbo.Initialize();
    m_beam_fbo.AttachTexture2D(m_beam_tex, GL_COLOR_ATTACHMENT0);
}

void OctreeTracer::Render(const ScreenQuad &quad, const Octree &octree, const Camera &camera)
{
    printf("OCTREE_RENDER BEGIN: %d\n", glGetError());
    camera.GetBuffer().BindBase(GL_UNIFORM_BUFFER, kCameraUBO);
    octree.GetOctreeBuffer().BindBase(GL_SHADER_STORAGE_BUFFER, kOctreeSSBO);

    if(m_beam_enable)
    {
        //perform beam optimization
        glViewport(0, 0, kBeamWidth, kBeamHeight);
        m_beam_fbo.Bind();
        m_beam_shader.Use();
        m_beam_shader.SetFloat(m_beam_unif_dir_size, m_beam_dir_size);
        m_beam_shader.SetFloat(m_beam_unif_origin_size, m_beam_origin_size);
        quad.Render();
        mygl3::FrameBuffer::Unbind();
    }

    //trace primary ray
    glViewport(0, 0, kWidth, kHeight);
    m_beam_tex.Bind(kBeamSampler2D);
    m_shader.Use();
    m_shader.SetInt(m_unif_view_type, (GLint)m_view_type);
    m_shader.SetInt(m_unif_beam_enable, (GLint)m_beam_enable);
    quad.Render();

    printf("OCTREE_RENDER END: %d\n", glGetError());
}
trsh commented 4 years ago
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0
OCTREE_RENDER BEGIN: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
OCTREE_RENDER END: 0

Continuously

AdamYuan commented 4 years ago

ok, it seems to be a black screen with totally no OpenGL error...... I will do furthur tests when I have access to the windows laptop...... There should be some stupid mistakes.....

AdamYuan commented 4 years ago

Can this executable work: http://adamyuan.xyz/SparseVoxelOctree.exe

trsh commented 4 years ago

Same! Black screen

AdamYuan commented 4 years ago

Can you see a red screen if you replace src/Application.cpp with:

//
// Created by adamyuan on 19-5-3.
//

#include <cstdio>
#include <tinyfiledialogs/tinyfiledialogs.h>
#include <imgui/imgui.h>
#include <imgui/imgui_impl_opengl3.h>
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_internal.h>
#include "Scene.hpp"
#include "Voxelizer.hpp"
#include "Application.hpp"
#include "Config.hpp"
#include "OctreeBuilder.hpp"

constexpr size_t kFilenameBufSize = 512;

Application::Application()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
    m_window = glfwCreateWindow(kWidth, kHeight, "SparseVoxelOctree", nullptr, nullptr);
    if (m_window == nullptr) {
        printf("[APPLICATION]Failed to load glfw.");
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(m_window);
    glfwSetWindowUserPointer(m_window, (void*)this);
    glfwSetKeyCallback(m_window, glfw_key_callback);

    gl3wInit();

    m_quad.Initialize();
    m_camera.Initialize();
    m_camera.m_position = glm::vec3(1.5f);
    m_octree_tracer.Initialize();
    m_pathtracer.Initialize();

    //Initialize ImGui
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGui::StyleColorsDarcula();

    ImGui_ImplGlfw_InitForOpenGL(m_window, true);
    ImGui_ImplOpenGL3_Init("#version 450 core");
}

void Application::LoadScene(const char *filename, int octree_level)
{
    /*if(octree_level < kOctreeLevelMin || octree_level > kOctreeLevelMax) return;

    Scene scene;
    if( scene.Initialize(filename) )
    {
        Voxelizer voxelizer;
        voxelizer.Initialize(octree_level);
        voxelizer.Voxelize(scene);

        m_octree.reset( new Octree );
        OctreeBuilder builder;
        builder.Initialize();
        builder.Build(m_octree.get(), voxelizer, octree_level);
    }*/
}

Application::~Application()
{
    glfwDestroyWindow(m_window);
    glfwTerminate();
}

void Application::Run()
{
    mygl3::Shader red;
    red.Initialize();
    red.Load(R"(#version 450 core
layout (location = 0) in vec2 aPosition;
void main() { gl_Position = vec4(aPosition, 1.0, 1.0); }
)", GL_VERTEX_SHADER);
    red.Load(
            R"(
#version 450 core
out vec4 oFragColor;
void main() {
    oFragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
}
)", GL_FRAGMENT_SHADER);
    while(!glfwWindowShouldClose(m_window))
    {
        /*m_fps.Update();
        ImGui_ImplOpenGL3_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame();

        glClear(GL_COLOR_BUFFER_BIT);

        if(m_ui_display_flag) ui_main();

        if(m_octree)
        {
            if(m_pathtracing_flag)
                m_pathtracer.Render(m_quad);
            else
            {
                m_camera.Control(m_window, m_fps);
                m_camera.Update();

                m_octree_tracer.Render(m_quad, *m_octree, m_camera);
            }
        }

        ImGui::Render();
        ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());*/

        glViewport(0, 0, kWidth, kHeight);
        glClear(GL_COLOR_BUFFER_BIT);
        red.Use();
        m_quad.Render();

        glfwSwapBuffers(m_window);
        glfwPollEvents();
    }
}

void Application::ui_main()
{
    ui_main_menubar();
    ui_info_overlay();
}

void Application::ui_push_disable()
{
    ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
    ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
}

void Application::ui_pop_disable()
{
    ImGui::PopItemFlag();
    ImGui::PopStyleVar();
}

void Application::ui_info_overlay()
{
    ImGui::SetNextWindowPos(ImVec2(10.0f, ImGui::GetIO().DisplaySize.y - 10.0f),
                            ImGuiCond_Always, ImVec2(0, 1));
    ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.0f, 0.0f, 0.4f)); // Transparent background
    if (ImGui::Begin("INFO", nullptr,
                     ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize
                     |ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove
                     |ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_NoBringToFrontOnFocus))
    {
        ImGui::Text("Toggle UI display with [X]");
        ImGui::Text("Renderer: %s", glGetString(GL_RENDERER));
        ImGui::Text("OpenGL version: %s", glGetString(GL_VERSION));
        ImGui::Text("FPS: %f", m_fps.GetFps());

        if(m_octree)
            ImGui::Text("Octree Level: %d", m_octree->GetLevel());

        if(m_pathtracing_flag)
            ImGui::Text("SPP: %d", m_pathtracer.GetSPP());

        ImGui::End();
    }
    ImGui::PopStyleColor();
}

void Application::ui_main_menubar()
{
    bool open_load_scene_popup = false, open_export_exr_popup = false;

    ImGui::BeginMainMenuBar();

    if(! m_pathtracing_flag)
    {
        if(ImGui::Button("Load Scene"))
            open_load_scene_popup = true;

        if(m_octree && ImGui::Button("Start PT"))
        {
            m_pathtracing_flag = true;
            m_pathtracer.Prepare(m_camera, *m_octree, m_octree_tracer);
        }

        if(ImGui::BeginMenu("Camera"))
        {
            ImGui::DragAngle("FOV", &m_camera.m_fov, 1, 10, 180);
            ImGui::DragFloat("Speed", &m_camera.m_speed, 0.005f, 0.005f, 0.2f);
            ImGui::InputFloat3("Position", &m_camera.m_position[0]);
            ImGui::DragAngle("Yaw", &m_camera.m_yaw, 1, 0, 360);
            ImGui::DragAngle("Pitch", &m_camera.m_pitch, 1, -90, 90);
            ImGui::EndMenu();
        }

        if(ImGui::BeginMenu("Primary View"))
        {
            if(ImGui::MenuItem("Diffuse", nullptr, m_octree_tracer.m_view_type == OctreeTracer::kDiffuse))
                m_octree_tracer.m_view_type = OctreeTracer::kDiffuse;
            if(ImGui::MenuItem("Normal", nullptr, m_octree_tracer.m_view_type == OctreeTracer::kNormal))
                m_octree_tracer.m_view_type = OctreeTracer::kNormal;
            if(ImGui::MenuItem("Iterations", nullptr, m_octree_tracer.m_view_type == OctreeTracer::kIteration))
                m_octree_tracer.m_view_type = OctreeTracer::kIteration;
            ImGui::EndMenu();
        }

        if(ImGui::BeginMenu("Beam Optimization"))
        {
            if(ImGui::MenuItem("Enable", nullptr, m_octree_tracer.m_beam_enable))
                m_octree_tracer.m_beam_enable ^= 1;
            ImGui::DragFloat("Ray Direction Size", &m_octree_tracer.m_beam_dir_size, 0.001f, 0.0f, 0.1f);
            ImGui::DragFloat("Ray Origin Size", &m_octree_tracer.m_beam_origin_size, 0.001f, 0.0f, 0.1f);
            ImGui::EndMenu();
        }

        if(ImGui::BeginMenu("Path Tracer"))
        {
            ImGui::DragInt("Bounce", &m_pathtracer.m_bounce, 1, 2, kMaxBounce);
            ImGui::DragFloat3("Sun Radiance", &m_pathtracer.m_sun_radiance[0], 0.1f, 0.0f, 20.0f);
            ImGui::EndMenu();
        }
    }
    else if(m_octree)
    {
        if(ImGui::Button("Exit PT"))
            m_pathtracing_flag = false;
        if(ImGui::Button("Export OpenEXR"))
            open_export_exr_popup = true;

        ImGui::Checkbox("Pause", &m_pathtracer.m_pause);

        if(ImGui::BeginMenu("View"))
        {
            if(ImGui::MenuItem("Color", nullptr, m_pathtracer.m_view_type == PathTracer::kColor))
                m_pathtracer.m_view_type = PathTracer::kColor;
            if(ImGui::MenuItem("Albedo", nullptr, m_pathtracer.m_view_type == PathTracer::kAlbedo))
                m_pathtracer.m_view_type = PathTracer::kAlbedo;
            if(ImGui::MenuItem("Normal", nullptr, m_pathtracer.m_view_type == PathTracer::kNormal))
                m_pathtracer.m_view_type = PathTracer::kNormal;

            ImGui::EndMenu();
        }
    }

    ImGui::EndMainMenuBar();

    if(open_load_scene_popup)
        ImGui::OpenPopup("Load Scene");
    if(open_export_exr_popup)
        ImGui::OpenPopup("Export OpenEXR");

    ui_load_scene_modal();
    ui_export_exr_modal();
}
bool
Application::ui_file_open(const char *label, const char *btn, char *buf, size_t buf_size, const char *title,
                          int filter_num, const char *const *filter_patterns)
{
    bool ret = ImGui::InputText(label, buf, buf_size);
    ImGui::SameLine();

    if(ImGui::Button(btn))
    {
        const char *filename = tinyfd_openFileDialog(title, "", filter_num, filter_patterns,
                                                     nullptr, false);
        if(filename) strcpy(buf, filename);
        ret = true;
    }
    return ret;
}

bool
Application::ui_file_save(const char *label, const char *btn, char *buf, size_t buf_size, const char *title,
                          int filter_num, const char *const *filter_patterns)
{
    bool ret = ImGui::InputText(label, buf, buf_size);
    ImGui::SameLine();

    if(ImGui::Button(btn))
    {
        const char *filename = tinyfd_saveFileDialog(title, "", filter_num, filter_patterns,
                                                     nullptr);
        if(filename) strcpy(buf, filename);
        ret = true;
    }
    return ret;
}

void Application::ui_load_scene_modal()
{
    if (ImGui::BeginPopupModal("Load Scene", nullptr,
                               ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove))
    {
        static char name_buf[kFilenameBufSize];
        static int octree_leve = 10;

        constexpr const char *kFilter[] = {"*.obj"};

        ui_file_open("OBJ Filename", "...##5", name_buf, kFilenameBufSize, "OBJ Filename",
                     1, kFilter);
        ImGui::DragInt("Octree Level", &octree_leve, 1, 2, 12);

        if (ImGui::Button("Load", ImVec2(256, 0)))
        {
            LoadScene(name_buf, octree_leve);
            ImGui::CloseCurrentPopup();
        }
        ImGui::SetItemDefaultFocus();
        ImGui::SameLine();
        if (ImGui::Button("Cancel", ImVec2(256, 0)))
            ImGui::CloseCurrentPopup();

        ImGui::EndPopup();
    }
}

void Application::ui_export_exr_modal()
{
    if (ImGui::BeginPopupModal("Export OpenEXR", nullptr,
                               ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove))
    {
        static char exr_name_buf[kFilenameBufSize]{};
        static bool save_as_fp16{false};
        ImGui::LabelText("", "INFO: will export %s channel",
                         m_pathtracer.m_view_type == PathTracer::kColor ? "COLOR" :
                         (m_pathtracer.m_view_type == PathTracer::kAlbedo ? "ALBEDO" : "NORMAL"));

        constexpr const char *kFilter[] = {"*.exr"};
        ui_file_save("OpenEXR Filename", "...##0", exr_name_buf, kFilenameBufSize, "Export OpenEXR",
                     1, kFilter);

        ImGui::Checkbox("Export As FP16", &save_as_fp16);

        {
            if (ImGui::Button("Export", ImVec2(256, 0)))
            {
                m_pathtracer.Save(exr_name_buf, save_as_fp16);
                ImGui::CloseCurrentPopup();
            }
            ImGui::SetItemDefaultFocus();
            ImGui::SameLine();
            if (ImGui::Button("Cancel", ImVec2(256, 0)))
            {
                ImGui::CloseCurrentPopup();
            }
        }

        ImGui::EndPopup();
    }
}

void Application::glfw_key_callback(GLFWwindow *window, int key, int, int action, int)
{
    auto *app = (Application *)glfwGetWindowUserPointer(window);
    if(!ImGui::GetCurrentContext()->NavWindow
       || (ImGui::GetCurrentContext()->NavWindow->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus))
    {
        if (action == GLFW_PRESS && key == GLFW_KEY_X)
            app->m_ui_display_flag ^= 1u;
    }
}
trsh commented 4 years ago

Got tons of errors:

Severity    Code    Description Project File    Line    Suppression State
Error (active)  E1696   cannot open source file "tinyfiledialogs/tinyfiledialogs.h" SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   6   
Error (active)  E0147   declaration is incompatible with "bool Application::ui_file_open(const char *label, const char *btn, char *buf, size_t buf_size, const char *title, const std::vector<std::string, std::allocator<std::string>> &filters)" (declared at line 38 of "C:\Projects\vox\SparseVoxelOctree\src\Application.hpp") SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   260 
Error (active)  E0020   identifier "tinyfd_openFileDialog" is undefined SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   268 
Error (active)  E0147   declaration is incompatible with "bool Application::ui_file_save(const char *label, const char *btn, char *buf, size_t buf_size, const char *title, const std::vector<std::string, std::allocator<std::string>> &filters)" (declared at line 40 of "C:\Projects\vox\SparseVoxelOctree\src\Application.hpp") SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   277 
Error (active)  E0020   identifier "tinyfd_saveFileDialog" is undefined SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   285 
Error (active)  E0415   no suitable constructor exists to convert from "int" to "std::vector<std::string, std::allocator<std::string>>" SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   304 
Error (active)  E0140   too many arguments in function call SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   304 
Error (active)  E0415   no suitable constructor exists to convert from "int" to "std::vector<std::string, std::allocator<std::string>>" SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   334 
Error (active)  E0140   too many arguments in function call SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   334 
Warning     'freopen' is deprecated: This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]   shaders_gen C:\Projects\vox\SparseVoxelOctree\src\shaders_gen.cpp   22  
Warning     field 'delta_' will be initialized after field 'fps_' [-Wreorder]   SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\dep\mygl3\utils\framerate.hpp 18  
Error       'tinyfiledialogs/tinyfiledialogs.h' file not found  SparseVoxelOctree   C:\Projects\vox\SparseVoxelOctree\src\Application.cpp   6   
AdamYuan commented 4 years ago

(Update to the latest commit first)

trsh commented 4 years ago

Still black screen and no menu :)

In console:

QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
QUAD END: 0
QUAD BEGIN: 0
...
AdamYuan commented 4 years ago

that means some of my opengl base code dont work on your computer........

AdamYuan commented 4 years ago

There may be some non-standard parts in my opengl basecode. And I suspect the problem is in mygl3/Shader.hpp

AdamYuan commented 4 years ago

Try this: src/Application.cpp

//
// Created by adamyuan on 19-5-3.
//

#include <cstdio>
#include <tinyfiledialogs/tinyfiledialogs.h>
#include <imgui/imgui.h>
#include <imgui/imgui_impl_opengl3.h>
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_internal.h>
#include "Scene.hpp"
#include "Voxelizer.hpp"
#include "Application.hpp"
#include "Config.hpp"
#include "OctreeBuilder.hpp"

constexpr size_t kFilenameBufSize = 512;

Application::Application()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
    m_window = glfwCreateWindow(kWidth, kHeight, "SparseVoxelOctree", nullptr, nullptr);
    if (m_window == nullptr) {
        printf("[APPLICATION]Failed to load glfw.");
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(m_window);
    glfwSetWindowUserPointer(m_window, (void*)this);

    gl3wInit();

    m_quad.Initialize();

    //Initialize ImGui
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGui::StyleColorsDarcula();

    ImGui_ImplGlfw_InitForOpenGL(m_window, true);
    ImGui_ImplOpenGL3_Init("#version 450 core");
}

void Application::LoadScene(const char *filename, int octree_level)
{
}

Application::~Application()
{
    glfwDestroyWindow(m_window);
    glfwTerminate();
}

void Application::Run()
{
    constexpr const char *kVertStr = R"(#version 450 core
layout (location = 0) in vec2 aPosition;
void main() { gl_Position = vec4(aPosition, 1.0, 1.0); }
)";
    constexpr const char *kFragStr = R"(#version 450 core
out vec4 oFragColor;
void main() { oFragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f); }
)";

    GLuint vert_shader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vert_shader, 1, &kVertStr, nullptr);
    glCompileShader(vert_shader);

    GLuint frag_shader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(frag_shader, 1, &kFragStr, nullptr);
    glCompileShader(frag_shader);

    GLuint program = glCreateProgram();
    glAttachShader(program, vert_shader);
    glAttachShader(program, frag_shader);
    glLinkProgram(program);

    glDeleteShader(vert_shader);
    glDeleteShader(frag_shader);

    while(!glfwWindowShouldClose(m_window))
    {
        glClear(GL_COLOR_BUFFER_BIT);

        glUseProgram(program);
        m_quad.Render();

        glfwSwapBuffers(m_window);
        glfwPollEvents();
    }

    glDeleteProgram(program);
}
trsh commented 4 years ago

Congratulations! Now its Red :)))))

AdamYuan commented 4 years ago

!!!! Sadly I was incorrectly using OpenGL.. Now I had to spend some time to redesign my Shader class

AdamYuan commented 4 years ago

I pushed a new commit, this should be fixed

trsh commented 4 years ago

Jip!