Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
WIP 0

WIP 1

WIP

WIP cleanup
WIP cleanup

WIP

WIP

WIP

WIP
  • Loading branch information
hoffstadt committed Jan 18, 2025
1 parent e5cc75b commit c1c2b84
Show file tree
Hide file tree
Showing 37 changed files with 3,795 additions and 2,460 deletions.
4 changes: 3 additions & 1 deletion extensions/pl_debug_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Index of this file:
// core
#include <float.h>
#include "pl.h"
#include "pl_ds.h"

#include "pl_debug_ext.h"
#define PL_MATH_INCLUDE_FUNCTIONS
#include "pl_math.h"
Expand Down Expand Up @@ -103,6 +103,8 @@ static plDebugContext* gptDebugCtx = NULL;

#endif

#include "pl_ds.h"

//-----------------------------------------------------------------------------
// [SECTION] internal api
//-----------------------------------------------------------------------------
Expand Down
26 changes: 13 additions & 13 deletions extensions/pl_draw_backend_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Index of this file:
#include <float.h>
#include "pl.h"
#include "pl_memory.h"
#include "pl_ds.h"
#define PL_MATH_INCLUDE_FUNCTIONS
#include "pl_math.h"

Expand All @@ -33,8 +32,21 @@ Index of this file:

#ifdef PL_UNITY_BUILD
#include "pl_unity_ext.inc"
#else
static const plMemoryI* gptMemory = NULL;
#define PL_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
#define PL_REALLOC(x, y) gptMemory->tracked_realloc((x), (y), __FILE__, __LINE__)
#define PL_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)

#ifndef PL_DS_ALLOC
#define PL_DS_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
#define PL_DS_ALLOC_INDIRECT(x, FILE, LINE) gptMemory->tracked_realloc(NULL, (x), FILE, LINE)
#define PL_DS_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)
#endif
#endif

#include "pl_ds.h"

//-----------------------------------------------------------------------------
// [SECTION] internal structs
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -85,18 +97,6 @@ typedef struct _plDrawBackendContext

static plDrawBackendContext* gptDrawBackendCtx = NULL;

#ifndef PL_UNITY_BUILD
static const plMemoryI* gptMemory = NULL;
#define PL_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
#define PL_REALLOC(x, y) gptMemory->tracked_realloc((x), (y), __FILE__, __LINE__)
#define PL_FREE(x) gptMemory->tracked_realloc((x), 0, __FILE__, __LINE__)

static const plGraphicsI* gptGfx = NULL;
static const plStatsI* gptStats = NULL;
static const plDrawI* gptDraw = NULL;
static const plShaderI* gptShader = NULL;
#endif

//-----------------------------------------------------------------------------
// [SECTION] internal api
//-----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion extensions/pl_draw_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Index of this file:
#include "pl.h"
#define PL_MATH_INCLUDE_FUNCTIONS
#include "pl_draw_ext.h"
#include "pl_ds.h"
#include "pl_memory.h"
#include "pl_string.h"

Expand Down Expand Up @@ -140,6 +139,8 @@ static unsigned char* ptrDOut_ = NULL;
static const plFileI* gptFile = NULL;
#endif

#include "pl_ds.h"

//-----------------------------------------------------------------------------
// [SECTION] internal api
//-----------------------------------------------------------------------------
Expand Down
84 changes: 80 additions & 4 deletions extensions/pl_ecs_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Index of this file:
#define PL_MATH_INCLUDE_FUNCTIONS
#include "pl.h"
#include "pl_ecs_ext.h"
#include "pl_ds.h"
#include "pl_math.h"

// extensions
Expand Down Expand Up @@ -51,6 +50,8 @@ Index of this file:
static const plLogI* gptLog = NULL;
#endif

#include "pl_ds.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -114,6 +115,9 @@ static void pl_run_hierarchy_update_system (plComponentLibrary* ptLibrar
static void pl_run_animation_update_system (plComponentLibrary* ptLibrary, float fDeltaTime);
static void pl_run_inverse_kinematics_update_system(plComponentLibrary* ptLibrary);
static void pl_run_script_update_system (plComponentLibrary* ptLibrary);
static void pl_run_camera_update_system (plComponentLibrary* ptLibrary);
static void pl_run_light_update_system (plComponentLibrary* ptLibrary);
static void pl_run_probe_update_system (plComponentLibrary* ptLibrary);

// misc.
static void pl_calculate_normals (plMeshComponent* atMeshes, uint32_t uComponentCount);
Expand Down Expand Up @@ -590,7 +594,7 @@ pl_ecs_add_component(plComponentLibrary* ptLibrary, plComponentType tType, plEnt
ptManager->pComponents = sbComponents;
sbComponents[uComponentIndex] = (plMaterialComponent){
.tBlendMode = PL_BLEND_MODE_OPAQUE,
.tFlags = PL_MATERIAL_FLAG_NONE,
.tFlags = PL_MATERIAL_FLAG_CAST_SHADOW | PL_MATERIAL_FLAG_CAST_RECEIVE_SHADOW,
.tShaderType = PL_SHADER_TYPE_PBR,
.tBaseColor = {1.0f, 1.0f, 1.0f, 1.0f},
.tEmissiveColor = {0.0f, 0.0f, 0.0f, 0.0f},
Expand Down Expand Up @@ -724,7 +728,8 @@ pl_ecs_add_component(plComponentLibrary* ptLibrary, plComponentType tType, plEnt
ptManager->pComponents = sbComponents;
sbComponents[uComponentIndex] = (plEnvironmentProbeComponent){
.fRange = 10.0f,
.uResolution = 128
.uResolution = 128,
.tFlags = PL_ENVIRONMENT_PROBE_FLAGS_DIRTY
};
return &sbComponents[uComponentIndex];
}
Expand Down Expand Up @@ -1220,6 +1225,74 @@ pl_run_script_update_system(plComponentLibrary* ptLibrary)
pl_end_cpu_sample(gptProfile, 0);
}

static void
pl_run_camera_update_system(plComponentLibrary* ptLibrary)
{
pl_begin_cpu_sample(gptProfile, 0, __FUNCTION__);

plCameraComponent* sbtComponents = ptLibrary->tCameraComponentManager.pComponents;

const uint32_t uComponentCount = pl_sb_size(sbtComponents);
for(uint32_t i = 0; i < uComponentCount; i++)
{
plEntity tEntity = ptLibrary->tCameraComponentManager.sbtEntities[i];
if(pl_ecs_has_entity(&ptLibrary->tTransformComponentManager, tEntity))
{
plCameraComponent* ptCamera = &sbtComponents[i];
plTransformComponent* ptTransform = pl_ecs_get_component(ptLibrary, PL_COMPONENT_TYPE_TRANSFORM, tEntity);
ptCamera->tPos = ptTransform->tWorld.col[3].xyz;
pl_camera_update(ptCamera);
}
}
pl_end_cpu_sample(gptProfile, 0);
}

static void
pl_run_light_update_system(plComponentLibrary* ptLibrary)
{
pl_begin_cpu_sample(gptProfile, 0, __FUNCTION__);

plLightComponent* sbtComponents = ptLibrary->tLightComponentManager.pComponents;

const uint32_t uComponentCount = pl_sb_size(sbtComponents);
for(uint32_t i = 0; i < uComponentCount; i++)
{
plEntity tEntity = ptLibrary->tLightComponentManager.sbtEntities[i];
if(pl_ecs_has_entity(&ptLibrary->tTransformComponentManager, tEntity))
{
plLightComponent* ptLight = &sbtComponents[i];
plTransformComponent* ptTransform = pl_ecs_get_component(ptLibrary, PL_COMPONENT_TYPE_TRANSFORM, tEntity);
ptLight->tPosition = ptTransform->tWorld.col[3].xyz;

// TODO: direction
}
}
pl_end_cpu_sample(gptProfile, 0);
}

static void
pl_run_probe_update_system(plComponentLibrary* ptLibrary)
{
pl_begin_cpu_sample(gptProfile, 0, __FUNCTION__);

plEnvironmentProbeComponent* sbtComponents = ptLibrary->tEnvironmentProbeCompManager.pComponents;

const uint32_t uComponentCount = pl_sb_size(sbtComponents);
for(uint32_t i = 0; i < uComponentCount; i++)
{
plEntity tEntity = ptLibrary->tEnvironmentProbeCompManager.sbtEntities[i];
if(pl_ecs_has_entity(&ptLibrary->tTransformComponentManager, tEntity))
{
plEnvironmentProbeComponent* ptProbe = &sbtComponents[i];
plTransformComponent* ptTransform = pl_ecs_get_component(ptLibrary, PL_COMPONENT_TYPE_TRANSFORM, tEntity);
ptProbe->tPosition = ptTransform->tWorld.col[3].xyz;

// TODO: direction
}
}
pl_end_cpu_sample(gptProfile, 0);
}

static void
pl_run_animation_update_system(plComponentLibrary* ptLibrary, float fDeltaTime)
{
Expand Down Expand Up @@ -1851,7 +1924,10 @@ pl_load_ecs_ext(plApiRegistryI* ptApiRegistry, bool bReload)
.run_skin_update_system = pl_run_skin_update_system,
.run_animation_update_system = pl_run_animation_update_system,
.run_inverse_kinematics_update_system = pl_run_inverse_kinematics_update_system,
.run_script_update_system = pl_run_script_update_system
.run_script_update_system = pl_run_script_update_system,
.run_camera_update_system = pl_run_camera_update_system,
.run_light_update_system = pl_run_light_update_system,
.run_environment_probe_update_system = pl_run_probe_update_system
};
pl_set_api(ptApiRegistry, plEcsI, &tApi0);

Expand Down
11 changes: 8 additions & 3 deletions extensions/pl_ecs_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ typedef struct _plEcsI
void (*run_animation_update_system) (plComponentLibrary*, float fDeltaTime);
void (*run_inverse_kinematics_update_system)(plComponentLibrary*);
void (*run_script_update_system) (plComponentLibrary*);
void (*run_camera_update_system) (plComponentLibrary*);
void (*run_light_update_system) (plComponentLibrary*);
void (*run_environment_probe_update_system) (plComponentLibrary*);
} plEcsI;

