mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-05 22:03:36 +00:00
Fix texture allocation I think;
This commit is contained in:
parent
07af705e37
commit
dcef23640a
|
@ -52,16 +52,28 @@ static void lovrTextureAllocate(Texture* texture, TextureData* textureData) {
|
||||||
#ifndef EMSCRIPTEN
|
#ifndef EMSCRIPTEN
|
||||||
if (GLAD_GL_ARB_texture_storage) {
|
if (GLAD_GL_ARB_texture_storage) {
|
||||||
#endif
|
#endif
|
||||||
|
if (texture->type == TEXTURE_ARRAY) {
|
||||||
|
glTexStorage3D(texture->type, mipmapCount, internalFormat, w, h, texture->sliceCount);
|
||||||
|
} else {
|
||||||
glTexStorage2D(texture->type, mipmapCount, internalFormat, w, h);
|
glTexStorage2D(texture->type, mipmapCount, internalFormat, w, h);
|
||||||
|
}
|
||||||
#ifndef EMSCRIPTEN
|
#ifndef EMSCRIPTEN
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < mipmapCount; i++) {
|
for (int i = 0; i < mipmapCount; i++) {
|
||||||
if (texture->type == TEXTURE_CUBE) {
|
switch (texture->type) {
|
||||||
for (int face = 0; face < 6; face++) {
|
case TEXTURE_2D:
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, i, internalFormat, w, h, 0, glFormat, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(texture->type, i, internalFormat, w, h, 0, glFormat, GL_UNSIGNED_BYTE, NULL);
|
||||||
}
|
break;
|
||||||
} else {
|
|
||||||
glTexImage2D(texture->type, i, internalFormat, w, h, 0, glFormat, GL_UNSIGNED_BYTE, NULL);
|
case TEXTURE_CUBE:
|
||||||
|
for (int face = 0; face < 6; face++) {
|
||||||
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, i, internalFormat, w, h, 0, glFormat, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEXTURE_ARRAY:
|
||||||
|
glTexImage3D(texture->type, i, internalFormat, w, h, texture->sliceCount, 0, glFormat, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
w = MAX(w >> 1, 1);
|
w = MAX(w >> 1, 1);
|
||||||
h = MAX(h >> 1, 1);
|
h = MAX(h >> 1, 1);
|
||||||
|
@ -133,10 +145,27 @@ void lovrTextureReplacePixels(Texture* texture, TextureData* textureData, int sl
|
||||||
if (lovrTextureFormatIsCompressed(textureData->format)) {
|
if (lovrTextureFormatIsCompressed(textureData->format)) {
|
||||||
Mipmap m; int i;
|
Mipmap m; int i;
|
||||||
vec_foreach(&textureData->mipmaps, m, i) {
|
vec_foreach(&textureData->mipmaps, m, i) {
|
||||||
glCompressedTexImage2D(binding, i, glInternalFormat, m.width, m.height, 0, m.size, m.data);
|
switch (texture->type) {
|
||||||
|
case TEXTURE_2D:
|
||||||
|
case TEXTURE_CUBE:
|
||||||
|
glCompressedTexImage2D(binding, i, glInternalFormat, m.width, m.height, 0, m.size, m.data);
|
||||||
|
break;
|
||||||
|
case TEXTURE_ARRAY:
|
||||||
|
glCompressedTexSubImage3D(binding, i, 0, 0, slice, m.width, m.height, 1, glInternalFormat, m.size, m.data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glTexSubImage2D(binding, 0, 0, 0, textureData->width, textureData->height, glFormat, GL_UNSIGNED_BYTE, textureData->data);
|
switch (texture->type) {
|
||||||
|
case TEXTURE_2D:
|
||||||
|
case TEXTURE_CUBE:
|
||||||
|
glTexSubImage2D(binding, 0, 0, 0, textureData->width, textureData->height, glFormat, GL_UNSIGNED_BYTE, textureData->data);
|
||||||
|
break;
|
||||||
|
case TEXTURE_ARRAY:
|
||||||
|
glTexSubImage3D(binding, 0, 0, 0, slice, textureData->width, textureData->height, 1, glFormat, GL_UNSIGNED_BYTE, textureData->data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (texture->mipmaps) {
|
if (texture->mipmaps) {
|
||||||
glGenerateMipmap(texture->type);
|
glGenerateMipmap(texture->type);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue