Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ add_dz_test(DZ_ECSTest tests/ECS.cpp)
file(COPY images/Suzuho-Ueda.bmp DESTINATION ${CMAKE_BINARY_DIR}/images)
file(COPY images/hi.bmp DESTINATION ${CMAKE_BINARY_DIR}/images)
file(COPY models/SaiyanOne.glb DESTINATION ${CMAKE_BINARY_DIR}/models)
file(COPY models/GoldenSportsCar.glb DESTINATION ${CMAKE_BINARY_DIR}/models)
file(COPY models/GoldenSportsCar.glb DESTINATION ${CMAKE_BINARY_DIR}/models)
file(COPY hdri/autumn_field_puresky_4k.hdr DESTINATION ${CMAKE_BINARY_DIR}/hdri)
file(COPY hdri/zwartkops_straight_afternoon_4k.hdr DESTINATION ${CMAKE_BINARY_DIR}/hdri)
Binary file added hdri/autumn_field_puresky_4k.hdr
Binary file not shown.
Binary file added hdri/zwartkops_straight_afternoon_4k.hdr
Binary file not shown.
51 changes: 51 additions & 0 deletions include/dz/BlendState.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

namespace dz {
enum class BlendFactor
{
Zero = 0,
One = 1,
SrcColor = 2,
OneMinusSrcColor = 3,
DstColor = 4,
OneMinusDstColor = 5,
SrcAlpha = 6,
OneMinusSrcAlpha = 7,
DstAlpha = 8,
OneMinusDstAlpha = 9,
ConstantColor = 10,
OneMinusConstantColor = 11,
ConstantAlpha = 12,
OneMinusConstantAlpha = 13,
SrcAlphaSaturate = 14,
Src1Color = 15,
OneMinusSrc1Color = 16,
Src1Alpha = 17,
OneMinusSrc1Alpha = 18
};

enum class BlendOp
{
Add = 0,
Subtract = 1,
ReverseSubtract = 2,
Min = 3,
Max = 4
};

struct BlendState
{
bool enable = true;
BlendFactor srcColor = BlendFactor::SrcAlpha;
BlendFactor dstColor = BlendFactor::OneMinusSrcColor;
BlendFactor srcAlpha = BlendFactor::SrcAlpha;
BlendFactor dstAlpha = BlendFactor::OneMinusSrcAlpha;
BlendOp colorOp = BlendOp::Add;
BlendOp alphaOp = BlendOp::Add;
static BlendState Disabled;
static BlendState MainFramebuffer;
static BlendState Layout;
static BlendState Text;
static BlendState SrcAlpha;
};
}
4 changes: 2 additions & 2 deletions include/dz/DrawList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ namespace dz
// using FramebufferDrawList = std::unordered_map<Framebuffer*, ShaderDrawList>;

/**
* @brief A DrawTuples is the information required to produce a DrawList in a DrawListManager
* @brief A DrawTuple is the information required to produce a DrawList in a DrawListManager
*/
using DrawTuples = std::vector<std::tuple<Shader*, uint32_t>>;
using DrawTuple = std::tuple<Shader*, uint32_t>;

/**
* @brief A CameraTuple is the information required to draw from a cameras perspective
Expand Down
42 changes: 18 additions & 24 deletions include/dz/DrawListManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ namespace dz
template<typename DrawT>
struct DrawListManager : IDrawListManager
{
using Determine_DrawT_DrawTuples_Function = std::function<DrawTuples(BufferGroup*, DrawT&)>;
using Determine_DrawT_DrawTuple_Function = std::function<DrawTuple(BufferGroup*, DrawT&)>;
using Determine_CameraTuple_Function = std::function<CameraTuple(BufferGroup*, int)>;
using Determine_VisibleDraws_Function = std::function<std::vector<int>(BufferGroup*, int camera_index)>;
private:
Determine_DrawT_DrawTuples_Function fn_determine_DrawT_DrawTuples;
Determine_DrawT_DrawTuple_Function fn_determine_DrawT_DrawTuple;
Determine_CameraTuple_Function fn_determine_CameraTuple;
Determine_VisibleDraws_Function fn_get_visible_draws;
std::string draw_key;
Expand All @@ -54,15 +54,15 @@ namespace dz
* @brief Constructs a DrawListManager with a draw key and logic function.
*
* @param draw_key Buffer key to iterate over.
* @param fn_determine_DrawT_DrawTuples Function that maps a DrawT instance to shader and vertex count.
* @param fn_determine_DrawT_DrawTuple Function that maps a DrawT instance to shader and vertex count.
*/
DrawListManager(
const std::string& draw_key, const Determine_DrawT_DrawTuples_Function& fn_determine_DrawT_DrawTuples,
const std::string& draw_key, const Determine_DrawT_DrawTuple_Function& fn_determine_DrawT_DrawTuple,
const std::string& camera_key = "", const Determine_CameraTuple_Function& fn_determine_CameraTuple = {},
const Determine_VisibleDraws_Function& fn_get_visible_draws = {},
bool enable_global_camera_if_cameras_empty = true
):
fn_determine_DrawT_DrawTuples(fn_determine_DrawT_DrawTuples),
fn_determine_DrawT_DrawTuple(fn_determine_DrawT_DrawTuple),
fn_determine_CameraTuple(fn_determine_CameraTuple),
draw_key(draw_key),
camera_key(camera_key),
Expand Down Expand Up @@ -128,15 +128,10 @@ namespace dz
drawInformation.cameraDrawInfos.push_back(cameraDrawInfo);
}

auto drawTuplesMatch = [](const auto& a, const auto& b) -> bool
auto drawTupleMatch = [](const auto& a, const auto& b) -> bool
{
if (a.size() != b.size())
if (std::get<0>(a) != std::get<0>(b) || std::get<1>(a) != std::get<1>(b))
return false;
for (size_t k = 0; k < a.size(); ++k)
{
if (std::get<0>(a[k]) != std::get<0>(b[k]) || std::get<1>(a[k]) != std::get<1>(b[k]))
return false;
}
return true;
};

Expand All @@ -154,7 +149,7 @@ namespace dz

auto element_view = buffer_group_get_buffer_element_view(buffer_group, draw_key, i);
auto& element = element_view.template as_struct<DrawT>();
auto draw_tuples = fn_determine_DrawT_DrawTuples(buffer_group, element);
auto draw_tuple = fn_determine_DrawT_DrawTuple(buffer_group, element);

uint32_t run_start = static_cast<uint32_t>(i);
uint32_t instance_count = 1;
Expand All @@ -166,25 +161,24 @@ namespace dz
j = visible_entity_indices_data[vj];
auto next_element_view = buffer_group_get_buffer_element_view(buffer_group, draw_key, j);
auto& next_element = next_element_view.template as_struct<DrawT>();
auto next_draw_tuples = fn_determine_DrawT_DrawTuples(buffer_group, next_element);
auto next_draw_tuple = fn_determine_DrawT_DrawTuple(buffer_group, next_element);

if (!drawTuplesMatch(draw_tuples, next_draw_tuples))
if (!drawTupleMatch(draw_tuple, next_draw_tuple))
break;

instance_count += 1;
vj += 1;
}

for (auto& [shader, vertexCount] : draw_tuples)
{
DrawIndirectCommand cmd;
cmd.vertexCount = vertexCount;
cmd.instanceCount = instance_count;
cmd.firstVertex = 0;
cmd.firstInstance = run_start;
auto& [shader, vertexCount] = draw_tuple;

DrawIndirectCommand cmd;
cmd.vertexCount = vertexCount;
cmd.instanceCount = instance_count;
cmd.firstVertex = 0;
cmd.firstInstance = run_start;

cameraDrawInfo.shaderDrawList[shader].push_back(cmd);
}
cameraDrawInfo.shaderDrawList[shader].push_back(cmd);

vi = vj;
}
Expand Down
Loading
Loading