Hi, all.
when i was trying to update a small area of a texture with a second texture/image, i was embarassed that it is currently not possible. The modifyTexture method in the renderer-class only allows a texture to be updated completly by an image, where you are not able to select a region in that area. After reading a lot of documentation i decided to implement it.
Here is my contribution:
Renderer:
public void modifyTexture(Texture tex, Image pixels, int tileX, int tileY, int w, int h);
GLRenderer:
public void modifyTexture(Texture tex, Image pixels, int tileX, int tileY, int w, int h) {
setTexture(0, tex);
int target = convertTextureType(tex.getType(), pixels.getMultiSamples(), -1);
texUtil.uploadSubTexture(pixels, target, 0, tileX, tileY, w, h, linearizeSrgbImages);
}
TextureUtil:
public void uploadSubTexture(Image image, int target, int index, int tileX, int tileY, int w, int h, boolean linearizeSrgb) {
/*
similiar to public void uploadSubTexture(image, target, index, x, y, linearizeSrgb)
if (data == null) {
throw new IndexOutOfBoundsException("The image index " + index + " is not valid for the given image");
}
... here comes the new stuff
*/
data.limit(data.capacity());
int width = image.getWidth();
int pixelSize = image.getFormat().getBitsPerPixel() / 8;
for (int i = 0; i < h; i++) {
int y = tileY * h + i;
data.position((tileX + y * width) * pixelSize);
gl.glTexSubImage2D(target, 0, tileX, y, w, 1, oglFormat.format, oglFormat.dataType, data);
}
}
This was basically implemented in a different context and i just transformed it with no compiling. Feel free to give some feedback and maybe have that integrated into the engine.
Best regards.