formatted license comment
This commit is contained in:
parent
db5a728846
commit
0ffdb8c3ac
30 changed files with 16218 additions and 14914 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -2,3 +2,6 @@
|
||||||
.clang-format
|
.clang-format
|
||||||
compile-commands.json
|
compile-commands.json
|
||||||
topaz
|
topaz
|
||||||
|
**/*.BAK
|
||||||
|
**/*.bak
|
||||||
|
**/*~
|
||||||
|
|
|
||||||
1
.indent.pro
vendored
1
.indent.pro
vendored
|
|
@ -12,3 +12,4 @@
|
||||||
-npsl
|
-npsl
|
||||||
-di1
|
-di1
|
||||||
-ldi1
|
-ldi1
|
||||||
|
-nfc1
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
/* SPDX-License-Identifier:BSD-3-Clause */
|
||||||
#include "arena.h"
|
#include "arena.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
|
||||||
21
core/arena.h
21
core/arena.h
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
// 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)
|
||||||
|
size = 1;
|
||||||
struct vector *vector = (struct vector *)malloc(sizeof(struct vector));
|
struct vector *vector = (struct vector *)malloc(sizeof(struct vector));
|
||||||
vector->length = 0;
|
vector->length = 0;
|
||||||
vector->size = size;
|
vector->size = size;
|
||||||
|
|
@ -15,7 +16,8 @@ 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)
|
||||||
|
log_error("Popping from an empty vector.\n");
|
||||||
#endif
|
#endif
|
||||||
vector->length -= 1;
|
vector->length -= 1;
|
||||||
if (vector->length <= vector->size / 3) {
|
if (vector->length <= vector->size / 3) {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
// 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;
|
||||||
|
|
@ -16,26 +16,24 @@ struct vector {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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])
|
||||||
|
|
||||||
|
|
|
||||||
50
gl/gl.c
50
gl/gl.c
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0
|
/* SPDX-License-Identifier:BSD-3-Clause */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -764,7 +764,8 @@ PFNGLWINDOWPOS3SVPROC glad_glWindowPos3sv = NULL;
|
||||||
|
|
||||||
|
|
||||||
static void glad_gl_load_GL_VERSION_1_0(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_1_0(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_1_0) return;
|
if (!GLAD_GL_VERSION_1_0)
|
||||||
|
return;
|
||||||
glad_glAccum = (PFNGLACCUMPROC) load(userptr, "glAccum");
|
glad_glAccum = (PFNGLACCUMPROC) load(userptr, "glAccum");
|
||||||
glad_glAlphaFunc = (PFNGLALPHAFUNCPROC) load(userptr, "glAlphaFunc");
|
glad_glAlphaFunc = (PFNGLALPHAFUNCPROC) load(userptr, "glAlphaFunc");
|
||||||
glad_glBegin = (PFNGLBEGINPROC) load(userptr, "glBegin");
|
glad_glBegin = (PFNGLBEGINPROC) load(userptr, "glBegin");
|
||||||
|
|
@ -1073,7 +1074,8 @@ static void glad_gl_load_GL_VERSION_1_0( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glViewport = (PFNGLVIEWPORTPROC) load(userptr, "glViewport");
|
glad_glViewport = (PFNGLVIEWPORTPROC) load(userptr, "glViewport");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_1_1(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_1_1(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_1_1) return;
|
if (!GLAD_GL_VERSION_1_1)
|
||||||
|
return;
|
||||||
glad_glAreTexturesResident = (PFNGLARETEXTURESRESIDENTPROC) load(userptr, "glAreTexturesResident");
|
glad_glAreTexturesResident = (PFNGLARETEXTURESRESIDENTPROC) load(userptr, "glAreTexturesResident");
|
||||||
glad_glArrayElement = (PFNGLARRAYELEMENTPROC) load(userptr, "glArrayElement");
|
glad_glArrayElement = (PFNGLARRAYELEMENTPROC) load(userptr, "glArrayElement");
|
||||||
glad_glBindTexture = (PFNGLBINDTEXTUREPROC) load(userptr, "glBindTexture");
|
glad_glBindTexture = (PFNGLBINDTEXTUREPROC) load(userptr, "glBindTexture");
|
||||||
|
|
@ -1106,14 +1108,16 @@ static void glad_gl_load_GL_VERSION_1_1( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glVertexPointer = (PFNGLVERTEXPOINTERPROC) load(userptr, "glVertexPointer");
|
glad_glVertexPointer = (PFNGLVERTEXPOINTERPROC) load(userptr, "glVertexPointer");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_1_2(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_1_2(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_1_2) return;
|
if (!GLAD_GL_VERSION_1_2)
|
||||||
|
return;
|
||||||
glad_glCopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC) load(userptr, "glCopyTexSubImage3D");
|
glad_glCopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC) load(userptr, "glCopyTexSubImage3D");
|
||||||
glad_glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) load(userptr, "glDrawRangeElements");
|
glad_glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) load(userptr, "glDrawRangeElements");
|
||||||
glad_glTexImage3D = (PFNGLTEXIMAGE3DPROC) load(userptr, "glTexImage3D");
|
glad_glTexImage3D = (PFNGLTEXIMAGE3DPROC) load(userptr, "glTexImage3D");
|
||||||
glad_glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC) load(userptr, "glTexSubImage3D");
|
glad_glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC) load(userptr, "glTexSubImage3D");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_1_3(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_1_3(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_1_3) return;
|
if (!GLAD_GL_VERSION_1_3)
|
||||||
|
return;
|
||||||
glad_glActiveTexture = (PFNGLACTIVETEXTUREPROC) load(userptr, "glActiveTexture");
|
glad_glActiveTexture = (PFNGLACTIVETEXTUREPROC) load(userptr, "glActiveTexture");
|
||||||
glad_glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC) load(userptr, "glClientActiveTexture");
|
glad_glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC) load(userptr, "glClientActiveTexture");
|
||||||
glad_glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC) load(userptr, "glCompressedTexImage1D");
|
glad_glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC) load(userptr, "glCompressedTexImage1D");
|
||||||
|
|
@ -1162,7 +1166,8 @@ static void glad_gl_load_GL_VERSION_1_3( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glSampleCoverage = (PFNGLSAMPLECOVERAGEPROC) load(userptr, "glSampleCoverage");
|
glad_glSampleCoverage = (PFNGLSAMPLECOVERAGEPROC) load(userptr, "glSampleCoverage");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_1_4(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_1_4(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_1_4) return;
|
if (!GLAD_GL_VERSION_1_4)
|
||||||
|
return;
|
||||||
glad_glBlendColor = (PFNGLBLENDCOLORPROC) load(userptr, "glBlendColor");
|
glad_glBlendColor = (PFNGLBLENDCOLORPROC) load(userptr, "glBlendColor");
|
||||||
glad_glBlendEquation = (PFNGLBLENDEQUATIONPROC) load(userptr, "glBlendEquation");
|
glad_glBlendEquation = (PFNGLBLENDEQUATIONPROC) load(userptr, "glBlendEquation");
|
||||||
glad_glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC) load(userptr, "glBlendFuncSeparate");
|
glad_glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC) load(userptr, "glBlendFuncSeparate");
|
||||||
|
|
@ -1212,7 +1217,8 @@ static void glad_gl_load_GL_VERSION_1_4( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glWindowPos3sv = (PFNGLWINDOWPOS3SVPROC) load(userptr, "glWindowPos3sv");
|
glad_glWindowPos3sv = (PFNGLWINDOWPOS3SVPROC) load(userptr, "glWindowPos3sv");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_1_5(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_1_5(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_1_5) return;
|
if (!GLAD_GL_VERSION_1_5)
|
||||||
|
return;
|
||||||
glad_glBeginQuery = (PFNGLBEGINQUERYPROC) load(userptr, "glBeginQuery");
|
glad_glBeginQuery = (PFNGLBEGINQUERYPROC) load(userptr, "glBeginQuery");
|
||||||
glad_glBindBuffer = (PFNGLBINDBUFFERPROC) load(userptr, "glBindBuffer");
|
glad_glBindBuffer = (PFNGLBINDBUFFERPROC) load(userptr, "glBindBuffer");
|
||||||
glad_glBufferData = (PFNGLBUFFERDATAPROC) load(userptr, "glBufferData");
|
glad_glBufferData = (PFNGLBUFFERDATAPROC) load(userptr, "glBufferData");
|
||||||
|
|
@ -1234,7 +1240,8 @@ static void glad_gl_load_GL_VERSION_1_5( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) load(userptr, "glUnmapBuffer");
|
glad_glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) load(userptr, "glUnmapBuffer");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_2_0(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_2_0(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_2_0) return;
|
if (!GLAD_GL_VERSION_2_0)
|
||||||
|
return;
|
||||||
glad_glAttachShader = (PFNGLATTACHSHADERPROC) load(userptr, "glAttachShader");
|
glad_glAttachShader = (PFNGLATTACHSHADERPROC) load(userptr, "glAttachShader");
|
||||||
glad_glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC) load(userptr, "glBindAttribLocation");
|
glad_glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC) load(userptr, "glBindAttribLocation");
|
||||||
glad_glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC) load(userptr, "glBlendEquationSeparate");
|
glad_glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC) load(userptr, "glBlendEquationSeparate");
|
||||||
|
|
@ -1330,7 +1337,8 @@ static void glad_gl_load_GL_VERSION_2_0( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) load(userptr, "glVertexAttribPointer");
|
glad_glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) load(userptr, "glVertexAttribPointer");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_2_1(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_2_1(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_2_1) return;
|
if (!GLAD_GL_VERSION_2_1)
|
||||||
|
return;
|
||||||
glad_glUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC) load(userptr, "glUniformMatrix2x3fv");
|
glad_glUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC) load(userptr, "glUniformMatrix2x3fv");
|
||||||
glad_glUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC) load(userptr, "glUniformMatrix2x4fv");
|
glad_glUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC) load(userptr, "glUniformMatrix2x4fv");
|
||||||
glad_glUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC) load(userptr, "glUniformMatrix3x2fv");
|
glad_glUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC) load(userptr, "glUniformMatrix3x2fv");
|
||||||
|
|
@ -1339,7 +1347,8 @@ static void glad_gl_load_GL_VERSION_2_1( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC) load(userptr, "glUniformMatrix4x3fv");
|
glad_glUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC) load(userptr, "glUniformMatrix4x3fv");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_3_0(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_3_0(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_3_0) return;
|
if (!GLAD_GL_VERSION_3_0)
|
||||||
|
return;
|
||||||
glad_glBeginConditionalRender = (PFNGLBEGINCONDITIONALRENDERPROC) load(userptr, "glBeginConditionalRender");
|
glad_glBeginConditionalRender = (PFNGLBEGINCONDITIONALRENDERPROC) load(userptr, "glBeginConditionalRender");
|
||||||
glad_glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC) load(userptr, "glBeginTransformFeedback");
|
glad_glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC) load(userptr, "glBeginTransformFeedback");
|
||||||
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC) load(userptr, "glBindBufferBase");
|
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC) load(userptr, "glBindBufferBase");
|
||||||
|
|
@ -1426,7 +1435,8 @@ static void glad_gl_load_GL_VERSION_3_0( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC) load(userptr, "glVertexAttribIPointer");
|
glad_glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC) load(userptr, "glVertexAttribIPointer");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_3_1(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_3_1(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_3_1) return;
|
if (!GLAD_GL_VERSION_3_1)
|
||||||
|
return;
|
||||||
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC) load(userptr, "glBindBufferBase");
|
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC) load(userptr, "glBindBufferBase");
|
||||||
glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) load(userptr, "glBindBufferRange");
|
glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) load(userptr, "glBindBufferRange");
|
||||||
glad_glCopyBufferSubData = (PFNGLCOPYBUFFERSUBDATAPROC) load(userptr, "glCopyBufferSubData");
|
glad_glCopyBufferSubData = (PFNGLCOPYBUFFERSUBDATAPROC) load(userptr, "glCopyBufferSubData");
|
||||||
|
|
@ -1444,7 +1454,8 @@ static void glad_gl_load_GL_VERSION_3_1( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC) load(userptr, "glUniformBlockBinding");
|
glad_glUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC) load(userptr, "glUniformBlockBinding");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_3_2(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_3_2(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_3_2) return;
|
if (!GLAD_GL_VERSION_3_2)
|
||||||
|
return;
|
||||||
glad_glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC) load(userptr, "glClientWaitSync");
|
glad_glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC) load(userptr, "glClientWaitSync");
|
||||||
glad_glDeleteSync = (PFNGLDELETESYNCPROC) load(userptr, "glDeleteSync");
|
glad_glDeleteSync = (PFNGLDELETESYNCPROC) load(userptr, "glDeleteSync");
|
||||||
glad_glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC) load(userptr, "glDrawElementsBaseVertex");
|
glad_glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC) load(userptr, "glDrawElementsBaseVertex");
|
||||||
|
|
@ -1466,7 +1477,8 @@ static void glad_gl_load_GL_VERSION_3_2( GLADuserptrloadfunc load, void* userptr
|
||||||
glad_glWaitSync = (PFNGLWAITSYNCPROC) load(userptr, "glWaitSync");
|
glad_glWaitSync = (PFNGLWAITSYNCPROC) load(userptr, "glWaitSync");
|
||||||
}
|
}
|
||||||
static void glad_gl_load_GL_VERSION_3_3(GLADuserptrloadfunc load, void *userptr){
|
static void glad_gl_load_GL_VERSION_3_3(GLADuserptrloadfunc load, void *userptr){
|
||||||
if(!GLAD_GL_VERSION_3_3) return;
|
if (!GLAD_GL_VERSION_3_3)
|
||||||
|
return;
|
||||||
glad_glBindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) load(userptr, "glBindFragDataLocationIndexed");
|
glad_glBindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) load(userptr, "glBindFragDataLocationIndexed");
|
||||||
glad_glBindSampler = (PFNGLBINDSAMPLERPROC) load(userptr, "glBindSampler");
|
glad_glBindSampler = (PFNGLBINDSAMPLERPROC) load(userptr, "glBindSampler");
|
||||||
glad_glColorP3ui = (PFNGLCOLORP3UIPROC) load(userptr, "glColorP3ui");
|
glad_glColorP3ui = (PFNGLCOLORP3UIPROC) load(userptr, "glColorP3ui");
|
||||||
|
|
@ -1619,7 +1631,8 @@ static GLADapiproc glad_gl_get_proc_from_userptr(void *userptr, const char* name
|
||||||
static int glad_gl_find_extensions_gl(void){
|
static int glad_gl_find_extensions_gl(void){
|
||||||
const char *exts = NULL;
|
const char *exts = NULL;
|
||||||
char **exts_i = NULL;
|
char **exts_i = NULL;
|
||||||
if (!glad_gl_get_extensions(&exts, &exts_i)) return 0;
|
if (!glad_gl_get_extensions(&exts, &exts_i))
|
||||||
|
return 0;
|
||||||
|
|
||||||
GLAD_UNUSED(&glad_gl_has_extension);
|
GLAD_UNUSED(&glad_gl_has_extension);
|
||||||
|
|
||||||
|
|
@ -1641,7 +1654,8 @@ static int glad_gl_find_core_gl(void) {
|
||||||
int major = 0;
|
int major = 0;
|
||||||
int minor = 0;
|
int minor = 0;
|
||||||
version = (const char *)glad_glGetString(GL_VERSION);
|
version = (const char *)glad_glGetString(GL_VERSION);
|
||||||
if (!version) return 0;
|
if (!version)
|
||||||
|
return 0;
|
||||||
for (i = 0; prefixes[i]; i++) {
|
for (i = 0; prefixes[i]; i++) {
|
||||||
const size_t length = strlen(prefixes[i]);
|
const size_t length = strlen(prefixes[i]);
|
||||||
if (strncmp(version, prefixes[i], length) == 0) {
|
if (strncmp(version, prefixes[i], length) == 0) {
|
||||||
|
|
@ -1672,7 +1686,8 @@ int gladLoadGLUserPtr( GLADuserptrloadfunc load, void *userptr) {
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
glad_glGetString = (PFNGLGETSTRINGPROC) load(userptr, "glGetString");
|
glad_glGetString = (PFNGLGETSTRINGPROC) load(userptr, "glGetString");
|
||||||
if(glad_glGetString == NULL) return 0;
|
if (glad_glGetString == NULL)
|
||||||
|
return 0;
|
||||||
version = glad_gl_find_core_gl();
|
version = glad_gl_find_core_gl();
|
||||||
|
|
||||||
glad_gl_load_GL_VERSION_1_0(load, userptr);
|
glad_gl_load_GL_VERSION_1_0(load, userptr);
|
||||||
|
|
@ -1688,7 +1703,8 @@ int gladLoadGLUserPtr( GLADuserptrloadfunc load, void *userptr) {
|
||||||
glad_gl_load_GL_VERSION_3_2(load, userptr);
|
glad_gl_load_GL_VERSION_3_2(load, userptr);
|
||||||
glad_gl_load_GL_VERSION_3_3(load, userptr);
|
glad_gl_load_GL_VERSION_3_3(load, userptr);
|
||||||
|
|
||||||
if (!glad_gl_find_extensions_gl()) return 0;
|
if (!glad_gl_find_extensions_gl())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
141
gl/khrplatform.h
141
gl/khrplatform.h
|
|
@ -2,74 +2,67 @@
|
||||||
#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
|
* * Permission is hereby granted, free of charge, to any person obtaining a *
|
||||||
** copy of this software and/or associated documentation files (the
|
* copy of this software and/or associated documentation files (the *
|
||||||
** "Materials"), to deal in the Materials without restriction, including
|
* "Materials"), to deal in the Materials without restriction, including *
|
||||||
** without limitation the rights to use, copy, modify, merge, publish,
|
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
* distribute, sublicense, and/or sell copies of the Materials, and to * permit
|
||||||
** permit persons to whom the Materials are furnished to do so, subject to
|
* persons to whom the Materials are furnished to do so, subject to * the
|
||||||
** the following conditions:
|
* following conditions: *
|
||||||
**
|
*
|
||||||
** The above copyright notice and this permission notice shall be included
|
* * The above copyright notice and this permission notice shall be included *
|
||||||
** in all copies or substantial portions of the Materials.
|
* in all copies or substantial portions of the Materials. *
|
||||||
**
|
*
|
||||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
|
||||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN
|
||||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM,
|
||||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR
|
||||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * MATERIALS OR THE
|
||||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
* USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Khronos platform-specific types and definitions.
|
/*
|
||||||
|
* Khronos platform-specific types and definitions.
|
||||||
*
|
*
|
||||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
* The master copy of khrplatform.h is maintained in the Khronos EGL Registry
|
||||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
* repository at https://github.com/KhronosGroup/EGL-Registry The last semantic
|
||||||
* The last semantic modification to khrplatform.h was at commit ID:
|
* modification to khrplatform.h was at commit ID:
|
||||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
* 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_intptr_t signed same number of bits as a pointer
|
|
||||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
|
||||||
* khronos_ssize_t signed size
|
|
||||||
* khronos_usize_t unsigned size
|
|
||||||
* khronos_float_t signed 32 bit floating point
|
|
||||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||||
* nanoseconds
|
* nanoseconds khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
* khronos_boolean_enum_t enumerated boolean type. This should only be
|
||||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
* used as a base type when a client API's boolean type is an enum. Client APIs
|
||||||
* only be used as a base type when a client API's boolean type is
|
* which use an integer or other type for booleans cannot use this as the base
|
||||||
* an enum. Client APIs which use an integer or other type for
|
* type for their boolean.
|
||||||
* booleans cannot use this as the base type for their boolean.
|
|
||||||
*
|
*
|
||||||
* Tokens defined in khrplatform.h:
|
* Tokens defined in khrplatform.h:
|
||||||
*
|
*
|
||||||
|
|
@ -78,16 +71,13 @@
|
||||||
* 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)
|
||||||
|
|
@ -100,8 +90,10 @@
|
||||||
* 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
|
||||||
|
* compatible with static linking.
|
||||||
|
*/
|
||||||
#define KHRONOS_APICALL
|
#define KHRONOS_APICALL
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
#define KHRONOS_APICALL __declspec(dllimport)
|
#define KHRONOS_APICALL __declspec(dllimport)
|
||||||
|
|
@ -157,10 +149,10 @@ typedef uint64_t khronos_uint64_t;
|
||||||
* 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__
|
||||||
|
|
@ -245,9 +237,9 @@ 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;
|
||||||
|
|
@ -276,14 +268,15 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -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,9 +6,8 @@
|
||||||
#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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
80
linear.c
80
linear.c
|
|
@ -1,4 +1,4 @@
|
||||||
// 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)
|
||||||
|
|
@ -11,7 +11,8 @@ float vec2_dot(vec2 a, vec2 b)
|
||||||
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++) {
|
||||||
|
|
@ -21,7 +22,8 @@ float vec3_dot(vec3 a, vec3 b)
|
||||||
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++) {
|
||||||
|
|
@ -31,7 +33,8 @@ float vec4_dot(vec4 a, vec4 b)
|
||||||
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];
|
||||||
|
|
@ -40,7 +43,8 @@ void vec3_cross(vec3 dest, vec3 a, vec3 b)
|
||||||
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},
|
||||||
|
|
@ -52,7 +56,8 @@ void mat4_perspective(mat4 dest, float fov, float aspect, float near, float far)
|
||||||
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));
|
||||||
|
|
@ -85,49 +90,62 @@ void mat4_lookat(mat4 dest, vec3 eye, vec3 target, vec3 up)
|
||||||
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++)
|
||||||
|
res[i] = a[i] - b[i];
|
||||||
memcpy(dest, res, sizeof(vec2));
|
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++)
|
||||||
|
res[i] = a[i] - b[i];
|
||||||
memcpy(dest, res, sizeof(vec3));
|
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++)
|
||||||
|
res[i] = a[i] - b[i];
|
||||||
memcpy(dest, res, sizeof(vec4));
|
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++)
|
||||||
|
res[i] = a[i] + b[i];
|
||||||
memcpy(dest, res, sizeof(vec2));
|
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++)
|
||||||
|
res[i] = a[i] + b[i];
|
||||||
memcpy(dest, res, sizeof(vec3));
|
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++)
|
||||||
|
res[i] = a[i] + b[i];
|
||||||
memcpy(dest, res, sizeof(vec4));
|
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));
|
||||||
|
|
@ -137,7 +155,8 @@ void vec2_normalize(vec2 dest, vec2 a)
|
||||||
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));
|
||||||
|
|
@ -148,7 +167,8 @@ void vec3_normalize(vec3 dest, vec3 a)
|
||||||
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));
|
||||||
|
|
@ -160,20 +180,26 @@ void vec4_normalize(vec4 dest, vec4 a)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
linear.h
2
linear.h
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
||||||
2
topaz.c
2
topaz.c
|
|
@ -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"
|
||||||
|
|
|
||||||
2
types.h
2
types.h
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
7
utils.h
7
utils.h
|
|
@ -1,7 +0,0 @@
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
#ifndef UTILS_H
|
|
||||||
#define UTILS_H
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -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,9 +13,9 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,9 +14,8 @@
|
||||||
#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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
2
vk/vk.h
2
vk/vk.h
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue