Commit 2af96c97 authored by stonecompass's avatar stonecompass
Browse files

Improved camera previewing.


Former-commit-id: 3b167e97
parent be2f0b5d
......@@ -81,6 +81,12 @@ namespace editor
if(ImGui::Begin("Hierarchy", &hierarchy_open, ImGuiWindowFlags_NoFocusOnAppearing))
{
if(ImGui::Button("+ Empty"))
{
scene::EntityHandle new_handle = scene::_register_entity(scene::COMP_TRANSFORM, scene, true);
scene::select_entity(new_handle, scene.handle.manager);
}
for (i32 i = 0; i < scene.entity_count; i++)
{
scene::EntityHandle handle = scene.entities[i].handle;
......@@ -872,8 +878,14 @@ namespace editor
ImGui::Spacing();
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.35f, 1.0f));
ImGui::Text("(PREVIEWING CAMERA)");
ImGui::PopStyleColor();
if(ImGui::Button("STOP PREVIEW"))
{
stop_camera_preview(scene_manager);
}
}
ImGui::EndMainMenuBar();
......
......@@ -2400,15 +2400,15 @@ static void setup_instanced_vertex_attribute_buffers(rendering::VertexAttributeI
count = renderer->render.instancing.float_buffer_counts[handle];
Buffer *buffer = renderer->render.instancing.internal_float_buffers[handle];
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
if(renderer->render.instancing.dirty_float_buffers[handle])
{
glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizeiptr)(size * count), buf_ptr);
renderer->render.instancing.dirty_float_buffers[handle] = false;
}
glEnableVertexAttribArray(array_num);
glVertexAttribPointer(array_num, num_values, GL_FLOAT, GL_FALSE, (GLsizei)size, (void *)nullptr);
glVertexAttribDivisor(array_num, 1);
......@@ -2422,18 +2422,18 @@ static void setup_instanced_vertex_attribute_buffers(rendering::VertexAttributeI
count = renderer->render.instancing.float2_buffer_counts[handle];
Buffer *buffer = renderer->render.instancing.internal_float2_buffers[handle];
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
if(renderer->render.instancing.dirty_float2_buffers[handle])
{
glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizeiptr)(size * count), buf_ptr);
renderer->render.instancing.dirty_float2_buffers[handle] = false;
}
glEnableVertexAttribArray(array_num);
glVertexAttribPointer(array_num, num_values, GL_FLOAT, GL_FALSE, (GLsizei)size, (void *)nullptr);
glVertexAttribDivisor(array_num, 1);
glEnableVertexAttribArray(array_num);
glVertexAttribPointer(array_num, num_values, GL_FLOAT, GL_FALSE, (GLsizei)size, (void *)nullptr);
glVertexAttribDivisor(array_num, 1);
}
break;
case rendering::ValueType::FLOAT3:
......@@ -2445,17 +2445,17 @@ static void setup_instanced_vertex_attribute_buffers(rendering::VertexAttributeI
Buffer *buffer = renderer->render.instancing.internal_float3_buffers[handle];
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
if(renderer->render.instancing.dirty_float3_buffers[handle])
{
glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizeiptr)(size * count), buf_ptr);
renderer->render.instancing.dirty_float3_buffers[handle] = false;
}
glEnableVertexAttribArray(array_num);
glVertexAttribPointer(array_num, num_values, GL_FLOAT, GL_FALSE, (GLsizei)size, (void *)nullptr);
glVertexAttribDivisor(array_num, 1);
glEnableVertexAttribArray(array_num);
glVertexAttribPointer(array_num, num_values, GL_FLOAT, GL_FALSE, (GLsizei)size, (void *)nullptr);
glVertexAttribDivisor(array_num, 1);
}
break;
case rendering::ValueType::FLOAT4:
......@@ -2490,12 +2490,12 @@ static void setup_instanced_vertex_attribute_buffers(rendering::VertexAttributeI
Buffer *buffer = renderer->render.instancing.internal_mat4_buffers[handle];
GLsizei vec4_size = sizeof(math::Vec4);
glEnableVertexAttribArray(array_num);
glEnableVertexAttribArray(array_num + 1);
glEnableVertexAttribArray(array_num + 2);
glEnableVertexAttribArray(array_num + 3);
glEnableVertexAttribArray(array_num);
glEnableVertexAttribArray(array_num + 1);
glEnableVertexAttribArray(array_num + 2);
glEnableVertexAttribArray(array_num + 3);
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
glBindBuffer(GL_ARRAY_BUFFER, buffer->vbo);
if(renderer->render.instancing.dirty_mat4_buffers[handle])
{
......@@ -2503,15 +2503,15 @@ static void setup_instanced_vertex_attribute_buffers(rendering::VertexAttributeI
renderer->render.instancing.dirty_mat4_buffers[handle] = false;
}
glVertexAttribPointer(array_num, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)0);
glVertexAttribPointer(array_num + 1, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)(vec4_size));
glVertexAttribPointer(array_num + 2, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)(2 * vec4_size));
glVertexAttribPointer(array_num + 3, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)(3 * vec4_size));
glVertexAttribPointer(array_num, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)0);
glVertexAttribPointer(array_num + 1, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)(vec4_size));
glVertexAttribPointer(array_num + 2, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)(2 * vec4_size));
glVertexAttribPointer(array_num + 3, 4, GL_FLOAT, GL_FALSE, 4 * vec4_size, (void *)(3 * vec4_size));
glVertexAttribDivisor(array_num, 1);
glVertexAttribDivisor(array_num + 1, 1);
glVertexAttribDivisor(array_num + 2, 1);
glVertexAttribDivisor(array_num + 3, 1);
glVertexAttribDivisor(array_num, 1);
glVertexAttribDivisor(array_num + 1, 1);
glVertexAttribDivisor(array_num + 2, 1);
glVertexAttribDivisor(array_num + 3, 1);
}
break;
case rendering::ValueType::INTEGER:
......@@ -2841,7 +2841,7 @@ static void render_pass(RenderState &render_state, Renderer *renderer, rendering
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
rendering::Material material = get_material_instance(command.material, renderer);
rendering::Material &material = get_material_instance(command.material, renderer);
ShaderGL *shader = &render_state.gl_shaders[material.shader.handle];
switch(command.type)
......
......@@ -1918,8 +1918,6 @@ static Camera get_standard_camera(SceneManager& manager)
{
if(IS_ENTITY_HANDLE_VALID(entity) && !HANDLES_EQUAL(entity, manager->selected_entity))
{
stop_camera_preview(manager);
// Deselect the previously selected entity
if(IS_ENTITY_HANDLE_VALID(manager->selected_entity))
scene::set_wireframe_enabled(false, manager->selected_entity, manager->loaded_scene);
......@@ -2069,6 +2067,8 @@ static Camera get_standard_camera(SceneManager& manager)
}
else
{
manager->mode = SceneMode::RUNNING;
scene::reload_scene(manager->loaded_scene);
manager->renderer->api_functions.show_mouse_cursor(false, &render_state);
......@@ -2085,7 +2085,6 @@ static Camera get_standard_camera(SceneManager& manager)
manager->gizmos.active = false;
manager->selected_entity = { -1 };
manager->mode = SceneMode::RUNNING;
}
}
......@@ -4109,6 +4108,12 @@ static Camera get_standard_camera(SceneManager& manager)
return _get_light_comp(handle, scene);
}
static EntityHandle get_main_camera_handle(SceneHandle handle)
{
Scene& scene = get_scene(handle);
return scene.main_camera_handle;
}
static TransformComponent &get_main_camera_transform(SceneHandle handle)
{
Scene& scene = get_scene(handle);
......
......@@ -792,6 +792,7 @@ namespace scene
static Camera & get_scene_camera(SceneHandle handle);
static TransformComponent &get_main_camera_transform(SceneHandle handle);
static CameraComponent &get_main_camera_comp(SceneHandle handle);
static EntityHandle get_main_camera_handle(SceneHandle handle);
static void set_camera_for_render_pass(EntityHandle camera_entity, rendering::RenderPassHandle handle, SceneHandle scene_handle);
static EntityHandle pick_entity(SceneHandle handle, i32 mouse_x, i32 mouse_y);
static Entity& get_entity(EntityHandle handle, Scene &scene);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment