formatted license comment

This commit is contained in:
Lorenzo Torres 2025-11-04 00:00:52 +01:00
parent db5a728846
commit 0ffdb8c3ac
30 changed files with 16218 additions and 14914 deletions

3
.gitignore vendored
View file

@ -2,3 +2,6 @@
.clang-format .clang-format
compile-commands.json compile-commands.json
topaz topaz
**/*.BAK
**/*.bak
**/*~

1
.indent.pro vendored
View file

@ -12,3 +12,4 @@
-npsl -npsl
-di1 -di1
-ldi1 -ldi1
-nfc1

View file

@ -1,11 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "arena.h" #include "arena.h"
#include <stdlib.h> #include <stdlib.h>
struct arena_allocator *arena_init(usize size) struct arena_allocator *arena_init(usize size)
{ {
struct arena_allocator *allocator = (struct arena_allocator *) malloc(sizeof(struct arena_allocator)); struct arena_allocator *allocator = (struct arena_allocator *)malloc(sizeof(struct arena_allocator));
allocator->size = size; allocator->size = size;
allocator->base = (usize) malloc(size); allocator->base = (usize) malloc(size);
allocator->position = 0; allocator->position = 0;
@ -27,15 +27,15 @@ void *arena_alloc(struct arena_allocator *allocator, usize size)
} }
void *ptr = (void *)(allocator->base + allocator->position); void *ptr = (void *)(allocator->base + allocator->position);
allocator->position += size; allocator->position += size;
return ptr; return ptr;
} }
void *arena_zalloc(struct arena_allocator *allocator, usize size) void *arena_zalloc(struct arena_allocator *allocator, usize size)
{ {
void *ptr = arena_alloc(allocator, size); void *ptr = arena_alloc(allocator, size);
for (usize i=0; i < size; i++) { for (usize i = 0; i < size; i++) {
((u8 *)ptr)[i] = 0x0; ((u8 *) ptr)[i] = 0x0;
} }
return ptr; return ptr;

View file

@ -1,15 +1,13 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef ARENA_H #ifndef ARENA_H
#define ARENA_H #define ARENA_H
#include "../types.h" #include "../types.h"
/* /*
* An arena is a fast allocator that just * An arena is a fast allocator that just keeps everything in a contiguous
* keeps everything in a contiguous chunk * chunk of memory and moves a "pointer" when allocating new memory. The
* of memory and moves a "pointer" when * allocated memory is then free'd all at once.
* allocating new memory. The allocated
* memory is then free'd all at once.
*/ */
struct arena_allocator { struct arena_allocator {
usize size; usize size;
@ -25,19 +23,16 @@ struct arena_allocator *arena_init(usize size);
void arena_deinit(struct arena_allocator *allocator); void arena_deinit(struct arena_allocator *allocator);
/* /*
* Allocate a chunk of memory of size `size` on the * Allocate a chunk of memory of size `size` on the arena.
* arena.
*/ */
void *arena_alloc(struct arena_allocator *allocator, usize size); void *arena_alloc(struct arena_allocator *allocator, usize size);
/* /*
* Same as `arena_alloc()` but also set all the allocated * Same as `arena_alloc()` but also set all the allocated memory to zero.
* memory to zero.
*/ */
void *arena_zalloc(struct arena_allocator *allocator, usize size); void *arena_zalloc(struct arena_allocator *allocator, usize size);
/* /*
* Free all the allocated memory at once. * Free all the allocated memory at once. This just sets the allocator cursor
* This just sets the allocator cursor to its * to its starting position.
* starting position.
*/ */
void arena_bump(struct arena_allocator *allocator); void arena_bump(struct arena_allocator *allocator);

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef LOG_H #ifndef LOG_H
#define LOG_H #define LOG_H

View file

@ -1,11 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "vector.h" #include "vector.h"
#include "log.h" #include "log.h"
struct vector *vector_init(usize size, usize element_size) struct vector *vector_init(usize size, usize element_size)
{ {
if (size == 0) size = 1; if (size == 0)
struct vector *vector = (struct vector *) malloc(sizeof(struct vector)); size = 1;
struct vector *vector = (struct vector *)malloc(sizeof(struct vector));
vector->length = 0; vector->length = 0;
vector->size = size; vector->size = size;
vector->data = malloc(size * element_size); vector->data = malloc(size * element_size);
@ -14,12 +15,13 @@ struct vector *vector_init(usize size, usize element_size)
void *vector_shrink(struct vector *vector, usize element_size) void *vector_shrink(struct vector *vector, usize element_size)
{ {
#ifdef DEBUG #ifdef DEBUG
if (vector->length == 0) log_error("Popping from an empty vector.\n"); if (vector->length == 0)
#endif log_error("Popping from an empty vector.\n");
#endif
vector->length -= 1; vector->length -= 1;
if (vector->length <= vector->size/3) { if (vector->length <= vector->size / 3) {
vector->size = vector->length + vector->length/2; vector->size = vector->length + vector->length / 2;
vector->data = realloc(vector->data, vector->size * element_size + 1); vector->data = realloc(vector->data, vector->size * element_size + 1);
} }
return vector->data; return vector->data;

View file

@ -1,41 +1,39 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef VECTOR_H #ifndef VECTOR_H
#define VECTOR_H #define VECTOR_H
#include <stdlib.h> #include <stdlib.h>
#include "../types.h" #include "../types.h"
/* The vector is a dynamically growing array /*
* that can be operated as a regular array * The vector is a dynamically growing array that can be operated as a regular
* by accessing its `data` member and as a * array by accessing its `data` member and as a stack using `vector_push()`
* stack using `vector_push()` and `vector_pop()`. * and `vector_pop()`.
*/ */
struct vector { struct vector {
usize length, size; usize length, size;
void *data; void *data;
}; };
/* /*
* Create a new vector with starting capacity of `size` * Create a new vector with starting capacity of `size` where each element has
* where each element has size `element_size`. * size `element_size`.
*/ */
struct vector *vector_init(usize size, usize element_size); struct vector *vector_init(usize size, usize element_size);
void vector_deinit(struct vector *vector); void vector_deinit(struct vector *vector);
/* /*
* This function reduces the lenth of the vector thus * This function reduces the lenth of the vector thus removing the last
* removing the last element. If the used memory (length) * element. If the used memory (length) is less than 1/3 of the allocated
* is less than 1/3 of the allocated memory (size) the * memory (size) the memory is reallocated to fit 1.5x the new length. Consider
* memory is reallocated to fit 1.5x the new length. * using the `vector_pop()` macro instead.
* Consider using the `vector_pop()` macro instead.
*/ */
void *vector_shrink(struct vector *vector, usize element_size); void *vector_shrink(struct vector *vector, usize element_size);
/* /*
* Push `value` on the vector. If there isn't enough * Push `value` on the vector. If there isn't enough allocated memory,
* allocated memory, reallocate the internal array * reallocate the internal array to be 1.5x the current size and copy all the
* to be 1.5x the current size and copy all the elements * elements to the new allocated memory.
* to the new allocated memory.
*/ */
#define vector_push(vec, T, value) do {\ #define vector_push(vec, T, value) do {\
if (vec->length + 1 >= vec->size) {\ if (vec->length + 1 >= vec->size) {\
@ -47,8 +45,8 @@ void *vector_shrink(struct vector *vector, usize element_size);
} while (0) } while (0)
/* /*
* Return the last element of the vector and calls * Return the last element of the vector and calls `vector_shrink()`. Check out
* `vector_shrink()`. Check out that function description. * that function description.
*/ */
#define vector_pop(vector, T) (((T*)vector_shrink((vector), sizeof(T)))[vector->length]) #define vector_pop(vector, T) (((T*)vector_shrink((vector), sizeof(T)))[vector->length])

3310
gl/gl.c

File diff suppressed because it is too large Load diff

3160
gl/gl.h

File diff suppressed because it is too large Load diff

View file

@ -2,96 +2,86 @@
#define __khrplatform_h_ #define __khrplatform_h_
/* /*
** Copyright (c) 2008-2018 The Khronos Group Inc. * * Copyright (c) 2008-2018 The Khronos Group Inc. *
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/* Khronos platform-specific types and definitions.
* *
* The master copy of khrplatform.h is maintained in the Khronos EGL * * Permission is hereby granted, free of charge, to any person obtaining a *
* Registry repository at https://github.com/KhronosGroup/EGL-Registry * copy of this software and/or associated documentation files (the *
* The last semantic modification to khrplatform.h was at commit ID: * "Materials"), to deal in the Materials without restriction, including *
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692 * without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Materials, and to * permit
* persons to whom the Materials are furnished to do so, subject to * the
* following conditions: *
*
* * The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Materials. *
*
* * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * MATERIALS OR THE
* USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/*
* Khronos platform-specific types and definitions.
*
* The master copy of khrplatform.h is maintained in the Khronos EGL Registry
* repository at https://github.com/KhronosGroup/EGL-Registry The last semantic
* modification to khrplatform.h was at commit ID:
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
* *
* Adopters may modify this file to suit their platform. Adopters are * Adopters may modify this file to suit their platform. Adopters are
* encouraged to submit platform specific modifications to the Khronos * encouraged to submit platform specific modifications to the Khronos group so
* group so that they can be included in future versions of this file. * that they can be included in future versions of this file. Please submit
* Please submit changes by filing pull requests or issues on * changes by filing pull requests or issues on the EGL Registry repository
* the EGL Registry repository linked above. * linked above.
* *
* *
* See the Implementer's Guidelines for information about where this file * See the Implementer's Guidelines for information about where this file
* should be located on your system and for more details of its use: * should be located on your system and for more details of its use:
* http://www.khronos.org/registry/implementers_guide.pdf * http://www.khronos.org/registry/implementers_guide.pdf
* *
* This file should be included as * This file should be included as #include <KHR/khrplatform.h> by Khronos
* #include <KHR/khrplatform.h> * client API header files that use its types and defines.
* by Khronos client API header files that use its types and defines.
* *
* The types in khrplatform.h should only be used to define API-specific types. * The types in khrplatform.h should only be used to define API-specific types.
* *
* Types defined in khrplatform.h: * Types defined in khrplatform.h: khronos_int8_t signed 8 bit
* khronos_int8_t signed 8 bit * khronos_uint8_t unsigned 8 bit khronos_int16_t signed 16 bit
* khronos_uint8_t unsigned 8 bit * khronos_uint16_t unsigned 16 bit khronos_int32_t signed 32 bit
* khronos_int16_t signed 16 bit * khronos_uint32_t unsigned 32 bit khronos_int64_t signed 64 bit
* khronos_uint16_t unsigned 16 bit * khronos_uint64_t unsigned 64 bit khronos_intptr_t signed same
* khronos_int32_t signed 32 bit * number of bits as a pointer khronos_uintptr_t unsigned same number of bits
* khronos_uint32_t unsigned 32 bit * as a pointer khronos_ssize_t signed size khronos_usize_t
* khronos_int64_t signed 64 bit * unsigned size khronos_float_t signed 32 bit floating point
* khronos_uint64_t unsigned 64 bit * khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_intptr_t signed same number of bits as a pointer * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* khronos_uintptr_t unsigned same number of bits as a pointer * nanoseconds khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_ssize_t signed size * khronos_boolean_enum_t enumerated boolean type. This should only be
* khronos_usize_t unsigned size * used as a base type when a client API's boolean type is an enum. Client APIs
* khronos_float_t signed 32 bit floating point * which use an integer or other type for booleans cannot use this as the base
* khronos_time_ns_t unsigned 64 bit time in nanoseconds * type for their boolean.
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for
* booleans cannot use this as the base type for their boolean.
* *
* Tokens defined in khrplatform.h: * Tokens defined in khrplatform.h:
* *
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
* *
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
* *
* Calling convention macros defined in this file: * Calling convention macros defined in this file: KHRONOS_APICALL
* KHRONOS_APICALL * KHRONOS_APIENTRY KHRONOS_APIATTRIBUTES
* KHRONOS_APIENTRY
* KHRONOS_APIATTRIBUTES
* *
* These may be used in function prototypes as: * These may be used in function prototypes as:
* *
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname( * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( int arg1, int arg2)
* int arg1, * KHRONOS_APIATTRIBUTES;
* int arg2) KHRONOS_APIATTRIBUTES;
*/ */
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) #if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
# define KHRONOS_STATIC 1 #define KHRONOS_STATIC 1
#endif #endif
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
@ -100,17 +90,19 @@
* This precedes the return type of the function in the function prototype. * This precedes the return type of the function in the function prototype.
*/ */
#if defined(KHRONOS_STATIC) #if defined(KHRONOS_STATIC)
/* If the preprocessor constant KHRONOS_STATIC is defined, make the /*
* header compatible with static linking. */ * If the preprocessor constant KHRONOS_STATIC is defined, make the header
# define KHRONOS_APICALL * compatible with static linking.
*/
#define KHRONOS_APICALL
#elif defined(_WIN32) #elif defined(_WIN32)
# define KHRONOS_APICALL __declspec(dllimport) #define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__) #elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C #define KHRONOS_APICALL IMPORT_C
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
# define KHRONOS_APICALL __attribute__((visibility("default"))) #define KHRONOS_APICALL __attribute__((visibility("default")))
#else #else
# define KHRONOS_APICALL #define KHRONOS_APICALL
#endif #endif
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
@ -120,10 +112,10 @@
* name in the function prototype. * name in the function prototype.
*/ */
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */ /* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall #define KHRONOS_APIENTRY __stdcall
#else #else
# define KHRONOS_APIENTRY #define KHRONOS_APIENTRY
#endif #endif
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
@ -147,20 +139,20 @@
* Using <stdint.h> * Using <stdint.h>
*/ */
#include <stdint.h> #include <stdint.h>
typedef int32_t khronos_int32_t; typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t; typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t; typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t; typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1 #define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1 #define KHRONOS_SUPPORT_FLOAT 1
/* /*
* To support platform where unsigned long cannot be used interchangeably with * To support platform where unsigned long cannot be used interchangeably with
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t. * inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
* Ideally, we could just use (u)intptr_t everywhere, but this could result in * Ideally, we could just use (u)intptr_t everywhere, but this could result in
* ABI breakage if khronos_uintptr_t is changed from unsigned long to * ABI breakage if khronos_uintptr_t is changed from unsigned long to unsigned
* unsigned long long or similar (this results in different C++ name mangling). * long long or similar (this results in different C++ name mangling). To avoid
* To avoid changes for existing platforms, we restrict usage of intptr_t to * changes for existing platforms, we restrict usage of intptr_t to platforms
* platforms where the size of a pointer is larger than the size of long. * where the size of a pointer is larger than the size of long.
*/ */
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) #if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__ #if __SIZEOF_POINTER__ > __SIZEOF_LONG__
@ -174,10 +166,10 @@ typedef uint64_t khronos_uint64_t;
* Using <inttypes.h> * Using <inttypes.h>
*/ */
#include <inttypes.h> #include <inttypes.h>
typedef int32_t khronos_int32_t; typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t; typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t; typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t; typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1 #define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1 #define KHRONOS_SUPPORT_FLOAT 1
@ -186,10 +178,10 @@ typedef uint64_t khronos_uint64_t;
/* /*
* Win32 * Win32
*/ */
typedef __int32 khronos_int32_t; typedef __int32 khronos_int32_t;
typedef unsigned __int32 khronos_uint32_t; typedef unsigned __int32 khronos_uint32_t;
typedef __int64 khronos_int64_t; typedef __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t; typedef unsigned __int64 khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1 #define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1 #define KHRONOS_SUPPORT_FLOAT 1
@ -198,15 +190,15 @@ typedef unsigned __int64 khronos_uint64_t;
/* /*
* Sun or Digital * Sun or Digital
*/ */
typedef int khronos_int32_t; typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t; typedef unsigned int khronos_uint32_t;
#if defined(__arch64__) || defined(_LP64) #if defined(__arch64__) || defined(_LP64)
typedef long int khronos_int64_t; typedef long int khronos_int64_t;
typedef unsigned long int khronos_uint64_t; typedef unsigned long int khronos_uint64_t;
#else #else
typedef long long int khronos_int64_t; typedef long long int khronos_int64_t;
typedef unsigned long long int khronos_uint64_t; typedef unsigned long long int khronos_uint64_t;
#endif /* __arch64__ */ #endif /* __arch64__ */
#define KHRONOS_SUPPORT_INT64 1 #define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1 #define KHRONOS_SUPPORT_FLOAT 1
@ -215,8 +207,8 @@ typedef unsigned long long int khronos_uint64_t;
/* /*
* Hypothetical platform with no float or int64 support * Hypothetical platform with no float or int64 support
*/ */
typedef int khronos_int32_t; typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t; typedef unsigned int khronos_uint32_t;
#define KHRONOS_SUPPORT_INT64 0 #define KHRONOS_SUPPORT_INT64 0
#define KHRONOS_SUPPORT_FLOAT 0 #define KHRONOS_SUPPORT_FLOAT 0
@ -226,10 +218,10 @@ typedef unsigned int khronos_uint32_t;
* Generic fallback * Generic fallback
*/ */
#include <stdint.h> #include <stdint.h>
typedef int32_t khronos_int32_t; typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t; typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t; typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t; typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1 #define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1 #define KHRONOS_SUPPORT_FLOAT 1
@ -239,54 +231,55 @@ typedef uint64_t khronos_uint64_t;
/* /*
* Types that are (so far) the same on all platforms * Types that are (so far) the same on all platforms
*/ */
typedef signed char khronos_int8_t; typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t; typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t; typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t; typedef unsigned short int khronos_uint16_t;
/* /*
* Types that differ between LLP64 and LP64 architectures - in LLP64, * Types that differ between LLP64 and LP64 architectures - in LLP64, pointers
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears * are 64 bits, but 'long' is still 32 bits. Win64 appears to be the only LLP64
* to be the only LLP64 architecture in current use. * architecture in current use.
*/ */
#ifdef KHRONOS_USE_INTPTR_T #ifdef KHRONOS_USE_INTPTR_T
typedef intptr_t khronos_intptr_t; typedef intptr_t khronos_intptr_t;
typedef uintptr_t khronos_uintptr_t; typedef uintptr_t khronos_uintptr_t;
#elif defined(_WIN64) #elif defined(_WIN64)
typedef signed long long int khronos_intptr_t; typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t; typedef unsigned long long int khronos_uintptr_t;
#else #else
typedef signed long int khronos_intptr_t; typedef signed long int khronos_intptr_t;
typedef unsigned long int khronos_uintptr_t; typedef unsigned long int khronos_uintptr_t;
#endif #endif
#if defined(_WIN64) #if defined(_WIN64)
typedef signed long long int khronos_ssize_t; typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t; typedef unsigned long long int khronos_usize_t;
#else #else
typedef signed long int khronos_ssize_t; typedef signed long int khronos_ssize_t;
typedef unsigned long int khronos_usize_t; typedef unsigned long int khronos_usize_t;
#endif #endif
#if KHRONOS_SUPPORT_FLOAT #if KHRONOS_SUPPORT_FLOAT
/* /*
* Float type * Float type
*/ */
typedef float khronos_float_t; typedef float khronos_float_t;
#endif #endif
#if KHRONOS_SUPPORT_INT64 #if KHRONOS_SUPPORT_INT64
/* Time types /*
* Time types
* *
* These types can be used to represent a time interval in nanoseconds or * These types can be used to represent a time interval in nanoseconds or an
* an absolute Unadjusted System Time. Unadjusted System Time is the number * absolute Unadjusted System Time. Unadjusted System Time is the number of
* of nanoseconds since some arbitrary system event (e.g. since the last * nanoseconds since some arbitrary system event (e.g. since the last time the
* time the system booted). The Unadjusted System Time is an unsigned * system booted). The Unadjusted System Time is an unsigned 64 bit value that
* 64 bit value that wraps back to 0 every 584 years. Time intervals * wraps back to 0 every 584 years. Time intervals may be either signed or
* may be either signed or unsigned. * unsigned.
*/ */
typedef khronos_uint64_t khronos_utime_nanoseconds_t; typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t; typedef khronos_int64_t khronos_stime_nanoseconds_t;
#endif #endif
/* /*
@ -303,9 +296,9 @@ typedef khronos_int64_t khronos_stime_nanoseconds_t;
* comparisons should not be made against KHRONOS_TRUE. * comparisons should not be made against KHRONOS_TRUE.
*/ */
typedef enum { typedef enum {
KHRONOS_FALSE = 0, KHRONOS_FALSE = 0,
KHRONOS_TRUE = 1, KHRONOS_TRUE = 1,
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
} khronos_boolean_enum_t; } khronos_boolean_enum_t;
#endif /* __khrplatform_h_ */ #endif /* __khrplatform_h_ */

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "gl.h" #include "gl.h"
#define RGFW_IMPLEMENTATION #define RGFW_IMPLEMENTATION
@ -6,21 +6,20 @@
#include "../rgfw.h" #include "../rgfw.h"
/* /*
* This function is the entrypoint for the whole * This function is the entrypoint for the whole game. Its role is to
* game. Its role is to initialize OpenGL, create * initialize OpenGL, create the renderer and start the game loop.
* the renderer and start the game loop.
*/ */
int platform_run(i32 argc, u8 **argv) int platform_run(i32 argc, u8 * *argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
RGFW_glHints* hints = RGFW_getGlobalHints_OpenGL(); RGFW_glHints *hints = RGFW_getGlobalHints_OpenGL();
hints->major = 3; hints->major = 3;
hints->minor = 3; hints->minor = 3;
RGFW_setGlobalHints_OpenGL(hints); RGFW_setGlobalHints_OpenGL(hints);
RGFW_window* win = RGFW_createWindow("Topaz", 0, 0, 800, 600, RGFW_windowCenter | RGFW_windowNoResize | RGFW_windowHide); RGFW_window *win = RGFW_createWindow("Topaz", 0, 0, 800, 600, RGFW_windowCenter | RGFW_windowNoResize | RGFW_windowHide);
RGFW_window_createContext_OpenGL(win, hints); RGFW_window_createContext_OpenGL(win, hints);
int glad_version = gladLoadGL(RGFW_getProcAddress_OpenGL); int glad_version = gladLoadGL(RGFW_getProcAddress_OpenGL);

250
linear.c
View file

@ -1,179 +1,205 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "linear.h" #include "linear.h"
float vec2_dot(vec2 a, vec2 b) float vec2_dot(vec2 a, vec2 b)
{ {
float result = 0.0f; float result = 0.0f;
for (int i=0; i<2; i++) { for (int i = 0; i < 2; i++) {
result += a[i] * b[i]; result += a[i] * b[i];
} }
return result; return result;
} }
float vec3_dot(vec3 a, vec3 b) float
vec3_dot(vec3 a, vec3 b)
{ {
float result = 0.0f; float result = 0.0f;
for (int i=0; i<3; i++) { for (int i = 0; i < 3; i++) {
result += a[i] * b[i]; result += a[i] * b[i];
} }
return result; return result;
} }
float vec4_dot(vec4 a, vec4 b) float
vec4_dot(vec4 a, vec4 b)
{ {
float result = 0.0f; float result = 0.0f;
for (int i=0; i<4; i++) { for (int i = 0; i < 4; i++) {
result += a[i] * b[i]; result += a[i] * b[i];
} }
return result; return result;
} }
void vec3_cross(vec3 dest, vec3 a, vec3 b) void
vec3_cross(vec3 dest, vec3 a, vec3 b)
{ {
vec3 res = {0}; vec3 res = {0};
res[0] = a[1] * b[2] - a[2] * b[1]; res[0] = a[1] * b[2] - a[2] * b[1];
res[1] = a[2] * b[0] - a[0] * b[2]; res[1] = a[2] * b[0] - a[0] * b[2];
res[2] = a[0] * b[1] - a[1] * b[0]; res[2] = a[0] * b[1] - a[1] * b[0];
memcpy(dest, res, sizeof(vec3)); memcpy(dest, res, sizeof(vec3));
} }
void mat4_perspective(mat4 dest, float fov, float aspect, float near, float far) void
mat4_perspective(mat4 dest, float fov, float aspect, float near, float far)
{ {
mat4 perspective = { mat4 perspective = {
{ 1.0f/(aspect*tan(fov/2.0f)), 0.0f, 0.0f, 0.0f }, {1.0f / (aspect * tan(fov / 2.0f)), 0.0f, 0.0f, 0.0f},
{ 0.0f, 1.0f/tan(fov/2.0f), 0.0f, 0.0f }, {0.0f, 1.0f / tan(fov / 2.0f), 0.0f, 0.0f},
{ 0.0f, 0.0f, -((far+near)/(far-near)), -((2*far*near)/(far-near)) }, {0.0f, 0.0f, -((far + near) / (far - near)), -((2 * far * near) / (far - near))},
{ 0.0f, 0.0f, -1.0f, 0.0f } {0.0f, 0.0f, -1.0f, 0.0f}
}; };
memcpy(dest, perspective, sizeof(mat4)); memcpy(dest, perspective, sizeof(mat4));
} }
void mat4_lookat(mat4 dest, vec3 eye, vec3 target, vec3 up) void
mat4_lookat(mat4 dest, vec3 eye, vec3 target, vec3 up)
{ {
vec3 target_cpy = {0}; vec3 target_cpy = {0};
memcpy(target_cpy, target, sizeof(vec3)); memcpy(target_cpy, target, sizeof(vec3));
vec3_sub(target_cpy, target_cpy, eye); vec3_sub(target_cpy, target_cpy, eye);
vec3 zaxis = {0}; vec3 zaxis = {0};
vec3_normalize(zaxis, target_cpy); vec3_normalize(zaxis, target_cpy);
vec3 zaxis_cpy = {0}; vec3 zaxis_cpy = {0};
memcpy(zaxis_cpy, zaxis, sizeof(vec3)); memcpy(zaxis_cpy, zaxis, sizeof(vec3));
vec3_cross(zaxis_cpy, zaxis, up); vec3_cross(zaxis_cpy, zaxis, up);
vec3 xaxis = {0}; vec3 xaxis = {0};
vec3_normalize(xaxis, zaxis_cpy); vec3_normalize(xaxis, zaxis_cpy);
vec3 yaxis = {0}; vec3 yaxis = {0};
vec3_cross(yaxis, xaxis, zaxis); vec3_cross(yaxis, xaxis, zaxis);
zaxis[0] = -zaxis[0]; zaxis[0] = -zaxis[0];
zaxis[1] = -zaxis[1]; zaxis[1] = -zaxis[1];
zaxis[2] = -zaxis[2]; zaxis[2] = -zaxis[2];
mat4 view = { mat4 view = {
{ xaxis[0], xaxis[1], xaxis[2], -vec3_dot(xaxis, eye) }, {xaxis[0], xaxis[1], xaxis[2], -vec3_dot(xaxis, eye)},
{ yaxis[0], yaxis[1], yaxis[2], -vec3_dot(yaxis, eye) }, {yaxis[0], yaxis[1], yaxis[2], -vec3_dot(yaxis, eye)},
{ zaxis[0], zaxis[1], zaxis[2], -vec3_dot(zaxis, eye) }, {zaxis[0], zaxis[1], zaxis[2], -vec3_dot(zaxis, eye)},
{ 0.0f, 0.0f, 0.0f, 1.0f } {0.0f, 0.0f, 0.0f, 1.0f}
}; };
memcpy(dest, view, sizeof(mat4)); memcpy(dest, view, sizeof(mat4));
} }
void vec2_sub(vec2 dest, vec2 a, vec2 b) void
vec2_sub(vec2 dest, vec2 a, vec2 b)
{ {
vec2 res = {0}; vec2 res = {0};
for (int i=0; i<2; i++) res[i] = a[i] - b[i]; for (int i = 0; i < 2; i++)
memcpy(dest, res, sizeof(vec2)); res[i] = a[i] - b[i];
memcpy(dest, res, sizeof(vec2));
} }
void vec3_sub(vec3 dest, vec3 a, vec3 b) void
vec3_sub(vec3 dest, vec3 a, vec3 b)
{ {
vec3 res = {0}; vec3 res = {0};
for (int i=0; i<3; i++) res[i] = a[i] - b[i]; for (int i = 0; i < 3; i++)
memcpy(dest, res, sizeof(vec3)); res[i] = a[i] - b[i];
memcpy(dest, res, sizeof(vec3));
} }
void vec4_sub(vec4 dest, vec4 a, vec4 b) void
vec4_sub(vec4 dest, vec4 a, vec4 b)
{ {
vec4 res = {0}; vec4 res = {0};
for (int i=0; i<4; i++) res[i] = a[i] - b[i]; for (int i = 0; i < 4; i++)
memcpy(dest, res, sizeof(vec4)); res[i] = a[i] - b[i];
memcpy(dest, res, sizeof(vec4));
} }
void vec2_add(vec2 dest, vec2 a, vec2 b) void
vec2_add(vec2 dest, vec2 a, vec2 b)
{ {
vec2 res = {0}; vec2 res = {0};
for (int i=0; i<2; i++) res[i] = a[i] + b[i]; for (int i = 0; i < 2; i++)
memcpy(dest, res, sizeof(vec2)); res[i] = a[i] + b[i];
memcpy(dest, res, sizeof(vec2));
} }
void vec3_add(vec3 dest, vec3 a, vec3 b) void
vec3_add(vec3 dest, vec3 a, vec3 b)
{ {
vec3 res = {0}; vec3 res = {0};
for (int i=0; i<3; i++) res[i] = a[i] + b[i]; for (int i = 0; i < 3; i++)
memcpy(dest, res, sizeof(vec3)); res[i] = a[i] + b[i];
memcpy(dest, res, sizeof(vec3));
} }
void vec4_add(vec4 dest, vec4 a, vec4 b) void
vec4_add(vec4 dest, vec4 a, vec4 b)
{ {
vec4 res = {0}; vec4 res = {0};
for (int i=0; i<4; i++) res[i] = a[i] + b[i]; for (int i = 0; i < 4; i++)
memcpy(dest, res, sizeof(vec4)); res[i] = a[i] + b[i];
memcpy(dest, res, sizeof(vec4));
} }
void vec2_normalize(vec2 dest, vec2 a) void
vec2_normalize(vec2 dest, vec2 a)
{ {
vec2 res = {0}; vec2 res = {0};
memcpy(res, a, sizeof(vec2)); memcpy(res, a, sizeof(vec2));
float w = sqrt(a[0] * a[0] + a[1] * a[1]); float w = sqrt(a[0] * a[0] + a[1] * a[1]);
res[0] /= w; res[0] /= w;
res[1] /= w; res[1] /= w;
memcpy(dest, res, sizeof(vec2)); memcpy(dest, res, sizeof(vec2));
} }
void vec3_normalize(vec3 dest, vec3 a) void
vec3_normalize(vec3 dest, vec3 a)
{ {
vec3 res = {0}; vec3 res = {0};
memcpy(res, a, sizeof(vec3)); memcpy(res, a, sizeof(vec3));
float w = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); float w = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
res[0] /= w; res[0] /= w;
res[1] /= w; res[1] /= w;
res[2] /= w; res[2] /= w;
memcpy(dest, res, sizeof(vec3)); memcpy(dest, res, sizeof(vec3));
} }
void vec4_normalize(vec4 dest, vec4 a) void
vec4_normalize(vec4 dest, vec4 a)
{ {
vec4 res = {0}; vec4 res = {0};
memcpy(res, a, sizeof(vec4)); memcpy(res, a, sizeof(vec4));
float w = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); float w = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
res[0] /= w; res[0] /= w;
res[1] /= w; res[1] /= w;
res[2] /= w; res[2] /= w;
res[3] /= w; res[3] /= w;
memcpy(dest, res, sizeof(vec4)); memcpy(dest, res, sizeof(vec4));
} }
void vec2_scale(vec2 dest, vec2 a, float scale) void
vec2_scale(vec2 dest, vec2 a, float scale)
{ {
memcpy(dest, a, sizeof(vec2)); memcpy(dest, a, sizeof(vec2));
for (int i=0; i<2; i++) dest[i] *= scale; for (int i = 0; i < 2; i++)
dest[i] *= scale;
} }
void vec3_scale(vec3 dest, vec3 a, float scale) void
vec3_scale(vec3 dest, vec3 a, float scale)
{ {
memcpy(dest, a, sizeof(vec3)); memcpy(dest, a, sizeof(vec3));
for (int i=0; i<3; i++) dest[i] *= scale; for (int i = 0; i < 3; i++)
dest[i] *= scale;
} }
void vec4_scale(vec4 dest, vec4 a, float scale) void
vec4_scale(vec4 dest, vec4 a, float scale)
{ {
memcpy(dest, a, sizeof(vec4)); memcpy(dest, a, sizeof(vec4));
for (int i=0; i<4; i++) dest[i] *= scale; for (int i = 0; i < 4; i++)
dest[i] *= scale;
} }

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef LINEAR_H #ifndef LINEAR_H
#define LINEAR_H #define LINEAR_H

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef PLATFORM_H #ifndef PLATFORM_H
#define PLATFORM_H #define PLATFORM_H

View file

@ -1,13 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef RENDERER_H #ifndef RENDERER_H
#define RENDERER_H #define RENDERER_H
#include "../types.h" #include "../types.h"
/* /*
* A mesh is a drawable object represented * A mesh is a drawable object represented as an index (offset) in the global
* as an index (offset) in the global vertex * vertex and index buffers and a size.
* and index buffers and a size.
*/ */
struct mesh { struct mesh {
usize vertex_offset; usize vertex_offset;
@ -15,10 +14,9 @@ struct mesh {
usize size; usize size;
}; };
/* The renderer context stores objects /*
* related to rendering. Implementation * The renderer context stores objects related to rendering. Implementation
* depends on the graphics backend used * depends on the graphics backend used so for reference see gl/gl.h or vk/vk.h
* so for reference see gl/gl.h or vk/vk.h
*/ */
struct renderer_context; struct renderer_context;

23908
rgfw.h

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include <stdio.h> #include <stdio.h>
#include "platform.h" #include "platform.h"

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef TYPES_H #ifndef TYPES_H
#define TYPES_H #define TYPES_H

View file

@ -1,7 +0,0 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifndef UTILS_H
#define UTILS_H
#endif

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "device.h" #include "device.h"
#include "physical_device.h" #include "physical_device.h"
#include "../core/vector.h" #include "../core/vector.h"
@ -13,10 +13,10 @@ void vk_device_init(struct renderer_context *context)
for (usize i = 0; i < physical_device_extensions->length; i++) { for (usize i = 0; i < physical_device_extensions->length; i++) {
if (strcmp(((char **)physical_device_extensions->data)[i], "VK_KHR_portability_subset") == 0) { if (strcmp(((char **)physical_device_extensions->data)[i], "VK_KHR_portability_subset") == 0) {
/* /*
* The spec states that if VK_KHR_portability_subset * The spec states that if VK_KHR_portability_subset is
* is present in the physical device extensions, * present in the physical device extensions, the
* the device should also have that extension enabled. * device should also have that extension enabled.
*/ */
vector_push(device_extensions, char *, "VK_KHR_portability_subset"); vector_push(device_extensions, char *, "VK_KHR_portability_subset");
} }

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef DEVICE_H #ifndef DEVICE_H
#define DEVICE_H #define DEVICE_H

View file

@ -1,4 +1,4 @@
// SPDX - License - Identifier:BSD - 3 - Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "instance.h" #include "instance.h"
#include "../core/log.h" #include "../core/log.h"
#define RGFW_VULKAN #define RGFW_VULKAN

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef INSTANCE_H #ifndef INSTANCE_H
#define INSTANCE_H #define INSTANCE_H

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "physical_device.h" #include "physical_device.h"
#include "../core/log.h" #include "../core/log.h"
#include <stdio.h> #include <stdio.h>
@ -34,7 +34,7 @@ struct vector *vk_physical_device_get_extensions(struct renderer_context *contex
VkExtensionProperties *properties = NULL; VkExtensionProperties *properties = NULL;
vkEnumerateDeviceExtensionProperties(context->physical_device, NULL, &property_count, NULL); vkEnumerateDeviceExtensionProperties(context->physical_device, NULL, &property_count, NULL);
struct vector *extensions = vector_init(property_count, sizeof(char *)); struct vector *extensions = vector_init(property_count, sizeof(char *));
properties = (VkExtensionProperties *) malloc(sizeof(VkExtensionProperties) * property_count); properties = (VkExtensionProperties *) malloc(sizeof(VkExtensionProperties) * property_count);
@ -50,7 +50,7 @@ struct vector *vk_physical_device_get_extensions(struct renderer_context *contex
} }
free(properties); free(properties);
return extensions; return extensions;
} }

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef PHYSICAL_DEVICE_H #ifndef PHYSICAL_DEVICE_H
#define PHYSICAL_DEVICE_H #define PHYSICAL_DEVICE_H
@ -8,21 +8,18 @@
/* /*
* Get the list of all available devices and * Get the list of all available devices and pick the best option.
* pick the best option.
*/ */
void vk_physical_device_pick(struct renderer_context *context); void vk_physical_device_pick(struct renderer_context *context);
/* /*
* Get the list of all available device * Get the list of all available device extensions and return a vector
* extensions and return a vector containing * containing those.
* those.
*/ */
struct vector *vk_physical_device_get_extensions(struct renderer_context *context); struct vector *vk_physical_device_get_extensions(struct renderer_context *context);
/* /*
* The physical device is responsible of selecting * The physical device is responsible of selecting the queue family indices,
* the queue family indices, used later by the * used later by the device to create the queues. This function sets the family
* device to create the queues. This function * indices in the renderer context.
* sets the family indices in the renderer context.
*/ */
void vk_physical_device_select_family_indices(struct renderer_context *context); void vk_physical_device_select_family_indices(struct renderer_context *context);

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#define RGFW_VULKAN #define RGFW_VULKAN
#define RGFW_IMPLEMENTATION #define RGFW_IMPLEMENTATION
@ -14,18 +14,17 @@
#include "../rendering/renderer.h" #include "../rendering/renderer.h"
/* /*
* This function is the entrypoint for the whole * This function is the entrypoint for the whole game. Its role is to
* game. Its role is to initialize Vulkan, create * initialize Vulkan, create the renderer and start the game loop.
* the renderer and start the game loop.
*/ */
int platform_run(i32 argc, u8 **argv) int platform_run(i32 argc, u8 * *argv)
{ {
(void) argc; (void)argc;
(void) argv; (void)argv;
log_info("Using Vulkan as rendering backend.\n"); log_info("Using Vulkan as rendering backend.\n");
RGFW_window* win = RGFW_createWindow("topaz", 0, 0, 800, 600, RGFW_windowCenter | RGFW_windowNoResize | RGFW_windowHide); RGFW_window *win = RGFW_createWindow("topaz", 0, 0, 800, 600, RGFW_windowCenter | RGFW_windowNoResize | RGFW_windowHide);
RGFW_window_show(win); RGFW_window_show(win);
RGFW_window_setExitKey(win, RGFW_escape); RGFW_window_setExitKey(win, RGFW_escape);

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#include "../rendering/renderer.h" #include "../rendering/renderer.h"
#include "instance.h" #include "instance.h"
#include "physical_device.h" #include "physical_device.h"
@ -10,7 +10,7 @@
struct renderer_context *renderer_context_init(void) struct renderer_context *renderer_context_init(void)
{ {
struct renderer_context *context = (struct renderer_context *) arena_alloc(global_arena, (sizeof(struct renderer_context))); struct renderer_context *context = (struct renderer_context *)arena_alloc(global_arena, (sizeof(struct renderer_context)));
vk_instance_init(context); vk_instance_init(context);
vk_physical_device_pick(context); vk_physical_device_pick(context);
@ -32,10 +32,10 @@ struct mesh *renderer_build_chunk_mesh(void)
void renderer_draw_mesh(struct mesh mesh) void renderer_draw_mesh(struct mesh mesh)
{ {
(void) mesh; (void)mesh;
} }
void renderer_draw_chunk(struct mesh mesh) void renderer_draw_chunk(struct mesh mesh)
{ {
(void) mesh; (void)mesh;
} }

View file

@ -1,4 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier:BSD-3-Clause */
#ifndef VK_H #ifndef VK_H
#define VK_H #define VK_H

View file

@ -1,14 +0,0 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifdef BLOCK_H
#define BLOCK_H
#include "../types.h"
typedef u16 block_id;
#define BLOCK_AIR_ID 0
#define BLOCK_STONE_ID 1
#define BLOCK_DIRT_ID 1
#define BLOCK_GRASS_ID 1
#endif

View file

@ -1,22 +0,0 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifndef CHUNK_H
#define CHUNK_H
#include "block.h"
#define CHUNK_SIZE 16
#define CHUNK_INDEX(x, y, z) (CHUNK_SIZE * CHUNK_SIZE * (x) + CHUNK_SIZE * (y) + (z))
typedef usize chunk_position[2];
/*
* Chunk are a group of blocks with
* size 16x16x16. The world is composed
* of infinite chunks in each axis.
*/
struct chunk {
block_id blocks[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
chunk_position position;
};
#endif