commit 3690f0d8d79bf3950a6e14e85af747f1f8d4487a
parent ebc96d76759060471280a9e08177f67c5573a7b3
Author: amin <dev@aminmesbah.com>
Date: Sun, 21 Jul 2019 02:21:41 +0000
Don't use glTexStorage3D to allocate space
We want to require OpenGL 3.3, not 4.2.
FossilOrigin-Name: e685598703bd39f20bc1e95e2aecbae781e83d48553bd82013b820475c58e525
Diffstat:
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/am_math.h b/src/am_math.h
@@ -17,6 +17,12 @@ internal inline f32 math_max(f32 a, f32 b)
return max;
}
+internal inline u32 math_pow_of_2(u32 exponent)
+{
+ u32 result = 1 << exponent;
+ return result;
+}
+
internal inline i32 math_round(f32 n)
{
return n < 0.0f ? n - 0.5 : n + 0.5;
@@ -210,6 +216,12 @@ internal inline bool math_v2i_eq(v2i vec1, v2i vec2)
return result;
}
+internal inline bool math_v2u_eq(v2u vec1, v2u vec2)
+{
+ bool result = (vec1.x == vec2.x && vec1.y == vec2.y);
+ return result;
+}
+
internal inline v3 math_v3_cross(v3 vec1, v3 vec2)
{
// cross product, a.k.a. outer product or vector product
diff --git a/src/render.c b/src/render.c
@@ -58,7 +58,16 @@ internal void renderer_init(struct RendererState *renderer, struct Image *images
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D_ARRAY, texture_id);
u32 mip_map_levels = 4;
- glTexStorage3D(GL_TEXTURE_2D_ARRAY, mip_map_levels, GL_RGBA8, tile_dim.x, tile_dim.y, tileset_dim.x * tileset_dim.y);
+ // NOTE(amin): This allocates space for the 2D array texture. If we
+ // required OpenGL 4.2, we could instead use glTexStorage3D and no
+ // loop:
+ // glTexStorage3D(GL_TEXTURE_2D_ARRAY, mip_map_levels, GL_RGBA8, tile_dim.x, tile_dim.y, tileset_dim.x * tileset_dim.y);
+ for (u32 level = 0; level < mip_map_levels; level++)
+ {
+ v2u mip_dim = {tile_dim.x / math_pow_of_2(level), tile_dim.y / math_pow_of_2(level)};
+ assert(!math_v2u_eq(mip_dim, (v2u) {0, 0}));
+ glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL_RGBA8, mip_dim.x, mip_dim.y, tileset_dim.x * tileset_dim.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ }
size_t marker = mem_st_get_marker(allocator);
{