diff options
Diffstat (limited to 'src/asset/texture.c')
-rw-r--r-- | src/asset/texture.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/asset/texture.c b/src/asset/texture.c index c790394..fb423cc 100644 --- a/src/asset/texture.c +++ b/src/asset/texture.c | |||
@@ -49,7 +49,7 @@ Texture* gfx_texture_load(GfxCore* gfxcore, const LoadTextureCmd* cmd) { | |||
49 | assert(cmd->origin == AssetFromFile || cmd->origin == AssetFromMemory); | 49 | assert(cmd->origin == AssetFromFile || cmd->origin == AssetFromMemory); |
50 | assert(cmd->type == LoadTexture || cmd->type == LoadCubemap); | 50 | assert(cmd->type == LoadTexture || cmd->type == LoadCubemap); |
51 | 51 | ||
52 | int width, height, components, old_components; | 52 | int width, height, components; |
53 | unsigned char* pixels[6] = {0}; | 53 | unsigned char* pixels[6] = {0}; |
54 | 54 | ||
55 | switch (cmd->origin) { | 55 | switch (cmd->origin) { |
@@ -64,7 +64,8 @@ Texture* gfx_texture_load(GfxCore* gfxcore, const LoadTextureCmd* cmd) { | |||
64 | } | 64 | } |
65 | break; | 65 | break; |
66 | } | 66 | } |
67 | case LoadCubemap: | 67 | case LoadCubemap: { |
68 | int old_components = 0; | ||
68 | for (int i = 0; i < 6; ++i) { | 69 | for (int i = 0; i < 6; ++i) { |
69 | // Flip +Y and -Y textures vertically. | 70 | // Flip +Y and -Y textures vertically. |
70 | stbi_set_flip_vertically_on_load(((i == 2) || (i == 3)) ? 1 : 0); | 71 | stbi_set_flip_vertically_on_load(((i == 2) || (i == 3)) ? 1 : 0); |
@@ -76,9 +77,10 @@ Texture* gfx_texture_load(GfxCore* gfxcore, const LoadTextureCmd* cmd) { | |||
76 | log_error("Failed to load texture file: %s", filepath); | 77 | log_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 | log_error("All textures in a cubemap must have the same number of " | 81 | log_error( |
81 | "components"); | 82 | "All textures in a cubemap must have the same number of " |
83 | "components"); | ||
82 | break; | 84 | break; |
83 | } | 85 | } |
84 | if ((i != 2) && (i != 3)) { | 86 | if ((i != 2) && (i != 3)) { |
@@ -89,6 +91,7 @@ Texture* gfx_texture_load(GfxCore* gfxcore, const LoadTextureCmd* cmd) { | |||
89 | } | 91 | } |
90 | break; | 92 | break; |
91 | } | 93 | } |
94 | } | ||
92 | break; | 95 | break; |
93 | case AssetFromMemory: | 96 | case AssetFromMemory: |
94 | // TODO: Load textures from memory. | 97 | // TODO: Load textures from memory. |
@@ -122,6 +125,25 @@ Texture* gfx_texture_load(GfxCore* gfxcore, const LoadTextureCmd* cmd) { | |||
122 | } | 125 | } |
123 | 126 | ||
124 | switch (components) { | 127 | switch (components) { |
128 | case 1: | ||
129 | switch (cmd->colour_space) { | ||
130 | case LinearColourSpace: | ||
131 | desc.format = TextureR8; | ||
132 | break; | ||
133 | case sRGB: | ||
134 | // TODO: Gamma single-channel textures are not implemented yet. | ||
135 | // The caller should convert the single-channel to RGB and pass it down | ||
136 | // as sRGB. This is why the ChronographWatch currently appears red on the | ||
137 | // back. | ||
138 | log_error("Gamma colour space is not supported for 1-channel textures"); | ||
139 | // return 0; | ||
140 | desc.format = TextureR8; | ||
141 | break; | ||
142 | default: | ||
143 | log_error("Unsupported texture colour space: %d", cmd->colour_space); | ||
144 | return 0; | ||
145 | } | ||
146 | break; | ||
125 | case 3: | 147 | case 3: |
126 | switch (cmd->colour_space) { | 148 | switch (cmd->colour_space) { |
127 | case LinearColourSpace: | 149 | case LinearColourSpace: |