diff --git a/CMakeLists.txt b/CMakeLists.txt index 22da63d..5c11328 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,15 @@ cmake_minimum_required(VERSION 3.0) project(GLdc) +set(CMAKE_C_STANDARD 99) + include_directories(include) set( SOURCES + containers/aligned_vector.c + containers/named_array.c + containers/stack.c GL/clip.c GL/draw.c GL/error.c @@ -29,4 +34,9 @@ set(SOURCES ${SOURCES} GL/platforms/x86.c) endif() add_library(GLdc ${SOURCES}) +link_libraries(m) +include_directories(include) + +add_executable(nehe02 samples/nehe02/main.c) +target_link_libraries(nehe02 GLdc) diff --git a/GL/draw.c b/GL/draw.c index 27e2738..f9ac75c 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -5,9 +5,6 @@ #include #include -#include "../include/gl.h" -#include "../include/glext.h" - #include "private.h" #include "profiler.h" #include "platform.h" diff --git a/GL/error.c b/GL/error.c index 49732e5..c964fec 100644 --- a/GL/error.c +++ b/GL/error.c @@ -8,10 +8,10 @@ KOS Open GL State Machine Error Code Implementation. */ -#include "gl.h" - #include +#include "private.h" + static GLenum last_error = GL_NO_ERROR; static char error_function[64] = { '\0' }; diff --git a/GL/flush.c b/GL/flush.c index 6d82cff..be0d5f6 100644 --- a/GL/flush.c +++ b/GL/flush.c @@ -1,6 +1,4 @@ - -#include "../include/glkos.h" #include "../containers/aligned_vector.h" #include "private.h" #include "profiler.h" diff --git a/GL/framebuffer.c b/GL/framebuffer.c index bb6a9a8..0df1893 100644 --- a/GL/framebuffer.c +++ b/GL/framebuffer.c @@ -2,8 +2,6 @@ #include #include "private.h" -#include "../include/glkos.h" -#include "../include/glext.h" typedef struct { GLuint index; diff --git a/GL/immediate.c b/GL/immediate.c index e1f530b..f9e1958 100644 --- a/GL/immediate.c +++ b/GL/immediate.c @@ -10,11 +10,7 @@ #include #include -#include "../include/gl.h" -#include "../include/glext.h" -#include "../include/glkos.h" #include "profiler.h" - #include "private.h" static GLboolean IMMEDIATE_MODE_ACTIVE = GL_FALSE; diff --git a/GL/matrix.c b/GL/matrix.c index a3ffa71..1f40bdf 100644 --- a/GL/matrix.c +++ b/GL/matrix.c @@ -3,7 +3,7 @@ #include #include "private.h" -#include "../include/gl.h" + #include "../containers/stack.h" #define DEG2RAD (0.01745329251994329576923690768489) @@ -49,8 +49,8 @@ void _glInitMatrices() { stack_push(&MATRIX_STACKS[1], IDENTITY); stack_push(&MATRIX_STACKS[2], IDENTITY); - memcpy4(NORMAL_MATRIX, IDENTITY, sizeof(Matrix4x4)); - memcpy4(SCREENVIEW_MATRIX, IDENTITY, sizeof(Matrix4x4)); + FASTCPY4(NORMAL_MATRIX, IDENTITY, sizeof(Matrix4x4)); + FASTCPY4(SCREENVIEW_MATRIX, IDENTITY, sizeof(Matrix4x4)); const VideoMode* vid_mode = GetVideoMode(); @@ -96,7 +96,7 @@ static void transpose(GLfloat* m) { } static void recalculateNormalMatrix() { - memcpy4(NORMAL_MATRIX, stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)), sizeof(Matrix4x4)); + FASTCPY4(NORMAL_MATRIX, stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)), sizeof(Matrix4x4)); inverse((GLfloat*) NORMAL_MATRIX); transpose((GLfloat*) NORMAL_MATRIX); } diff --git a/GL/platform.h b/GL/platform.h index 81c635c..08afb82 100644 --- a/GL/platform.h +++ b/GL/platform.h @@ -67,11 +67,11 @@ typedef enum GPUTextureFormat { GPU_TXRFMT_STRIDE = (1 << 21) } GPUTextureFormat; -inline uint32_t GPUPaletteSelect8BPP(uint32_t x) { +static inline uint32_t GPUPaletteSelect8BPP(uint32_t x) { return x << 25; } -inline uint32_t GPUPaletteSelect4BPP(uint32_t x) { +static inline uint32_t GPUPaletteSelect4BPP(uint32_t x) { return x << 21; } diff --git a/GL/platforms/x86.c b/GL/platforms/x86.c index 0bfb2c4..79bc47c 100644 --- a/GL/platforms/x86.c +++ b/GL/platforms/x86.c @@ -1,6 +1,12 @@ +#include +#include + #include "../platform.h" #include "x86.h" +static size_t AVAILABLE_VRAM = 16 * 1024 * 1024; +static Matrix4x4 MATRIX; + void InitGPU(_Bool autosort, _Bool fsaa) { } @@ -24,3 +30,71 @@ void SceneListFinish() { void SceneFinish() { } + +void UploadMatrix4x4(const Matrix4x4* mat) { + memcpy(&MATRIX, mat, sizeof(Matrix4x4)); +} + +void MultiplyMatrix4x4(const Matrix4x4* mat) { + (void) mat; +} + +void DownloadMatrix4x4(Matrix4x4* mat) { + memcpy(mat, &MATRIX, sizeof(Matrix4x4)); +} + +static VideoMode vid_mode = { + 640, 480 +}; + +const VideoMode* GetVideoMode() { + return &vid_mode; +} + +size_t GPUMemoryAvailable() { + return AVAILABLE_VRAM; +} + +void* GPUMemoryAlloc(size_t size) { + if(size > AVAILABLE_VRAM) { + return NULL; + } else { + return malloc(size); + } +} + +void GPUSetPaletteFormat(GPUPaletteFormat format) { + +} + +void GPUSetPaletteEntry(uint32_t idx, uint32_t value) { + +} + +void GPUSetBackgroundColour(float r, float g, float b) { + +} + +void GPUSetAlphaCutOff(uint8_t v) { + +} + +void GPUSetClearDepth(float v) { + +} + +void GPUSetFogLinear(float start, float end) { + +} + +void GPUSetFogExp(float density) { + +} + +void GPUSetFogExp2(float density) { + +} + +void GPUSetFogColor(float r, float g, float b, float a) { + +} diff --git a/GL/platforms/x86.h b/GL/platforms/x86.h index 722cd83..30698ee 100644 --- a/GL/platforms/x86.h +++ b/GL/platforms/x86.h @@ -14,6 +14,7 @@ #define FASTCPY(dst, src, bytes) memcpy(dst, src, bytes) #define FASTCPY4(dst, src, bytes) memcpy(dst, src, bytes) #define MEMSET4(dst, v, size) memset((dst), (v), (size)) + #define VEC3_NORMALIZE(x, y, z) \ do { \ float l = MATH_fsrra((x) * (x) + (y) * (y) + (z) * (z)); \ @@ -31,55 +32,46 @@ struct PolyHeader; struct PolyContext; -inline void CompilePolyHeader(PolyHeader* out, const PolyContext* in) { +static inline void CompilePolyHeader(PolyHeader* out, const PolyContext* in) { (void) out; (void) in; } -inline void UploadMatrix4x4(const Matrix4x4* mat) { - (void) mat; -} - -inline void MultiplyMatrix4x4(const Matrix4x4* mat) { - (void) mat; -} - -inline void DownloadMatrix4x4(Matrix4x4* mat) { - (void) mat; -} +void UploadMatrix4x4(const Matrix4x4* mat); +void MultiplyMatrix4x4(const Matrix4x4* mat); +void DownloadMatrix4x4(Matrix4x4* mat); /* Transform a 3-element vector in-place using the stored matrix (w == 1) */ -inline void TransformVec3(float* x) { +static inline void TransformVec3(float* x) { } /* Transform a 3-element vector using the stored matrix (w == 1) */ -inline void TransformVec3NoMod(const float* xIn, float* xOut) { +static inline void TransformVec3NoMod(const float* xIn, float* xOut) { } /* Transform a 3-element normal using the stored matrix (w == 0)*/ -inline void TransformNormalNoMod(const float* xIn, float* xOut) { +static inline void TransformNormalNoMod(const float* xIn, float* xOut) { } /* Transform a 4-element vector in-place by the stored matrix */ -inline void TransformVec4(float* x) { +static inline void TransformVec4(float* x) { } -inline void TransformVertices(const Vertex* vertices, const int count) { +static inline void TransformVertices(const Vertex* vertices, const int count) { (void) vertices; (void) count; } void InitGPU(_Bool autosort, _Bool fsaa); -size_t GPUMemoryAvailable(); -void* GPUMemoryAlloc(size_t size); - enum GPUPaletteFormat; +size_t GPUMemoryAvailable(); +void* GPUMemoryAlloc(size_t size); void GPUSetPaletteFormat(GPUPaletteFormat format); void GPUSetPaletteEntry(uint32_t idx, uint32_t value); diff --git a/GL/private.h b/GL/private.h index abe0c58..3236498 100644 --- a/GL/private.h +++ b/GL/private.h @@ -7,7 +7,10 @@ #include "platform.h" #include "types.h" -#include "../include/gl.h" +#include "../include/GL/gl.h" +#include "../include/GL/glext.h" +#include "../include/GL/glkos.h" + #include "../containers/aligned_vector.h" #include "../containers/named_array.h" diff --git a/GL/state.c b/GL/state.c index 4488398..6665d1a 100644 --- a/GL/state.c +++ b/GL/state.c @@ -2,10 +2,6 @@ #include #include -#include "../include/gl.h" -#include "../include/glext.h" -#include "../include/glkos.h" - #include "private.h" static PolyContext GL_CONTEXT; @@ -641,10 +637,10 @@ void APIENTRY glGetBooleanv(GLenum pname, GLboolean* params) { void APIENTRY glGetFloatv(GLenum pname, GLfloat* params) { switch(pname) { case GL_PROJECTION_MATRIX: - memcpy4(params, _glGetProjectionMatrix(), sizeof(float) * 16); + FASTCPY4(params, _glGetProjectionMatrix(), sizeof(float) * 16); break; case GL_MODELVIEW_MATRIX: - memcpy4(params, _glGetModelViewMatrix(), sizeof(float) * 16); + FASTCPY4(params, _glGetModelViewMatrix(), sizeof(float) * 16); break; case GL_POLYGON_OFFSET_FACTOR: *params = OFFSET_FACTOR; diff --git a/GL/texture.c b/GL/texture.c index 01a3d68..fca7c07 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -8,8 +8,6 @@ #include "config.h" #include "platform.h" -#include "../include/glext.h" -#include "../include/glkos.h" #include "yalloc/yalloc.h" diff --git a/GL/util.c b/GL/util.c index eaf2e17..835dd98 100644 --- a/GL/util.c +++ b/GL/util.c @@ -1,4 +1,4 @@ -#include "../include/glkos.h" +#include "private.h" void APIENTRY glVertexPackColor3fKOS(GLVertexKOS* vertex, float r, float g, float b) { vertex->bgra[3] = 255; diff --git a/include/gl.h b/include/GL/gl.h similarity index 100% rename from include/gl.h rename to include/GL/gl.h diff --git a/include/glext.h b/include/GL/glext.h similarity index 100% rename from include/glext.h rename to include/GL/glext.h diff --git a/include/glkos.h b/include/GL/glkos.h similarity index 100% rename from include/glkos.h rename to include/GL/glkos.h diff --git a/include/glu.h b/include/GL/glu.h similarity index 100% rename from include/glu.h rename to include/GL/glu.h diff --git a/samples/nehe02/main.c b/samples/nehe02/main.c index b3782e6..aeaa8b8 100644 --- a/samples/nehe02/main.c +++ b/samples/nehe02/main.c @@ -1,6 +1,6 @@ -#include "gl.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/glkos.h" /* A general OpenGL initialization function. Sets all of the initial parameters. */ void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.