mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-08-20 09:57:10 +00:00
faster texture loading
This commit is contained in:
parent
fdb2a1098b
commit
587d685c5b
|
|
@ -471,10 +471,11 @@ void Texture::blit(int x, int y, Texture* source, bool rotated) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::transferFromBuffer(intArray buffer) {
|
void Texture::transferFromBuffer(intArray buffer) {
|
||||||
if (depth == 1) {
|
//if (depth == 1) {
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
// 4jcraft - move pos out of loops
|
||||||
|
data[0]->clear();
|
||||||
// #ifdef __PS3__
|
// #ifdef __PS3__
|
||||||
// int byteRemapRGBA[] = { 3, 0, 1, 2 };
|
// int byteRemapRGBA[] = { 3, 0, 1, 2 };
|
||||||
// int byteRemapBGRA[] = { 3, 2, 1, 0 };
|
// int byteRemapBGRA[] = { 3, 2, 1, 0 };
|
||||||
|
|
@ -484,7 +485,24 @@ void Texture::transferFromBuffer(intArray buffer) {
|
||||||
// #endif
|
// #endif
|
||||||
int* byteRemap = ((format == TFMT_BGRA) ? byteRemapBGRA : byteRemapRGBA);
|
int* byteRemap = ((format == TFMT_BGRA) ? byteRemapBGRA : byteRemapRGBA);
|
||||||
|
|
||||||
for (int z = 0; z < depth; z++) {
|
int totalPixels = width * height * depth;
|
||||||
|
|
||||||
|
for (int i = 0; i < totalPixels; i++){
|
||||||
|
int pixel = buffer[i];
|
||||||
|
int offset = i * 4;
|
||||||
|
|
||||||
|
data[0]->put(offset + byteRemap[0], (uint8_t)((pixel >> 24) & 0xff));
|
||||||
|
data[0]->put(offset + byteRemap[1], (uint8_t)((pixel >> 16) & 0xff));
|
||||||
|
data[0]->put(offset + byteRemap[2], (uint8_t)((pixel >> 8) & 0xff));
|
||||||
|
data[0]->put(offset + byteRemap[3], (uint8_t)((pixel >> 0) & 0xff));
|
||||||
|
|
||||||
|
data[0]->position(totalPixels * 4);
|
||||||
|
data[0]->limit(totalPixels * 4);
|
||||||
|
|
||||||
|
updateOnGPU();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for (int z = 0; z < depth; z++) {
|
||||||
int plane = z * height * width * 4;
|
int plane = z * height * width * 4;
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
int column = plane + y * width * 4;
|
int column = plane + y * width * 4;
|
||||||
|
|
@ -504,6 +522,7 @@ void Texture::transferFromBuffer(intArray buffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
data[0]->position(width * height * depth * 4);
|
data[0]->position(width * height * depth * 4);
|
||||||
|
*/
|
||||||
|
|
||||||
updateOnGPU();
|
updateOnGPU();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue