Skip to content

Commit

Permalink
refactor: move voxel stuff to engine
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 28, 2023
1 parent 272177a commit dfc2786
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 280 deletions.
5 changes: 0 additions & 5 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ set(CUBOS_CORE_SOURCE
"src/cubos/core/data/fs/file_system.cpp"
"src/cubos/core/data/fs/standard_archive.cpp"
"src/cubos/core/data/fs/embedded_archive.cpp"
"src/cubos/core/data/qb_parser.cpp"
"src/cubos/core/data/context.cpp"

"src/cubos/core/io/window.cpp"
Expand All @@ -63,11 +62,7 @@ set(CUBOS_CORE_SOURCE
"src/cubos/core/gl/render_device.cpp"
"src/cubos/core/gl/ogl_render_device.hpp"
"src/cubos/core/gl/ogl_render_device.cpp"
"src/cubos/core/gl/material.cpp"
"src/cubos/core/gl/palette.cpp"
"src/cubos/core/gl/grid.cpp"
"src/cubos/core/gl/util.cpp"
"src/cubos/core/gl/vertex.cpp"

"src/cubos/core/al/audio_device.cpp"
"src/cubos/core/al/oal_audio_device.cpp"
Expand Down
26 changes: 0 additions & 26 deletions core/include/cubos/core/data/qb_parser.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion core/include/cubos/core/gl/module.dox
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ namespace cubos::core::gl
{
/// @defgroup core-gl Graphics
/// @ingroup core
/// @brief Provides a graphics API abstraction and some voxel utilities.
/// @brief Provides a graphics API abstraction.
} // namespace cubos::core::gl
151 changes: 0 additions & 151 deletions core/src/cubos/core/data/qb_parser.cpp

This file was deleted.

4 changes: 4 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ set(CUBOS_ENGINE_SOURCE
"src/cubos/engine/scene/bridge.cpp"

"src/cubos/engine/voxels/plugin.cpp"
"src/cubos/engine/voxels/grid.cpp"
"src/cubos/engine/voxels/material.cpp"
"src/cubos/engine/voxels/palette.cpp"

"src/cubos/engine/collisions/plugin.cpp"
"src/cubos/engine/collisions/broad_phase.cpp"
Expand All @@ -54,6 +57,7 @@ set(CUBOS_ENGINE_SOURCE
"src/cubos/engine/input/axis.cpp"

"src/cubos/engine/renderer/plugin.cpp"
"src/cubos/engine/renderer/vertex.cpp"
"src/cubos/engine/renderer/frame.cpp"
"src/cubos/engine/renderer/renderer.cpp"
"src/cubos/engine/renderer/deferred_renderer.cpp"
Expand Down
6 changes: 3 additions & 3 deletions engine/include/cubos/engine/renderer/deferred_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <vector>

#include <cubos/core/gl/render_device.hpp>
#include <cubos/core/gl/vertex.hpp>

#include <cubos/engine/renderer/renderer.hpp>
#include <cubos/engine/renderer/vertex.hpp>
#include <cubos/engine/settings/settings.hpp>

// TODO: make these defines proper constants (we're using C++!)
Expand Down Expand Up @@ -40,8 +40,8 @@ namespace cubos::engine

// Implement interface methods.

RendererGrid upload(const core::gl::Grid& grid) override;
void setPalette(const core::gl::Palette& palette) override;
RendererGrid upload(const Grid& grid) override;
void setPalette(const Palette& palette) override;

protected:
// Implement interface methods.
Expand Down
7 changes: 3 additions & 4 deletions engine/include/cubos/engine/renderer/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

#pragma once

#include <cubos/core/gl/grid.hpp>
#include <cubos/core/gl/palette.hpp>

#include <cubos/engine/assets/plugin.hpp>
#include <cubos/engine/renderer/renderer.hpp>
#include <cubos/engine/voxels/grid.hpp>
#include <cubos/engine/voxels/palette.hpp>

namespace cubos::engine
{
Expand Down Expand Up @@ -68,7 +67,7 @@ namespace cubos::engine
/// @ingroup renderer-plugin
struct [[cubos::component("cubos/renderable_grid", VecStorage)]] RenderableGrid
{
Asset<core::gl::Grid> asset; ///< Handle to the grid asset to be rendered.
Asset<Grid> asset; ///< Handle to the grid asset to be rendered.
glm::vec3 offset = {0.0F, 0.0F, 0.0F}; ///< Translation applied to the voxel grid before any other.
[[cubos::ignore]] RendererGrid handle = nullptr; ///< Handle to the uploaded grid - set automatically.
};
Expand Down
10 changes: 5 additions & 5 deletions engine/include/cubos/engine/renderer/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

#include <glm/glm.hpp>

#include <cubos/core/gl/grid.hpp>
#include <cubos/core/gl/palette.hpp>
#include <cubos/core/gl/render_device.hpp>
#include <cubos/core/gl/vertex.hpp>
#include <cubos/core/io/window.hpp>

#include <cubos/engine/renderer/camera.hpp>
#include <cubos/engine/renderer/pps/manager.hpp>
#include <cubos/engine/renderer/vertex.hpp>
#include <cubos/engine/voxels/grid.hpp>
#include <cubos/engine/voxels/palette.hpp>

namespace cubos::engine
{
Expand Down Expand Up @@ -74,11 +74,11 @@ namespace cubos::engine
/// @brief Uploads a grid to the GPU and returns an handle which can be used to draw it.
/// @param grid Grid to upload.
/// @return Handle of the grid.
virtual RendererGrid upload(const core::gl::Grid& grid) = 0;
virtual RendererGrid upload(const Grid& grid) = 0;

/// @brief Sets the current palette of the renderer.
/// @param palette Palette to set.
virtual void setPalette(const core::gl::Palette& palette) = 0;
virtual void setPalette(const Palette& palette) = 0;

/// @brief Resizes the renderer's framebuffers.
/// @param size New size of the window.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// @file
/// @brief Class @ref cubos::core::gl::Vertex and function @ref cubos::core::gl::triangulate.
/// @ingroup core-gl
/// @brief Class @ref cubos::engine::Vertex and function @ref cubos::engine::triangulate.
/// @ingroup renderer-plugin

#pragma once

Expand All @@ -9,12 +9,12 @@
#include <cubos/core/data/deserializer.hpp>
#include <cubos/core/data/serializer.hpp>

namespace cubos::core::gl
namespace cubos::engine
{
class Grid;

/// @brief Represents a voxel vertex.
/// @ingroup core-gl
/// @ingroup renderer-plugin
struct Vertex
{
glm::uvec3 position; ///< Position of the vertex.
Expand All @@ -26,12 +26,12 @@ namespace cubos::core::gl
/// @param grid Grid to triangulate.
/// @param vertices Vertices of the mesh.
/// @param indices Indices of the mesh.
/// @ingroup core-gl
/// @ingroup renderer-plugin
void triangulate(const Grid& grid, std::vector<Vertex>& vertices, std::vector<uint32_t>& indices);
} // namespace cubos::core::gl
} // namespace cubos::engine

namespace cubos::core::data
{
void serialize(Serializer& serializer, const gl::Vertex& vertex, const char* name);
void deserialize(Deserializer& deserializer, gl::Vertex& vertex);
void serialize(Serializer& serializer, const engine::Vertex& vertex, const char* name);
void deserialize(Deserializer& deserializer, engine::Vertex& vertex);
} // namespace cubos::core::data
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// @file
/// @brief Class @ref cubos::core::gl::Grid.
/// @ingroup core-gl
/// @brief Class @ref cubos::engine::Grid.
/// @ingroup voxels-plugin

#pragma once

Expand All @@ -11,23 +11,23 @@
#include <cubos/core/data/deserializer.hpp>
#include <cubos/core/data/serializer.hpp>

namespace cubos::core::gl
namespace cubos::engine
{
class Palette;
class Grid;
} // namespace cubos::core::gl
} // namespace cubos::engine

namespace cubos::core::data
{
void serialize(Serializer& serializer, const gl::Grid& grid, const char* name);
void deserialize(Deserializer& deserializer, gl::Grid& grid);
void serialize(Serializer& serializer, const engine::Grid& grid, const char* name);
void deserialize(Deserializer& deserializer, engine::Grid& grid);
} // namespace cubos::core::data

namespace cubos::core::gl
namespace cubos::engine
{
/// @brief Represents a voxel object using a 3D grid.
/// @see Each voxel stores a material index to be used with a @ref Palette.
/// @ingroup core-gl
/// @ingroup voxels-plugin
class Grid final
{
public:
Expand Down Expand Up @@ -89,10 +89,11 @@ namespace cubos::core::gl
bool convert(const Palette& src, const Palette& dst, float minSimilarity);

private:
friend void data::serialize(data::Serializer& /*serializer*/, const Grid& /*grid*/, const char* /*name*/);
friend void data::deserialize(data::Deserializer& /*deserializer*/, Grid& /*grid*/);
friend void core::data::serialize(core::data::Serializer& /*serializer*/, const Grid& /*grid*/,
const char* /*name*/);
friend void core::data::deserialize(core::data::Deserializer& /*deserializer*/, Grid& /*grid*/);

glm::uvec3 mSize; ///< Size of the grid.
std::vector<uint16_t> mIndices; ///< Indices of the grid.
};
} // namespace cubos::core::gl
} // namespace cubos::engine
Loading

0 comments on commit dfc2786

Please sign in to comment.