diff options
| author | 3gg <3gg@shellblade.net> | 2023-06-17 20:23:34 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2023-06-17 20:23:34 -0700 |
| commit | 9d1eb251b5d26759e17dd7bee316cf27fdcb28bf (patch) | |
| tree | 639b6f95cf4e9a00a388ae6c1d26dc4cebee6583 | |
| parent | 520e4e67cd9ff53f3c3512c80d07193625e07e3e (diff) | |
Move and import error library from clib.
| -rw-r--r-- | gfx/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | gfx/include/gfx/error.h | 22 | ||||
| -rw-r--r-- | gfx/src/error.c | 5 | ||||
| -rw-r--r-- | gfx/src/render/framebuffer.c | 67 | ||||
| -rw-r--r-- | gfx/src/render/renderbuffer.c | 14 | ||||
| -rw-r--r-- | gfx/src/render/texture.c | 5 | ||||
| -rw-r--r-- | gfx/src/scene/light.c | 10 | ||||
| -rw-r--r-- | gfx/src/util/scene.c | 4 | ||||
| -rw-r--r-- | gfx/src/util/texture.c | 20 | ||||
| -rw-r--r-- | gltfview/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | gltfview/src/game.c | 4 |
11 files changed, 64 insertions, 90 deletions
diff --git a/gfx/CMakeLists.txt b/gfx/CMakeLists.txt index f5c9b5a..f5ef44c 100644 --- a/gfx/CMakeLists.txt +++ b/gfx/CMakeLists.txt | |||
| @@ -52,7 +52,6 @@ add_library(gfx SHARED | |||
| 52 | src/scene/object.c | 52 | src/scene/object.c |
| 53 | src/scene/scene.c | 53 | src/scene/scene.c |
| 54 | src/scene/scene_memory.c | 54 | src/scene/scene_memory.c |
| 55 | src/error.c | ||
| 56 | src/gfx.c | 55 | src/gfx.c |
| 57 | src/util/geometry.c | 56 | src/util/geometry.c |
| 58 | src/util/ibl.c | 57 | src/util/ibl.c |
| @@ -75,6 +74,7 @@ target_link_libraries(gfx PUBLIC | |||
| 75 | target_link_libraries(gfx PRIVATE | 74 | target_link_libraries(gfx PRIVATE |
| 76 | cgltf | 75 | cgltf |
| 77 | cgltf-tangents | 76 | cgltf-tangents |
| 77 | error | ||
| 78 | glad | 78 | glad |
| 79 | listpool | 79 | listpool |
| 80 | log | 80 | log |
diff --git a/gfx/include/gfx/error.h b/gfx/include/gfx/error.h deleted file mode 100644 index 062dba1..0000000 --- a/gfx/include/gfx/error.h +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstring.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | /// Get the last error. | ||
| 7 | const char* gfx_get_error(void); | ||
| 8 | |||
| 9 | extern xlstring gfx_error; | ||
| 10 | |||
| 11 | /// Set the last error. | ||
| 12 | #define gfx_set_error(...) \ | ||
| 13 | gfx_error.length = snprintf(gfx_error.str, xlstring_size, __VA_ARGS__) | ||
| 14 | |||
| 15 | /// Prepend an error to the last error. | ||
| 16 | #define gfx_prepend_error(...) \ | ||
| 17 | { \ | ||
| 18 | xlstring head; \ | ||
| 19 | head.length = snprintf(head.str, xlstring_size, __VA_ARGS__); \ | ||
| 20 | xlstring_append(&head, xlstring_make(": ")); \ | ||
| 21 | gfx_error = xlstring_concat(head, gfx_error); \ | ||
| 22 | } | ||
diff --git a/gfx/src/error.c b/gfx/src/error.c deleted file mode 100644 index 4370097..0000000 --- a/gfx/src/error.c +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | #include <gfx/error.h> | ||
| 2 | |||
| 3 | xlstring gfx_error; | ||
| 4 | |||
| 5 | const char* gfx_get_error(void) { return xlstring_cstr(&gfx_error); } | ||
diff --git a/gfx/src/render/framebuffer.c b/gfx/src/render/framebuffer.c index 323ef56..84ade4a 100644 --- a/gfx/src/render/framebuffer.c +++ b/gfx/src/render/framebuffer.c | |||
| @@ -3,12 +3,12 @@ | |||
| 3 | #include "renderbuffer.h" | 3 | #include "renderbuffer.h" |
| 4 | #include "texture.h" | 4 | #include "texture.h" |
| 5 | 5 | ||
| 6 | #include <gfx/error.h> | 6 | #include <error.h> |
| 7 | 7 | ||
| 8 | #include <assert.h> | 8 | #include <assert.h> |
| 9 | 9 | ||
| 10 | static void framebuffer_attach_colour(FrameBuffer* framebuffer, | 10 | static void framebuffer_attach_colour( |
| 11 | const FrameBufferAttachment* attachment) { | 11 | FrameBuffer* framebuffer, const FrameBufferAttachment* attachment) { |
| 12 | assert(framebuffer); | 12 | assert(framebuffer); |
| 13 | assert(attachment); | 13 | assert(attachment); |
| 14 | 14 | ||
| @@ -16,27 +16,28 @@ static void framebuffer_attach_colour(FrameBuffer* framebuffer, | |||
| 16 | case FrameBufferNoAttachment: | 16 | case FrameBufferNoAttachment: |
| 17 | break; | 17 | break; |
| 18 | case FrameBufferTexture: | 18 | case FrameBufferTexture: |
| 19 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 19 | glFramebufferTexture2D( |
| 20 | attachment->texture.texture->id, | 20 | GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 21 | attachment->texture.mip_level); | 21 | attachment->texture.texture->id, attachment->texture.mip_level); |
| 22 | break; | 22 | break; |
| 23 | case FrameBufferCubemapTexture: | 23 | case FrameBufferCubemapTexture: |
| 24 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 24 | glFramebufferTexture2D( |
| 25 | to_GL_cubemap_face(attachment->cubemap.face), | 25 | GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 26 | attachment->cubemap.texture->id, | 26 | to_GL_cubemap_face(attachment->cubemap.face), |
| 27 | attachment->cubemap.mip_level); | 27 | attachment->cubemap.texture->id, attachment->cubemap.mip_level); |
| 28 | break; | 28 | break; |
| 29 | case FrameBufferRenderBuffer: | 29 | case FrameBufferRenderBuffer: |
| 30 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 30 | glFramebufferRenderbuffer( |
| 31 | GL_RENDERBUFFER, attachment->renderbuffer->id); | 31 | GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, |
| 32 | attachment->renderbuffer->id); | ||
| 32 | break; | 33 | break; |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 35 | ASSERT_GL; | 36 | ASSERT_GL; |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | static void framebuffer_attach_depth(FrameBuffer* framebuffer, | 39 | static void framebuffer_attach_depth( |
| 39 | const FrameBufferAttachment* attachment) { | 40 | FrameBuffer* framebuffer, const FrameBufferAttachment* attachment) { |
| 40 | assert(framebuffer); | 41 | assert(framebuffer); |
| 41 | assert(attachment); | 42 | assert(attachment); |
| 42 | 43 | ||
| @@ -44,33 +45,33 @@ static void framebuffer_attach_depth(FrameBuffer* framebuffer, | |||
| 44 | case FrameBufferNoAttachment: | 45 | case FrameBufferNoAttachment: |
| 45 | break; | 46 | break; |
| 46 | case FrameBufferTexture: | 47 | case FrameBufferTexture: |
| 47 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | 48 | glFramebufferTexture2D( |
| 48 | GL_DEPTH_COMPONENT, attachment->texture.texture->id, | 49 | GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT, |
| 49 | attachment->texture.mip_level); | 50 | attachment->texture.texture->id, attachment->texture.mip_level); |
| 50 | break; | 51 | break; |
| 51 | // TODO: Could distinguish between colour and depth attachment types to make | 52 | // TODO: Could distinguish between colour and depth attachment types to make |
| 52 | // this a compile-time error. | 53 | // this a compile-time error. |
| 53 | case FrameBufferCubemapTexture: | 54 | case FrameBufferCubemapTexture: |
| 54 | gfx_set_error( | 55 | set_error("Cannot use a cubemap texture as a depth framebuffer attachment"); |
| 55 | "Cannot use a cubemap texture as a depth framebuffer attachment"); | ||
| 56 | break; | 56 | break; |
| 57 | case FrameBufferRenderBuffer: | 57 | case FrameBufferRenderBuffer: |
| 58 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | 58 | glFramebufferRenderbuffer( |
| 59 | GL_RENDERBUFFER, attachment->renderbuffer->id); | 59 | GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, |
| 60 | attachment->renderbuffer->id); | ||
| 60 | break; | 61 | break; |
| 61 | } | 62 | } |
| 62 | 63 | ||
| 63 | ASSERT_GL; | 64 | ASSERT_GL; |
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | bool gfx_init_framebuffer(FrameBuffer* framebuffer, | 67 | bool gfx_init_framebuffer( |
| 67 | const FrameBufferDesc* desc) { | 68 | FrameBuffer* framebuffer, const FrameBufferDesc* desc) { |
| 68 | assert(framebuffer); | 69 | assert(framebuffer); |
| 69 | assert(desc); | 70 | assert(desc); |
| 70 | 71 | ||
| 71 | glGenFramebuffers(1, &framebuffer->id); | 72 | glGenFramebuffers(1, &framebuffer->id); |
| 72 | if (!framebuffer->id) { | 73 | if (!framebuffer->id) { |
| 73 | gfx_set_error("glGenFramebuffers() failed"); | 74 | set_error("glGenFramebuffers() failed"); |
| 74 | return false; | 75 | return false; |
| 75 | } | 76 | } |
| 76 | 77 | ||
| @@ -84,7 +85,7 @@ bool gfx_init_framebuffer(FrameBuffer* framebuffer, | |||
| 84 | framebuffer_attach_colour(framebuffer, &desc->colour); | 85 | framebuffer_attach_colour(framebuffer, &desc->colour); |
| 85 | framebuffer_attach_depth(framebuffer, &desc->depth); | 86 | framebuffer_attach_depth(framebuffer, &desc->depth); |
| 86 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { | 87 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { |
| 87 | gfx_set_error("glCheckFramebufferStatus() failed"); | 88 | set_error("glCheckFramebufferStatus() failed"); |
| 88 | gfx_del_framebuffer(framebuffer); | 89 | gfx_del_framebuffer(framebuffer); |
| 89 | return false; | 90 | return false; |
| 90 | } | 91 | } |
| @@ -95,8 +96,8 @@ bool gfx_init_framebuffer(FrameBuffer* framebuffer, | |||
| 95 | return true; | 96 | return true; |
| 96 | } | 97 | } |
| 97 | 98 | ||
| 98 | bool gfx_framebuffer_attach_colour(FrameBuffer* framebuffer, | 99 | bool gfx_framebuffer_attach_colour( |
| 99 | const FrameBufferAttachment* attachment) { | 100 | FrameBuffer* framebuffer, const FrameBufferAttachment* attachment) { |
| 100 | assert(framebuffer); | 101 | assert(framebuffer); |
| 101 | assert(attachment); | 102 | assert(attachment); |
| 102 | 103 | ||
| @@ -104,14 +105,14 @@ bool gfx_framebuffer_attach_colour(FrameBuffer* framebuffer, | |||
| 104 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->id); | 105 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->id); |
| 105 | framebuffer_attach_colour(framebuffer, attachment); | 106 | framebuffer_attach_colour(framebuffer, attachment); |
| 106 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { | 107 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { |
| 107 | gfx_set_error("glCheckFramebufferStatus() failed"); | 108 | set_error("glCheckFramebufferStatus() failed"); |
| 108 | return false; | 109 | return false; |
| 109 | } | 110 | } |
| 110 | return true; | 111 | return true; |
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | bool gfx_framebuffer_attach_depth(FrameBuffer* framebuffer, | 114 | bool gfx_framebuffer_attach_depth( |
| 114 | const FrameBufferAttachment* attachment) { | 115 | FrameBuffer* framebuffer, const FrameBufferAttachment* attachment) { |
| 115 | assert(framebuffer); | 116 | assert(framebuffer); |
| 116 | assert(attachment); | 117 | assert(attachment); |
| 117 | 118 | ||
| @@ -119,7 +120,7 @@ bool gfx_framebuffer_attach_depth(FrameBuffer* framebuffer, | |||
| 119 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->id); | 120 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->id); |
| 120 | framebuffer_attach_depth(framebuffer, attachment); | 121 | framebuffer_attach_depth(framebuffer, attachment); |
| 121 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { | 122 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { |
| 122 | gfx_set_error("glCheckFramebufferStatus() failed"); | 123 | set_error("glCheckFramebufferStatus() failed"); |
| 123 | return false; | 124 | return false; |
| 124 | } | 125 | } |
| 125 | return true; | 126 | return true; |
| @@ -143,8 +144,8 @@ void gfx_deactivate_framebuffer(const FrameBuffer* framebuffer) { | |||
| 143 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | 144 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | void gfx_framebuffer_set_viewport(FrameBuffer* framebuffer, int x, int y, | 147 | void gfx_framebuffer_set_viewport( |
| 147 | int width, int height) { | 148 | FrameBuffer* framebuffer, int x, int y, int width, int height) { |
| 148 | assert(framebuffer); | 149 | assert(framebuffer); |
| 149 | glViewport(x, y, width, height); | 150 | glViewport(x, y, width, height); |
| 150 | } | 151 | } |
diff --git a/gfx/src/render/renderbuffer.c b/gfx/src/render/renderbuffer.c index 3b19483..a2eae52 100644 --- a/gfx/src/render/renderbuffer.c +++ b/gfx/src/render/renderbuffer.c | |||
| @@ -2,23 +2,23 @@ | |||
| 2 | 2 | ||
| 3 | #include "texture.h" | 3 | #include "texture.h" |
| 4 | 4 | ||
| 5 | #include <gfx/error.h> | 5 | #include <error.h> |
| 6 | 6 | ||
| 7 | bool gfx_init_renderbuffer(RenderBuffer* renderbuffer, | 7 | bool gfx_init_renderbuffer( |
| 8 | const RenderBufferDesc* desc) { | 8 | RenderBuffer* renderbuffer, const RenderBufferDesc* desc) { |
| 9 | assert(renderbuffer); | 9 | assert(renderbuffer); |
| 10 | assert(desc); | 10 | assert(desc); |
| 11 | 11 | ||
| 12 | glGenRenderbuffers(1, &renderbuffer->id); | 12 | glGenRenderbuffers(1, &renderbuffer->id); |
| 13 | if (!renderbuffer->id) { | 13 | if (!renderbuffer->id) { |
| 14 | gfx_set_error("glGenRenderbuffers failed"); | 14 | set_error("glGenRenderbuffers failed"); |
| 15 | return false; | 15 | return false; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer->id); | 18 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer->id); |
| 19 | glRenderbufferStorage(GL_RENDERBUFFER, | 19 | glRenderbufferStorage( |
| 20 | to_GL_internal_format(desc->texture_format), | 20 | GL_RENDERBUFFER, to_GL_internal_format(desc->texture_format), desc->width, |
| 21 | desc->width, desc->height); | 21 | desc->height); |
| 22 | glBindRenderbuffer(GL_RENDERBUFFER, 0); | 22 | glBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 23 | 23 | ||
| 24 | ASSERT_GL; | 24 | ASSERT_GL; |
diff --git a/gfx/src/render/texture.c b/gfx/src/render/texture.c index 31bf636..312aecc 100644 --- a/gfx/src/render/texture.c +++ b/gfx/src/render/texture.c | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #include "texture.h" | 1 | #include "texture.h" |
| 2 | 2 | ||
| 3 | #include <gfx/error.h> | 3 | #include <error.h> |
| 4 | |||
| 5 | #include <math/defs.h> | 4 | #include <math/defs.h> |
| 6 | 5 | ||
| 7 | #include <assert.h> | 6 | #include <assert.h> |
| @@ -13,7 +12,7 @@ bool gfx_init_texture(Texture* texture, const TextureDesc* desc) { | |||
| 13 | 12 | ||
| 14 | glGenTextures(1, &texture->id); | 13 | glGenTextures(1, &texture->id); |
| 15 | if (!texture->id) { | 14 | if (!texture->id) { |
| 16 | gfx_set_error("glGenTextures() failed"); | 15 | set_error("glGenTextures() failed"); |
| 17 | return false; | 16 | return false; |
| 18 | } | 17 | } |
| 19 | texture->target = to_GL_dimension(desc->dimension); | 18 | texture->target = to_GL_dimension(desc->dimension); |
diff --git a/gfx/src/scene/light.c b/gfx/src/scene/light.c index 2ca1a01..31dca77 100644 --- a/gfx/src/scene/light.c +++ b/gfx/src/scene/light.c | |||
| @@ -3,14 +3,14 @@ | |||
| 3 | #include "node_impl.h" | 3 | #include "node_impl.h" |
| 4 | #include "scene_memory.h" | 4 | #include "scene_memory.h" |
| 5 | 5 | ||
| 6 | #include <gfx/error.h> | 6 | #include <error.h> |
| 7 | 7 | ||
| 8 | static void make_environment_light(Light* light, | 8 | static void make_environment_light( |
| 9 | const EnvironmentLightDesc* desc) { | 9 | Light* light, const EnvironmentLightDesc* desc) { |
| 10 | assert(light); | 10 | assert(light); |
| 11 | assert(desc); | 11 | assert(desc); |
| 12 | 12 | ||
| 13 | light->type = EnvironmentLightType; | 13 | light->type = EnvironmentLightType; |
| 14 | light->environment.environment_map = desc->environment_map; | 14 | light->environment.environment_map = desc->environment_map; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| @@ -27,7 +27,7 @@ Light* gfx_make_light(const LightDesc* desc) { | |||
| 27 | make_environment_light(light, &desc->light.environment); | 27 | make_environment_light(light, &desc->light.environment); |
| 28 | break; | 28 | break; |
| 29 | default: | 29 | default: |
| 30 | gfx_set_error("Unhandled light type"); | 30 | set_error("Unhandled light type"); |
| 31 | gfx_destroy_light(&light); | 31 | gfx_destroy_light(&light); |
| 32 | return 0; | 32 | return 0; |
| 33 | } | 33 | } |
diff --git a/gfx/src/util/scene.c b/gfx/src/util/scene.c index a638fa5..5d79cf2 100644 --- a/gfx/src/util/scene.c +++ b/gfx/src/util/scene.c | |||
| @@ -81,7 +81,6 @@ | |||
| 81 | 81 | ||
| 82 | #include <gfx/util/scene.h> | 82 | #include <gfx/util/scene.h> |
| 83 | 83 | ||
| 84 | #include <gfx/error.h> | ||
| 85 | #include <gfx/gfx.h> | 84 | #include <gfx/gfx.h> |
| 86 | #include <gfx/render_backend.h> | 85 | #include <gfx/render_backend.h> |
| 87 | #include <gfx/scene/animation.h> | 86 | #include <gfx/scene/animation.h> |
| @@ -96,6 +95,7 @@ | |||
| 96 | #include <gfx/util/texture.h> | 95 | #include <gfx/util/texture.h> |
| 97 | 96 | ||
| 98 | #include <cstring.h> | 97 | #include <cstring.h> |
| 98 | #include <error.h> | ||
| 99 | #include <log/log.h> | 99 | #include <log/log.h> |
| 100 | #include <math/camera.h> | 100 | #include <math/camera.h> |
| 101 | #include <math/defs.h> | 101 | #include <math/defs.h> |
| @@ -702,7 +702,7 @@ static bool load_texture_and_uniform( | |||
| 702 | 702 | ||
| 703 | textures[texture_index] = gfx_load_texture(render_backend, cmd); | 703 | textures[texture_index] = gfx_load_texture(render_backend, cmd); |
| 704 | if (!textures[texture_index]) { | 704 | if (!textures[texture_index]) { |
| 705 | gfx_prepend_error( | 705 | prepend_error( |
| 706 | "Failed to load texture: %s", | 706 | "Failed to load texture: %s", |
| 707 | mstring_cstr(&cmd->data.texture.filepath)); | 707 | mstring_cstr(&cmd->data.texture.filepath)); |
| 708 | return false; | 708 | return false; |
diff --git a/gfx/src/util/texture.c b/gfx/src/util/texture.c index 0727dae..7ec0e40 100644 --- a/gfx/src/util/texture.c +++ b/gfx/src/util/texture.c | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | #include <gfx/util/texture.h> | 1 | #include <gfx/util/texture.h> |
| 2 | 2 | ||
| 3 | #include <gfx/error.h> | ||
| 4 | #include <gfx/render_backend.h> | 3 | #include <gfx/render_backend.h> |
| 5 | 4 | ||
| 5 | #include <error.h> | ||
| 6 | |||
| 6 | #define STB_IMAGE_IMPLEMENTATION | 7 | #define STB_IMAGE_IMPLEMENTATION |
| 7 | #include <stb_image.h> | 8 | #include <stb_image.h> |
| 8 | 9 | ||
| @@ -60,7 +61,7 @@ Texture* gfx_load_texture( | |||
| 60 | stbi_set_flip_vertically_on_load(0); | 61 | stbi_set_flip_vertically_on_load(0); |
| 61 | pixels[0] = stbi_load(filepath, &width, &height, &components, 0); | 62 | pixels[0] = stbi_load(filepath, &width, &height, &components, 0); |
| 62 | if (!pixels[0]) { | 63 | if (!pixels[0]) { |
| 63 | gfx_set_error("Failed to load texture file: %s", filepath); | 64 | set_error("Failed to load texture file: %s", filepath); |
| 64 | } | 65 | } |
| 65 | break; | 66 | break; |
| 66 | } | 67 | } |
| @@ -73,13 +74,12 @@ Texture* gfx_load_texture( | |||
| 73 | stbi_uc* image_pixels = | 74 | stbi_uc* image_pixels = |
| 74 | stbi_load(filepath, &width, &height, &components, 0); | 75 | stbi_load(filepath, &width, &height, &components, 0); |
| 75 | if (!image_pixels) { | 76 | if (!image_pixels) { |
| 76 | gfx_set_error("Failed to load texture file: %s", filepath); | 77 | set_error("Failed to load texture file: %s", filepath); |
| 77 | break; | 78 | break; |
| 78 | } | 79 | } |
| 79 | if (i > 0 && components != old_components) { | 80 | if (i > 0 && components != old_components) { |
| 80 | gfx_set_error( | 81 | set_error("All textures in a cubemap must have the same number of " |
| 81 | "All textures in a cubemap must have the same number of " | 82 | "components"); |
| 82 | "components"); | ||
| 83 | break; | 83 | break; |
| 84 | } | 84 | } |
| 85 | if ((i != 2) && (i != 3)) { | 85 | if ((i != 2) && (i != 3)) { |
| @@ -93,7 +93,7 @@ Texture* gfx_load_texture( | |||
| 93 | break; | 93 | break; |
| 94 | case TextureFromMemory: | 94 | case TextureFromMemory: |
| 95 | // TODO: Load textures from memory. | 95 | // TODO: Load textures from memory. |
| 96 | gfx_set_error("Loading textures from memory is not yet implemented"); | 96 | set_error("Loading textures from memory is not yet implemented"); |
| 97 | return 0; | 97 | return 0; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| @@ -132,7 +132,7 @@ Texture* gfx_load_texture( | |||
| 132 | desc.format = TextureSRGB8; | 132 | desc.format = TextureSRGB8; |
| 133 | break; | 133 | break; |
| 134 | default: | 134 | default: |
| 135 | gfx_set_error("Unsupported texture colour space: %d", cmd->colour_space); | 135 | set_error("Unsupported texture colour space: %d", cmd->colour_space); |
| 136 | return 0; | 136 | return 0; |
| 137 | } | 137 | } |
| 138 | break; | 138 | break; |
| @@ -145,12 +145,12 @@ Texture* gfx_load_texture( | |||
| 145 | desc.format = TextureSRGBA8; | 145 | desc.format = TextureSRGBA8; |
| 146 | break; | 146 | break; |
| 147 | default: | 147 | default: |
| 148 | gfx_set_error("Unsupported texture colour space: %d", cmd->colour_space); | 148 | set_error("Unsupported texture colour space: %d", cmd->colour_space); |
| 149 | return 0; | 149 | return 0; |
| 150 | } | 150 | } |
| 151 | break; | 151 | break; |
| 152 | default: | 152 | default: |
| 153 | gfx_set_error("Unsupported number of texture components: %d", components); | 153 | set_error("Unsupported number of texture components: %d", components); |
| 154 | return 0; | 154 | return 0; |
| 155 | } | 155 | } |
| 156 | 156 | ||
diff --git a/gltfview/CMakeLists.txt b/gltfview/CMakeLists.txt index 0b0c3cc..de745ce 100644 --- a/gltfview/CMakeLists.txt +++ b/gltfview/CMakeLists.txt | |||
| @@ -13,6 +13,7 @@ target_include_directories(gltfview PRIVATE | |||
| 13 | 13 | ||
| 14 | target_link_libraries(gltfview PRIVATE | 14 | target_link_libraries(gltfview PRIVATE |
| 15 | cstring | 15 | cstring |
| 16 | error | ||
| 16 | gfx | 17 | gfx |
| 17 | gfx-app | 18 | gfx-app |
| 18 | list | 19 | list |
diff --git a/gltfview/src/game.c b/gltfview/src/game.c index 6d8430b..7470f75 100644 --- a/gltfview/src/game.c +++ b/gltfview/src/game.c | |||
| @@ -9,11 +9,11 @@ | |||
| 9 | #include "game.h" | 9 | #include "game.h" |
| 10 | #include "plugins/plugin.h" | 10 | #include "plugins/plugin.h" |
| 11 | 11 | ||
| 12 | #include <gfx/error.h> | ||
| 13 | #include <gfx/render_backend.h> | 12 | #include <gfx/render_backend.h> |
| 14 | #include <gfx/scene/camera.h> | 13 | #include <gfx/scene/camera.h> |
| 15 | #include <gfx/scene/object.h> | 14 | #include <gfx/scene/object.h> |
| 16 | 15 | ||
| 16 | #include <error.h> | ||
| 17 | #include <log/log.h> | 17 | #include <log/log.h> |
| 18 | #include <math/camera.h> | 18 | #include <math/camera.h> |
| 19 | #include <plugin.h> | 19 | #include <plugin.h> |
| @@ -105,7 +105,7 @@ bool game_new(Game* game, int argc, const char** argv) { | |||
| 105 | return true; | 105 | return true; |
| 106 | 106 | ||
| 107 | cleanup: | 107 | cleanup: |
| 108 | LOGE("Gfx error: %s", gfx_get_error()); | 108 | LOGE("Gfx error: %s", get_error()); |
| 109 | game_end(game); | 109 | game_end(game); |
| 110 | return false; | 110 | return false; |
| 111 | } | 111 | } |
