Skip to content

Commit

Permalink
Zephyr: Renderer: remove unused RenderObject API
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed Jun 8, 2024
1 parent ccfe67c commit b9668fc
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 73 deletions.
2 changes: 1 addition & 1 deletion app/next/src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ namespace zephyr {
};
std::copy_n(index_data, sizeof(index_data) / sizeof(u32), indices.begin());

const int grid_size = 64;
const int grid_size = 37;

for(int x = -grid_size / 2; x < grid_size / 2; x++) {
for(int y = -grid_size / 2; y < grid_size / 2; y++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ namespace zephyr {
Frustum frustum{};
};

struct RenderObject {
RenderGeometry* render_geometry{};
Matrix4 local_to_world{};
};

class RenderBackend {
public:
struct RenderBundleKey {
Expand Down Expand Up @@ -99,7 +94,6 @@ namespace zephyr {
virtual void DestroyRenderGeometry(RenderGeometry* render_geometry) = 0;

/// Just a quick thing for testing the rendering.
virtual void Render(const RenderCamera& render_camera, std::span<const RenderObject> render_objects) = 0;
virtual void Render(const RenderCamera& render_camera, const eastl::hash_map<RenderBundleKey, std::vector<RenderBundleItem>>& render_bundles) = 0;

/// Start rendering the next frame.
Expand Down
2 changes: 0 additions & 2 deletions zephyr/renderer/include/zephyr/renderer/render_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ namespace zephyr {
GeometryCache m_geometry_cache;

RenderScene m_render_scene{}; //< Representation of the scene graph that is internal to the render engine.

std::vector<RenderObject> m_render_objects{};
RenderCamera m_render_camera{};
};

Expand Down
1 change: 0 additions & 1 deletion zephyr/renderer/include/zephyr/renderer/render_scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace zephyr {
public:
void SetSceneGraph(std::shared_ptr<SceneGraph> scene_graph);
void Update();
void GetRenderObjects(std::vector<RenderObject>& out_render_objects, const GeometryCache& geometry_cache);
void GetRenderCamera(RenderCamera& out_render_camera);
void UpdateGeometries(GeometryCache& geometry_cache);

Expand Down
15 changes: 0 additions & 15 deletions zephyr/renderer/src/backend/opengl/render_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,6 @@ namespace zephyr {
m_render_geometry_manager->DestroyRenderGeometry(render_geometry);
}

void OpenGLRenderBackend::Render(const RenderCamera& render_camera, std::span<const RenderObject> render_objects) {
eastl::hash_map<RenderBundleKey, std::vector<RenderBundleItem>> render_bundles;

for(const RenderObject& render_object : render_objects) {
// TODO(fleroviux): get rid of unsafe size_t to u32 conversion.
auto render_geometry = dynamic_cast<OpenGLRenderGeometry*>(render_object.render_geometry);
RenderBundleKey render_bundle_key{};
render_bundle_key.uses_ibo = render_geometry->GetNumberOfIndices();
render_bundle_key.geometry_layout = render_geometry->GetLayout().key;
render_bundles[render_bundle_key].emplace_back(render_object.local_to_world, (u32)render_geometry->GetGeometryID(), (u32)0u);
}

Render(render_camera, render_bundles);
}

void OpenGLRenderBackend::Render(const RenderCamera& render_camera, const eastl::hash_map<RenderBundleKey, std::vector<RenderBundleItem>>& render_bundles) {
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Expand Down
1 change: 0 additions & 1 deletion zephyr/renderer/src/backend/opengl/render_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace zephyr {
void UpdateRenderGeometryAABB(RenderGeometry* render_geometry, const Box3& aabb) override;
void DestroyRenderGeometry(RenderGeometry* render_geometry) override;

void Render(const RenderCamera& render_camera, std::span<const RenderObject> render_objects) override;
void Render(const RenderCamera& render_camera, const eastl::hash_map<RenderBundleKey, std::vector<RenderBundleItem>>& render_bundles) override;

void SwapBuffers() override;
Expand Down
33 changes: 0 additions & 33 deletions zephyr/renderer/src/backend/vulkan/render_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,6 @@ namespace zephyr {
ZEPHYR_PANIC("unimplemented");
}

void Render(const RenderCamera& render_camera, std::span<const RenderObject> render_objects) override {
const VkClearValue clear_value{
.color = VkClearColorValue{
.float32 = {0.01f, 0.01f, 0.01f, 1.0f}
}
};

const VkRenderPassBeginInfo render_pass_begin_info{
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.pNext = nullptr,
.renderPass = m_vk_render_pass,
.framebuffer = m_vk_swap_chain_fbs[m_vk_swap_chain_image_index],
.renderArea = VkRect2D{
.offset = VkOffset2D{0u, 0u},
.extent = VkExtent2D{1920u, 1080u}
},
.clearValueCount = 1u,
.pClearValues = &clear_value
};

const Matrix4 view_projection = render_camera.projection * render_camera.view;
vkCmdBeginRenderPass(m_vk_command_buffer, &render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(m_vk_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_vk_pipeline);
vkCmdPushConstants(m_vk_command_buffer, m_vk_pipeline_layout, VK_SHADER_STAGE_ALL, 0u, sizeof(Matrix4), &view_projection);

for(const RenderObject& render_object : render_objects) {
vkCmdPushConstants(m_vk_command_buffer, m_vk_pipeline_layout, VK_SHADER_STAGE_ALL, sizeof(Matrix4), sizeof(Matrix4), &render_object.local_to_world);
vkCmdDraw(m_vk_command_buffer, 3u, 1u, 0u, 0u);
}

vkCmdEndRenderPass(m_vk_command_buffer);
}

void Render(const RenderCamera& render_camera, const eastl::hash_map<RenderBundleKey, std::vector<RenderBundleItem>>& render_bundles) override {
ZEPHYR_PANIC("unimplemented");
}
Expand Down
14 changes: 0 additions & 14 deletions zephyr/renderer/src/render_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ namespace zephyr {
}
}

void RenderScene::GetRenderObjects(std::vector<RenderObject>& out_render_objects, const GeometryCache& geometry_cache) {
out_render_objects.clear();

for(const EntityID entity_id : m_view_mesh) {
const Transform& entity_transform = m_components_transform[entity_id];
const Mesh& entity_mesh = m_components_mesh[entity_id];

out_render_objects.push_back({
.render_geometry = geometry_cache.GetCachedRenderGeometry(entity_mesh.geometry),
.local_to_world = entity_transform.local_to_world
});
}
}

void RenderScene::GetRenderCamera(RenderCamera& out_render_camera) {
// TODO(fleroviux): implement a better way to pick the camera to use.
if(m_view_camera.empty()) {
Expand Down

0 comments on commit b9668fc

Please sign in to comment.