mirror of https://github.com/bjornbytes/lovr.git
Texture:replacePixels supports mipmap;
This commit is contained in:
parent
2dc79a48a8
commit
66ca77abd1
|
@ -1112,7 +1112,7 @@ int l_lovrGraphicsNewTexture(lua_State* L) {
|
|||
for (int i = 0; i < depth; i++) {
|
||||
lua_rawgeti(L, 1, i + 1);
|
||||
TextureData* textureData = luax_checktexturedata(L, -1);
|
||||
lovrTextureReplacePixels(texture, textureData, 0, 0, i);
|
||||
lovrTextureReplacePixels(texture, textureData, 0, 0, i, 0);
|
||||
lovrRelease(textureData);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
|
|
@ -76,8 +76,9 @@ int l_lovrTextureReplacePixels(lua_State* L) {
|
|||
TextureData* textureData = luax_checktype(L, 2, TextureData);
|
||||
int x = luaL_optinteger(L, 3, 0);
|
||||
int y = luaL_optinteger(L, 4, 0);
|
||||
int slice = luaL_optinteger(L, 5, 1);
|
||||
lovrTextureReplacePixels(texture, textureData, x, y, slice - 1);
|
||||
int slice = luaL_optinteger(L, 5, 1) - 1;
|
||||
int mipmap = luaL_optinteger(L, 6, 1) - 1;
|
||||
lovrTextureReplacePixels(texture, textureData, x, y, slice, mipmap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ void lovrFontAddGlyph(Font* font, Glyph* glyph) {
|
|||
glyph->y = atlas->y;
|
||||
|
||||
// Paste glyph into texture
|
||||
lovrTextureReplacePixels(font->texture, glyph->data, atlas->x, atlas->y, 0);
|
||||
lovrTextureReplacePixels(font->texture, glyph->data, atlas->x, atlas->y, 0, 0);
|
||||
|
||||
// Advance atlas cursor
|
||||
atlas->x += glyph->tw + atlas->padding;
|
||||
|
|
|
@ -889,7 +889,7 @@ Texture* lovrTextureCreate(TextureType type, TextureData** slices, int depth, bo
|
|||
|
||||
if (slices) {
|
||||
for (int i = 0; i < depth; i++) {
|
||||
lovrTextureReplacePixels(texture, slices[i], 0, 0, i);
|
||||
lovrTextureReplacePixels(texture, slices[i], 0, 0, i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -930,7 +930,7 @@ TextureType lovrTextureGetType(Texture* texture) {
|
|||
return texture->type;
|
||||
}
|
||||
|
||||
void lovrTextureReplacePixels(Texture* texture, TextureData* textureData, int x, int y, int slice) {
|
||||
void lovrTextureReplacePixels(Texture* texture, TextureData* textureData, int x, int y, int slice, int mipmap) {
|
||||
lovrRetain(textureData);
|
||||
lovrRelease(texture->slices[slice]);
|
||||
texture->slices[slice] = textureData;
|
||||
|
@ -939,20 +939,24 @@ void lovrTextureReplacePixels(Texture* texture, TextureData* textureData, int x,
|
|||
if (!texture->allocated) {
|
||||
lovrAssert(texture->type != TEXTURE_CUBE || textureData->width == textureData->height, "Cubemap images must be square");
|
||||
lovrTextureAllocate(texture, textureData);
|
||||
} else {
|
||||
bool overflow = (x + textureData->width > texture->width) || (y + textureData->height > texture->height);
|
||||
lovrAssert(!overflow, "Trying to replace pixels outside the texture's bounds");
|
||||
}
|
||||
|
||||
if (!textureData->blob.data) {
|
||||
return;
|
||||
}
|
||||
|
||||
int width = lovrTextureGetWidth(texture, mipmap);
|
||||
int height = lovrTextureGetHeight(texture, mipmap);
|
||||
bool overflow = (x + textureData->width > width) || (y + textureData->height > height);
|
||||
lovrAssert(!overflow, "Trying to replace pixels outside the texture's bounds");
|
||||
lovrAssert(mipmap >= 0 && mipmap < texture->mipmapCount, "Invalid mipmap level %d", mipmap);
|
||||
GLenum glFormat = convertTextureFormat(textureData->format);
|
||||
GLenum glInternalFormat = convertTextureFormatInternal(textureData->format, texture->srgb);
|
||||
GLenum binding = (texture->type == TEXTURE_CUBE) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice : texture->glType;
|
||||
|
||||
if (isTextureFormatCompressed(textureData->format)) {
|
||||
lovrAssert(width == textureData->width && height == textureData->height, "Compressed texture pixels must be fully replaced");
|
||||
lovrAssert(mipmap == 0, "Unable to replace a specific mipmap of a compressed texture");
|
||||
Mipmap m; int i;
|
||||
vec_foreach(&textureData->mipmaps, m, i) {
|
||||
switch (texture->type) {
|
||||
|
@ -970,11 +974,11 @@ void lovrTextureReplacePixels(Texture* texture, TextureData* textureData, int x,
|
|||
switch (texture->type) {
|
||||
case TEXTURE_2D:
|
||||
case TEXTURE_CUBE:
|
||||
glTexSubImage2D(binding, 0, x, y, textureData->width, textureData->height, glFormat, GL_UNSIGNED_BYTE, textureData->blob.data);
|
||||
glTexSubImage2D(binding, mipmap, x, y, textureData->width, textureData->height, glFormat, GL_UNSIGNED_BYTE, textureData->blob.data);
|
||||
break;
|
||||
case TEXTURE_ARRAY:
|
||||
case TEXTURE_VOLUME:
|
||||
glTexSubImage3D(binding, 0, x, y, slice, textureData->width, textureData->height, 1, glFormat, GL_UNSIGNED_BYTE, textureData->blob.data);
|
||||
glTexSubImage3D(binding, mipmap, x, y, slice, textureData->width, textureData->height, 1, glFormat, GL_UNSIGNED_BYTE, textureData->blob.data);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ int lovrTextureGetHeight(Texture* texture, int mipmap);
|
|||
int lovrTextureGetDepth(Texture* texture, int mipmap);
|
||||
int lovrTextureGetMipmapCount(Texture* texture);
|
||||
TextureType lovrTextureGetType(Texture* texture);
|
||||
void lovrTextureReplacePixels(Texture* texture, TextureData* data, int x, int y, int slice);
|
||||
void lovrTextureReplacePixels(Texture* texture, TextureData* data, int x, int y, int slice, int mipmap);
|
||||
TextureFilter lovrTextureGetFilter(Texture* texture);
|
||||
void lovrTextureSetFilter(Texture* texture, TextureFilter filter);
|
||||
TextureWrap lovrTextureGetWrap(Texture* texture);
|
||||
|
|
Loading…
Reference in New Issue