Changed function signatures to remove const qualifiers
Changed several function signatures across multiple files to remove the `const` qualifier from parameters of type `vec3s` for improved flexibility. Changed `material_collection_create` to `material_collection_init` for better initialization handling. Changed `scene_create` to `scene_init` to return a boolean indicating success or failure. Changed `render_target_create` to `render_target_init` for consistent initialization practices. Changed `window_create` to remove `const` from its parameters for consistency. Changed `evaluate_bsdf_directional` and `evaluate_bsdf_const_sky` to remove `const` from their parameters. Changed `sample_bsdf_simple_lit` and `sample_bsdf_pdf_simple_lit` to remove `const` from the `normal` parameter. Changed `scene_render` to take a pointer to `render_target_t` instead of returning it directly. Updated `main.c` to reflect new initialization functions for better memory management.
This commit is contained in:
@@ -25,8 +25,8 @@ inline void quad_create(vec3s center, vec3s forward, vec3s up, float size, uint8
|
||||
|
||||
inline void sphere_create(vec3s center, float radius, uint8_t material_id, triangle_collection_t* collection)
|
||||
{
|
||||
const int segments = 8;
|
||||
const int rings = 8;
|
||||
int segments = 8;
|
||||
int rings = 8;
|
||||
|
||||
for (int i = 0; i < rings; i++)
|
||||
{
|
||||
|
||||
@@ -26,13 +26,55 @@ typedef struct
|
||||
triangle_t* buffer;
|
||||
}triangle_collection_t;
|
||||
|
||||
triangle_collection_t triangle_collection_create(size_t size);
|
||||
void triangle_collection_resize(triangle_collection_t* collection, size_t size);
|
||||
void triangle_collection_free(triangle_collection_t* collection);
|
||||
void triangle_create_with_normals(vec3s point1, vec3s point2, vec3s point3,
|
||||
vec3s normal1, vec3s normal2, vec3s normal3,
|
||||
uint8_t material_id, triangle_collection_t* collection);
|
||||
void triangle_create(vec3s point1, vec3s point2, vec3s point3, uint8_t material_id, triangle_collection_t* collection);
|
||||
|
||||
inline bool triangle_collection_init(size_t size, triangle_collection_t* triangles)
|
||||
{
|
||||
if (size > UINT64_MAX)
|
||||
{
|
||||
size = UINT64_MAX;
|
||||
}
|
||||
|
||||
triangle_collection_t temp = {0};
|
||||
temp.buffer = (triangle_t*)malloc(size * sizeof(triangle_t));
|
||||
if (temp.buffer == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
temp.size = (uint64_t)size;
|
||||
temp.count = 0;
|
||||
|
||||
*triangles = temp;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void triangle_collection_resize(triangle_collection_t* collection, size_t size)
|
||||
{
|
||||
if (size > UINT64_MAX)
|
||||
{
|
||||
size = UINT64_MAX;
|
||||
}
|
||||
|
||||
triangle_t* temp = (triangle_t*)realloc(collection->buffer, size * sizeof(triangle_t));
|
||||
if (temp != NULL)
|
||||
{
|
||||
collection->buffer = temp;
|
||||
collection->size = (uint64_t)size;
|
||||
}
|
||||
}
|
||||
|
||||
inline void triangle_collection_free(triangle_collection_t* collection)
|
||||
{
|
||||
if (collection->buffer != NULL)
|
||||
{
|
||||
free(collection->buffer);
|
||||
collection->buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void triangle_create_with_normals(const vec3s point1, const vec3s point2, const vec3s point3,
|
||||
const vec3s normal1, const vec3s normal2, const vec3s normal3,
|
||||
const uint8_t material_id, triangle_collection_t* collection);
|
||||
void triangle_create(const vec3s point1, const vec3s point2, const vec3s point3, const uint8_t material_id, triangle_collection_t* collection);
|
||||
|
||||
#endif // TRIANGLE_H
|
||||
|
||||
Reference in New Issue
Block a user