From ec66676cffdf7b7e5056fd53085b5325b4086e91 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 8 Jun 2024 18:24:59 +0200 Subject: [PATCH] Revert "Some adaptions" This reverts commit c8706f9a73a783e0319ff6b27bc673cfc69dff91. --- src/AssimpViewerApp.cpp | 562 ---------------------------------------- src/main.cpp | 339 ------------------------ 2 files changed, 901 deletions(-) delete mode 100644 src/AssimpViewerApp.cpp delete mode 100644 src/main.cpp diff --git a/src/AssimpViewerApp.cpp b/src/AssimpViewerApp.cpp deleted file mode 100644 index edde274..0000000 --- a/src/AssimpViewerApp.cpp +++ /dev/null @@ -1,562 +0,0 @@ -#include "contrib/sokol/sokol_app.h" -#include "contrib/sokol/sokol_gfx.h" -#include "contrib/sokol/sokol_time.h" -#include "contrib/sokol/sokol_glue.h" - - -#include "AssimpViewerApp.h" -#include "MainRenderView.h" -#include -#include - -#include - -#if defined(__APPLE__) - #define SOKOL_METAL -#elif defined(_WIN32) - #define SOKOL_D3D11 -#elif defined(__EMSCRIPTEN__) - #define SOKOL_GLES2 -#else - #define SOKOL_GLCORE33 -#endif - -#include "contrib/sokol/sokol_app.h" -#include "contrib/sokol/sokol_time.h" -#include "contrib/sokol/sokol_gfx.h" - -#define MAX_BONES 64 -#define MAX_BLEND_SHAPES 64 - -struct vec2 { - float x, y; -}; - -struct vec3 { - float x,y,z; -}; - -struct mesh_vertex { - vec3 position; - vec3 normal; - vec2 uv; - float f_vertex_index; -}; - -struct skin_vertex { - uint8_t bone_index[4]; - uint8_t bone_weight[4]; -}; - -static sg_layout_desc mesh_vertex_layout; - -static void initMeshVertexFormat() { - mesh_vertex_layout.attrs[0].buffer_index = 0; - mesh_vertex_layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT3; - - mesh_vertex_layout.attrs[1].buffer_index = 0; - mesh_vertex_layout.attrs[1].format = SG_VERTEXFORMAT_FLOAT3; - - mesh_vertex_layout.attrs[2].buffer_index = 0; - mesh_vertex_layout.attrs[2].format = SG_VERTEXFORMAT_FLOAT2; - - mesh_vertex_layout.attrs[3].buffer_index = 0; - mesh_vertex_layout.attrs[3].format = SG_VERTEXFORMAT_FLOAT; -} - -static sg_layout_desc skinned_mesh_vertex_layout; - -static void initSkinnedMeshVertexFormat() { - skinned_mesh_vertex_layout.attrs[0].buffer_index = 0; - skinned_mesh_vertex_layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT3; - - skinned_mesh_vertex_layout.attrs[1].buffer_index = 0; - skinned_mesh_vertex_layout.attrs[1].format = SG_VERTEXFORMAT_FLOAT3; - - skinned_mesh_vertex_layout.attrs[2].buffer_index = 0; - skinned_mesh_vertex_layout.attrs[2].format = SG_VERTEXFORMAT_FLOAT2; - - skinned_mesh_vertex_layout.attrs[3].buffer_index = 0; - skinned_mesh_vertex_layout.attrs[3].format = SG_VERTEXFORMAT_FLOAT; -} - -struct quat { - float x,y,z,w; -}; - -struct mat4 { - float m11, m21, m31, m41; - float m12, m22, m32, m42; - float m13, m23, m33, m43; - float m14, m24, m34, m44; -}; - -struct viewer_node_anim { - float time_begin; - float framerate; - size_t num_frames; - quat const_rot; - vec3 const_pos; - vec3 const_scale; - quat *rot; - vec3 *pos; - vec3 *scale; -}; - -struct viewer_blend_channel_anim { - float const_weight; - float *weight; -}; - -struct viewer_anim { - const char *name; - float time_begin; - float time_end; - float framerate; - size_t num_frames; - - viewer_node_anim *nodes; - viewer_blend_channel_anim *blend_channels; -}; - -struct viewer_node { - int32_t parent_index; - - mat4 geometry_to_node; - mat4 node_to_parent; - mat4 node_to_world; - mat4 geometry_to_world; - mat4 normal_to_world; -}; - -struct viewer_blend_channel { - float weight; -}; - -struct viewer_mesh_part { - sg_buffer vertex_buffer; - sg_buffer index_buffer; - sg_buffer skin_buffer; // Optional - - size_t num_indices; - int32_t material_index; -}; - -struct viewer_mesh { - int32_t *instance_node_indices; - size_t num_instances; - - viewer_mesh_part *parts; - size_t num_parts; - - bool aabb_is_local; - vec3 aabb_min; - vec3 aabb_max; - - // Skinning (optional) - bool skinned; - size_t num_bones; - int32_t bone_indices[MAX_BONES]; - mat4 bone_matrices[MAX_BONES]; - - // Blend shapes (optional) - size_t num_blend_shapes; - sg_image blend_shape_image; - int32_t blend_channel_indices[MAX_BLEND_SHAPES]; -}; - -struct viewer_scene { - viewer_node *nodes; - size_t num_nodes; - - viewer_mesh *meshes; - size_t num_meshes; - - viewer_blend_channel *blend_channels; - size_t num_blend_channels; - - viewer_anim *animations; - size_t num_animations; - - vec3 aabb_min; - vec3 aabb_max; -}; - -struct viewer { - viewer_scene scene; - float anim_time; - - sg_shader shader_mesh_lit_static; - sg_shader shader_mesh_lit_skinned; - sg_pipeline pipe_mesh_lit_static; - sg_pipeline pipe_mesh_lit_skinned; - sg_image empty_blend_shape_image; - - mat4 world_to_view; - mat4 view_to_clip; - mat4 world_to_clip; - - float camera_yaw; - float camera_pitch; - float camera_distance; - uint32_t mouse_buttons; -}; - -namespace AssimpViewer { - -static constexpr char Tag[] = "OsreEdApp"; - -static void createTitleString(const std::string &assetName, std::string &titleString) { - titleString.clear(); - titleString += "AssimpViewer!"; - - titleString += " Asset: "; - titleString += assetName; -} - -AssimpViewerApp::AssimpViewerApp(int argc, char *argv[]) : - mTitle(), - mWindow(nullptr), - mSceneData() { - // empty -} - -AssimpViewerApp::~AssimpViewerApp() { - // empty -} - -const aiScene *AssimpViewerApp::importAssimp(const std::string &path) { - return nullptr; -} - -void *alloc_imp(size_t type_size, size_t count) -{ - void *ptr = malloc(type_size * count); - if (!ptr) { - fprintf(stderr, "Out of memory\n"); - exit(1); - } - memset(ptr, 0, type_size * count); - return ptr; -} - -void *alloc_dup_imp(size_t type_size, size_t count, const void *data) -{ - void *ptr = malloc(type_size * count); - if (!ptr) { - fprintf(stderr, "Out of memory\n"); - exit(1); - } - memcpy(ptr, data, type_size * count); - return ptr; -} - -#define alloc(m_type, m_count) (m_type*)alloc_imp(sizeof(m_type), (m_count)) -#define alloc_dup(m_type, m_count, m_data) (m_type*)alloc_dup_imp(sizeof(m_type), (m_count), (m_data)) - -size_t min_sz(size_t a, size_t b) { return a < b ? a : b; } -size_t max_sz(size_t a, size_t b) { return b < a ? a : b; } -size_t clamp_sz(size_t a, size_t min_a, size_t max_a) { return min_sz(max_sz(a, min_a), max_a); } - -struct viewer_node_anim { - float time_begin; - float framerate; - size_t num_frames; - quat const_rot; - vec3 const_pos; - vec3 const_scale; - quat *rot; - vec3 *pos; - vec3 *scale; -}; - -struct viewer_blend_channel_anim { - float const_weight; - float *weight; -}; - -struct viewer_anim { - const char *name; - float time_begin; - float time_end; - float framerate; - size_t num_frames; - - viewer_node_anim *nodes; - viewer_blend_channel_anim *blend_channels; -}; - -struct viewer_node { - int32_t parent_index; - - mat4 geometry_to_node; - mat4 node_to_parent; - mat4 node_to_world; - mat4 geometry_to_world; - mat4 normal_to_world; -}; - -struct viewer_blend_channel { - float weight; -}; - -struct viewer_mesh_part { - sg_buffer vertex_buffer; - sg_buffer index_buffer; - sg_buffer skin_buffer; // Optional - - size_t num_indices; - int32_t material_index; -}; - -struct viewer_mesh { - int32_t *instance_node_indices; - size_t num_instances; - - viewer_mesh_part *parts; - size_t num_parts; - - bool aabb_is_local; - vec3 aabb_min; - vec3 aabb_max; - - // Skinning (optional) - bool skinned; - size_t num_bones; - int32_t bone_indices[MAX_BONES]; - mat4 bone_matrices[MAX_BONES]; - - // Blend shapes (optional) - size_t num_blend_shapes; - sg_image blend_shape_image; - int32_t blend_channel_indices[MAX_BLEND_SHAPES]; -}; - -struct viewer_scene { - - viewer_node *nodes; - size_t num_nodes; - - viewer_mesh *meshes; - size_t num_meshes; - - viewer_blend_channel *blend_channels; - size_t num_blend_channels; - - viewer_anim *animations; - size_t num_animations; - - vec3 aabb_min; - vec3 aabb_max; - -}; - -struct viewer { - - viewer_scene scene; - float anim_time; - - sg_shader shader_mesh_lit_static; - sg_shader shader_mesh_lit_skinned; - sg_pipeline pipe_mesh_lit_static; - sg_pipeline pipe_mesh_lit_skinned; - sg_image empty_blend_shape_image; - - mat4 world_to_view; - mat4 view_to_clip; - mat4 world_to_clip; - - float camera_yaw; - float camera_pitch; - float camera_distance; - uint32_t mouse_buttons; -}; - -void init_pipelines(viewer *view) -{ - sg_backend backend = sg_query_backend(); - - view->shader_mesh_lit_static = sg_make_shader(static_lit_shader_desc(backend)); - view->pipe_mesh_lit_static = sg_make_pipeline(&(sg_pipeline_desc){ - .shader = view->shader_mesh_lit_static, - .layout = mesh_vertex_layout, - .index_type = SG_INDEXTYPE_UINT32, - .face_winding = SG_FACEWINDING_CCW, - .cull_mode = SG_CULLMODE_BACK, - .depth = { - .compare = SG_COMPAREFUNC_LESS_EQUAL, - .write_enabled = true, - }, - }); - - view->shader_mesh_lit_skinned = sg_make_shader(skinned_lit_shader_desc(backend)); - view->pipe_mesh_lit_skinned = sg_make_pipeline(&(sg_pipeline_desc){ - .shader = view->shader_mesh_lit_skinned, - .layout = skinned_mesh_vertex_layout, - .index_type = SG_INDEXTYPE_UINT32, - .face_winding = SG_FACEWINDING_CCW, - .cull_mode = SG_CULLMODE_BACK, - .depth = { - .compare = SG_COMPAREFUNC_LESS_EQUAL, - .write_enabled = true, - }, - }); - - vec4 empty_blend_shape_data = { 0 }; - view->empty_blend_shape_image = sg_make_image(&(sg_image_desc){ - .type = SG_IMAGETYPE_ARRAY, - .width = 1, - .height = 1, - .num_slices = 1, - .pixel_format = SG_PIXELFORMAT_RGBA32F, - .data.subimage[0][0] = SG_RANGE(empty_blend_shape_data), - }); -} - -void load_scene(viewer_scene *vs, const char *filename) -{ -} - -bool backend_uses_d3d_perspective(sg_backend backend) -{ - switch (backend) { - case SG_BACKEND_GLCORE33: return false; - case SG_BACKEND_GLES2: return false; - case SG_BACKEND_GLES3: return false; - case SG_BACKEND_D3D11: return true; - case SG_BACKEND_METAL_IOS: return true; - case SG_BACKEND_METAL_MACOS: return true; - case SG_BACKEND_METAL_SIMULATOR: return true; - case SG_BACKEND_WGPU: return true; - case SG_BACKEND_DUMMY: return false; - default: assert(0 && "Unhandled backend"); return false; - } -} - -void update_camera(viewer *view) -{ -} - -void draw_mesh(viewer *view, viewer_node *node, viewer_mesh *mesh) -{ -} - -void draw_scene(viewer *view) -{ - for (size_t mi = 0; mi < view->scene.num_meshes; mi++) { - viewer_mesh *mesh = &view->scene.meshes[mi]; - for (size_t ni = 0; ni < mesh->num_instances; ni++) { - viewer_node *node = &view->scene.nodes[mesh->instance_node_indices[ni]]; - draw_mesh(view, node, mesh); - } - } -} - -viewer g_viewer; -const char *g_filename; - -void init(void) -{ - sg_setup(&(sg_desc){ - .context = sapp_sgcontext(), - .buffer_pool_size = 4096, - .image_pool_size = 4096, - }); - - stm_setup(); - - init_pipelines(&g_viewer); - load_scene(&g_viewer.scene, g_filename); -} - -void onevent(const sapp_event *e) -{ - viewer *view = &g_viewer; - - switch (e->type) { - case SAPP_EVENTTYPE_MOUSE_DOWN: - view->mouse_buttons |= 1u << (uint32_t)e->mouse_button; - break; - case SAPP_EVENTTYPE_MOUSE_UP: - view->mouse_buttons &= ~(1u << (uint32_t)e->mouse_button); - break; - case SAPP_EVENTTYPE_UNFOCUSED: - view->mouse_buttons = 0; - break; - case SAPP_EVENTTYPE_MOUSE_MOVE: - if (view->mouse_buttons & 1) { - float scale = um_min((float)sapp_width(), (float)sapp_height()); - view->camera_yaw -= e->mouse_dx / scale * 180.0f; - view->camera_pitch -= e->mouse_dy / scale * 180.0f; - view->camera_pitch = um_clamp(view->camera_pitch, -89.0f, 89.0f); - } - break; - case SAPP_EVENTTYPE_MOUSE_SCROLL: - view->camera_distance += e->scroll_y * -0.02f; - view->camera_distance = um_clamp(view->camera_distance, -5.0f, 5.0f); - break; - default: - break; - } -} - -void frame() -{ - static uint64_t last_time; - float dt = (float)stm_sec(stm_laptime(&last_time)); - dt = std::min(dt, 0.1f); - - viewer_anim *anim = g_viewer.scene.num_animations > 0 ? &g_viewer.scene.animations[0] : NULL; - - if (anim) { - g_viewer.anim_time += dt; - if (g_viewer.anim_time >= anim->time_end) { - g_viewer.anim_time -= anim->time_end - anim->time_begin; - } - update_animation(&g_viewer.scene, anim, g_viewer.anim_time); - } - - update_camera(&g_viewer); - update_hierarchy(&g_viewer.scene); - - sg_pass_action action = { - .colors[0] = { - .action = SG_ACTION_CLEAR, - .value = { 0.1f, 0.1f, 0.2f }, - }, - }; - sg_begin_default_pass(&action, sapp_width(), sapp_height()); - - draw_scene(&g_viewer); - - sg_end_pass(); - sg_commit(); -} - -void cleanup(void) -{ - sg_shutdown(); -} - -sapp_desc sokol_main(int argc, char* argv[]) { - - if (argc <= 1) { - fprintf(stderr, "Usage: viewer file.fbx\n"); - exit(1); - } - - g_filename = argv[1]; - - return (sapp_desc){ - .init_cb = &init, - .event_cb = &onevent, - .frame_cb = &frame, - .cleanup_cb = &cleanup, - .width = 800, - .height = 600, - .sample_count = 4, - .window_title = "ufbx viewer", - }; -} - -} // namespace AssimpViewer diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 5cfab0a..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/*----------------------------------------------------------------------------------------------- -The MIT License (MIT) - -Copyright (c) 2015-2024 assimp_view by Kim Kulling - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------*/ -#include "backends/imgui_impl_sdl2.h" -#include "backends/imgui_impl_opengl3.h" -#include -#include -#include -#include -#include - -#ifdef main -# undef main -#endif - -#define main main - -#include "AssimpViewerApp.h" - -#include - -using namespace Assimp; - -using namespace AssimpViewer; - -static constexpr char Tag[] = "AssimpViewerApp"; - -void addChildren(aiNode *node) { - if (node == nullptr) { - return; - } - - bool open = false; - - if (ImGui::TreeNode(node->mName.C_Str())) { - open = true; - ImGui::Text("Type: aiNode"); - const std::string numMeshes = "Number of meshes: " + std::to_string(node->mNumMeshes); - ImGui::Text(numMeshes.c_str()); - - for (size_t i = 0; i < node->mNumChildren; ++i) { - aiNode *currentNode = node->mChildren[i]; - if (currentNode == nullptr) { - continue; - } - - addChildren(currentNode); - } - } - - if (open) { - ImGui::TreePop(); - } -} - -void setMenu(bool &newImporter, bool &importAsset, bool &done, bool &info) { - if (ImGui::BeginMenuBar()) { - if (ImGui::BeginMenu("File")) { - ImGui::MenuItem("New", nullptr, &newImporter); - ImGui::MenuItem("Import", nullptr, &importAsset); - ImGui::MenuItem("Quit", nullptr, &done); - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Info")) { - ImGui::MenuItem("Info", nullptr, &info); - ImGui::EndMenu(); - } - ImGui::EndMenuBar(); - } -} - -void setSceneTree(const aiScene *scene) { - if (scene == nullptr) { - return; - } - - if (scene->mRootNode == nullptr) { - return; - } - - aiNode *node = scene->mRootNode; - addChildren(node); -} - -struct SDLContext { - SDL_Window *window; - SDL_GLContext gl_context; - SDL_SysWMinfo wmInfo; - const char *glsl_version; -}; - -using errcode_t = int32_t; - -struct Logger { - static Logger sInstance; - static Logger &getInstance() { - return sInstance; - } - - void logInfo(const std::string &msg) { - std::cout << "*Inf* : " - << msg << "\n"; - } - - void logWarn(const std::string &msg) { - std::cerr << "*Warn*: " - << msg << "\n"; - } - - void logError(const std::string &msg) { - std::cerr << "*Err* : " - << msg << "\n"; - } -}; - -Logger Logger::sInstance; - -errcode_t initSDL(SDLContext &ctx, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { - printf("Error: %s\n", SDL_GetError()); - return -1; - } - - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); - auto Width = DM.w; - auto Height = DM.h; - - - // Decide GL+GLSL versions - // GL 3.0 + GLSL 130 - ctx.glsl_version = "#version 130"; - -#ifdef __APPLE__ - // GL 3.2 Core + GLSL 150 - ctx.glsl_version = "#version 150"; - SDL_GL_SetAttribute( // required on Mac OS - SDL_GL_CONTEXT_FLAGS, - SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); -#elif __linux__ - // GL 3.2 Core + GLSL 150 - ctx.glsl_version = "#version 150"; - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); -#elif _WIN32 - // GL 3.0 + GLSL 130 - ctx.glsl_version = "#version 130"; - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); -#endif - - // Create window with graphics context - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); - ctx.window = SDL_CreateWindow("Assimp Viewer", x, y, w, h, window_flags); - if (ctx.window == nullptr) { - Logger::getInstance().logError("Window is nullptr."); - return -1; - } - - ctx.gl_context = SDL_GL_CreateContext(ctx.window); - SDL_GL_MakeCurrent(ctx.window, ctx.gl_context); - SDL_GL_SetSwapInterval(1); // Enable vsync - - - SDL_VERSION(&ctx.wmInfo.version); - SDL_GetWindowWMInfo(ctx.window, &ctx.wmInfo); - -#ifdef __APPLE__ -#elif __linux__ -#elif _WIN32 - ctx.handle.hwnd = ctx.wmInfo.info.win.window; -#endif - - return 0; -} - -errcode_t releaseSDL(SDLContext &ctx) { - SDL_GL_DeleteContext(ctx.gl_context); - SDL_DestroyWindow(ctx.window); - SDL_Quit(); - - return 0; -} - -struct ImGuiWrapper { - SDLContext &mCtx; - ImGuiIO &mIo; - const ImVec4 mClearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - - ImGuiWrapper(SDLContext &ctx, ImGuiIO &io) : - mCtx(ctx), mIo(io) {} - - ~ImGuiWrapper() = default; - - errcode_t init() { - // Setup Dear ImGui context - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - mIo = ImGui::GetIO(); - - mIo.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - mIo.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls - - // Setup Dear ImGui style - ImGui::StyleColorsDark(); - - // Setup Platform/Renderer back end's - ImGui_ImplSDL2_InitForOpenGL(mCtx.window, mCtx.gl_context); - ImGui_ImplOpenGL3_Init(mCtx.glsl_version); - - return 0; - } - - void loadAsset_cb(AssimpViewerApp &assimpViewerApp) { - - } - - errcode_t updateFrame(AssimpViewerApp &assimpViewerApp, bool &done) { - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplSDL2_NewFrame(); - ImGui::NewFrame(); - ImGuiWindowFlags window_flags = 0; - window_flags |= ImGuiWindowFlags_MenuBar; - { - static int counter = 0; - bool importAsset = false; - bool newImporter = false; - bool p_open = true; - bool info = false; - ImGui::Begin("Assimp Viewer", &p_open, window_flags); - setMenu(newImporter, importAsset, done, info); - - if (importAsset) { - loadAsset_cb(assimpViewerApp); - } - - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / mIo.Framerate, mIo.Framerate); - if (ImGui::TreeNode("Scene")) { - - const aiScene *scene = assimpViewerApp.getScene(); - setSceneTree(scene); - ImGui::TreePop(); - } - ImGui::End(); - } - - ImGui::Render(); - - return 0; - } - - errcode_t renderFrame() { - glViewport(0, 0, (int)mIo.DisplaySize.x, (int)mIo.DisplaySize.y); - glClearColor(mClearColor.x * mClearColor.w, mClearColor.y * mClearColor.w, mClearColor.z * mClearColor.w, mClearColor.w); - glClear(GL_COLOR_BUFFER_BIT); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - SDL_GL_SwapWindow(mCtx.window); - - return 0; - } - // Cleanup - errcode_t release() { - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplSDL2_Shutdown(); - ImGui::DestroyContext(); - - return 0; - } -}; - - -int main(int argc, char *argv[]) { - SDLContext ctx; - uint32_t x = 25; - uint32_t y = 25; - uint32_t w = 1280; - uint32_t h = 1024; - if (initSDL(ctx, x, y, w, h) == -1) { - Logger::getInstance().logError("Cannot initialize SDL."); - return -1; - } - - AssimpViewerApp assimpViewerApp(argc, argv); - - - ImGuiIO io = {}; - ImGuiWrapper imguiWrapper(ctx, io); - imguiWrapper.init(); - - // Main loop - bool done = false; - while (!done) { - SDL_Event event; - while (SDL_PollEvent(&event)) { - ImGui_ImplSDL2_ProcessEvent(&event); - if (event.type == SDL_QUIT) { - done = true; - } - } - - // Start the Dear ImGui frame - imguiWrapper.updateFrame(assimpViewerApp, done); - imguiWrapper.renderFrame(); - - assimpViewerApp.renderFrame(); - } - - imguiWrapper.release(); - releaseSDL(ctx); - - return 0; -}