typedef struct _plCameraI
Expand Down Expand Up @@ -218,9 +221,11 @@ enum _plShaderType

enum _plMaterialFlags
{
PL_MATERIAL_FLAG_NONE = 0,
PL_MATERIAL_FLAG_DOUBLE_SIDED = 1 << 0,
PL_MATERIAL_FLAG_OUTLINE = 1 << 1,
PL_MATERIAL_FLAG_NONE = 0,
PL_MATERIAL_FLAG_DOUBLE_SIDED = 1 << 0,
PL_MATERIAL_FLAG_OUTLINE = 1 << 1,
PL_MATERIAL_FLAG_CAST_SHADOW = 1 << 2,
PL_MATERIAL_FLAG_CAST_RECEIVE_SHADOW = 1 << 3
};

enum _plBlendMode
Expand Down
3 changes: 2 additions & 1 deletion extensions/pl_gpu_allocators_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Index of this file:
#include "pl_graphics_ext.h"
#define PL_MATH_INCLUDE_FUNCTIONS
#include "pl_math.h"
#include "pl_ds.h"

#ifdef PL_UNITY_BUILD
#include "pl_unity_ext.inc"
Expand All @@ -40,6 +39,8 @@ Index of this file:
static const plDataRegistryI* gptDataRegistry = NULL;
#endif

#include "pl_ds.h"

//-----------------------------------------------------------------------------
// [SECTION] defines
//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions extensions/pl_graphics_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload)
.present = pl_present,
.copy_buffer_to_texture = pl_copy_buffer_to_texture,
.copy_texture_to_buffer = pl_copy_texture_to_buffer,
.copy_texture = pl_copy_texture,
.generate_mipmaps = pl_generate_mipmaps,
.copy_buffer = pl_copy_buffer,
.signal_semaphore = pl_signal_semaphore,
Expand Down
33 changes: 31 additions & 2 deletions extensions/pl_graphics_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Index of this file:
// [SECTION] apis
//-----------------------------------------------------------------------------

#define plGraphicsI_version (plVersion){1, 2, 0}
#define plGraphicsI_version (plVersion){1, 2, 1}

//-----------------------------------------------------------------------------
// [SECTION] includes
Expand Down Expand Up @@ -95,6 +95,7 @@ typedef struct _plRenderEncoder plRenderEncoder; // opaque type for
typedef struct _plComputeEncoder plComputeEncoder; // opaque type for command buffer encoder for compute ops
typedef struct _plBlitEncoder plBlitEncoder; // opaque type for command buffer encoder for blit ops
typedef struct _plBufferImageCopy plBufferImageCopy; // used for copying between buffers & textures with blit encoder
typedef struct _plImageCopy plImageCopy; // used for copying between textures with blit encoder
typedef struct _plPassTextureResource plPassTextureResource;
typedef struct _plPassBufferResource plPassBufferResource;
typedef struct _plPassResources plPassResources;
Expand Down Expand Up @@ -299,6 +300,7 @@ typedef struct _plGraphicsI
void (*set_texture_usage) (plBlitEncoder*, plTextureHandle, plTextureUsage tNewUsage, plTextureUsage tOldUsage);
void (*copy_buffer_to_texture) (plBlitEncoder*, plBufferHandle, plTextureHandle, uint32_t regionCount, const plBufferImageCopy*);
void (*copy_texture_to_buffer) (plBlitEncoder*, plTextureHandle, plBufferHandle, uint32_t regionCount, const plBufferImageCopy*);
void (*copy_texture) (plBlitEncoder*, plTextureHandle, plTextureHandle, uint32_t regionCount, const plImageCopy*);
void (*generate_mipmaps) (plBlitEncoder*, plTextureHandle);
void (*copy_buffer) (plBlitEncoder*, plBufferHandle source, plBufferHandle destination, uint32_t sourceOffset, uint32_t destinationOffset, size_t);

Expand Down Expand Up @@ -556,8 +558,10 @@ typedef struct _plBindGroupUpdateBufferData
{
plBufferHandle tBuffer;
uint32_t uSlot;
size_t szOffset;
size_t szBufferRange;

// [INTERNAL]
size_t _szOffset; // vulkan only :(
} plBindGroupUpdateBufferData;

typedef struct _plBindGroupUpdateData
Expand Down Expand Up @@ -630,6 +634,7 @@ typedef struct _plBindGroup

// [INTERNAL]
uint16_t _uGeneration;
plTextureHandle* _sbtTextures;
} plBindGroup;

//-------------------------------shaders---------------------------------------
Expand Down Expand Up @@ -885,6 +890,30 @@ typedef struct _plBufferImageCopy
plTextureUsage tCurrentImageUsage;
} plBufferImageCopy;

typedef struct _plImageCopy
{
// source info
int iSourceOffsetX;
int iSourceOffsetY;
int iSourceOffsetZ;
uint32_t uSourceExtentX;
uint32_t uSourceExtentY;
uint32_t uSourceExtentZ;
uint32_t uSourceMipLevel;
uint32_t uSourceBaseArrayLayer;
uint32_t uSourceLayerCount;
plTextureUsage tSourceImageUsage;

// destination offset
int iDestinationOffsetX;
int iDestinationOffsetY;
int iDestinationOffsetZ;
uint32_t uDestinationMipLevel;
uint32_t uDestinationBaseArrayLayer;
uint32_t uDestinationLayerCount;
plTextureUsage tDestinationImageUsage;
} plImageCopy;

typedef struct _plDrawArea
{
plRenderViewport atViewports[PL_MAX_VIEWPORTS];
Expand Down
3 changes: 2 additions & 1 deletion extensions/pl_graphics_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define PL_GRAPHICS_INTERNAL_EXT_H

#include "pl.h"
#include "pl_ds.h"
#include "pl_log_ext.h"
#include "pl_threads_ext.h"
#include "pl_graphics_ext.h"
Expand Down Expand Up @@ -34,6 +33,8 @@
static plIO* gptIO = NULL;
#endif

#include "pl_ds.h"

//-----------------------------------------------------------------------------
// [SECTION] global data
//-----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit c1c2b84

Please sign in to comment.