Skip to content

Commit ba73a4b

Browse files
committed
Bugfix texturing, imagefactory GB format from BGR
1 parent f700510 commit ba73a4b

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

graphics-by-opengl-j2se/src/main/java/com/nucleus/opengl/assets/GLAssetManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ protected void loadTextures(NucleusRenderer renderer, GLTF gltf, Material materi
282282
// Material has both metallicroughness and occlusion in the same texture
283283
loadTexture(renderer, gltf, mrInfo, ImageFormat.RGB, ColorModel.LINEAR);
284284
} else {
285+
//TODO ImageFormat.RG actually means picking GB pixels and putting into RG (2 pixels)
285286
Texture mr = loadTexture(renderer, gltf, mrInfo, ImageFormat.RG,
286287
ColorModel.LINEAR);
287288
if (mr != null) {
@@ -302,7 +303,7 @@ protected void loadTextures(NucleusRenderer renderer, GLTF gltf, Material materi
302303
* @param gltf
303304
* @param texInfo
304305
* @param destFormat Optional destination image format, if null then same as source
305-
* @param colorMode If model is linear or srgb
306+
* @param colorModel If model is linear or srgb
306307
* @return The loaded texture object
307308
* @throws IOException
308309
*/

graphics-by-opengl-j2se/src/main/java/com/nucleus/texturing/BaseImageFactory.java

+42-17
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected void copyPixels(byte[] source, SourceFormat sourceFormat, BufferImage
197197
break;
198198
case RG:
199199
case LUMINANCE_ALPHA:
200-
copyPixels_4BYTE_ABGR_TO_RG(source, buffer, destination.getWidth(), destination.getHeight());
200+
copyPixels_4BYTE_ABGR_TO_GB(source, buffer, destination.getWidth(), destination.getHeight());
201201
break;
202202

203203
default:
@@ -219,6 +219,10 @@ protected void copyPixels(byte[] source, SourceFormat sourceFormat, BufferImage
219219
case RGB5_A1:
220220
copyPixels_4BYTE_RGBA_TO_RGB5551(source, buffer);
221221
break;
222+
case RG:
223+
case LUMINANCE_ALPHA:
224+
copyPixels_4BYTE_ARGB_TO_GB(source, buffer, destination.getWidth(), destination.getHeight());
225+
break;
222226
default:
223227
throw new IllegalArgumentException(
224228
ErrorMessage.NOT_IMPLEMENTED.message + destination.getFormat());
@@ -231,7 +235,7 @@ protected void copyPixels(byte[] source, SourceFormat sourceFormat, BufferImage
231235
break;
232236
case RG:
233237
case LUMINANCE_ALPHA:
234-
copyPixels_3BYTE_BGR_TO_RG(source, buffer, destination.getWidth(),
238+
copyPixels_3BYTE_BGR_TO_GB(source, buffer, destination.getWidth(),
235239
destination.getHeight());
236240
break;
237241
case RGBA:
@@ -263,7 +267,7 @@ protected void copyPixels(byte[] source, SourceFormat sourceFormat, BufferImage
263267
break;
264268
case RG:
265269
case LUMINANCE_ALPHA:
266-
copyPixels_3BYTE_BGR_TO_RG(source, buffer, destination.getWidth(),
270+
copyPixels_3BYTE_BGR_TO_GB(source, buffer, destination.getWidth(),
267271
destination.getHeight());
268272
break;
269273
default:
@@ -419,24 +423,24 @@ protected void copyPixels_3BYTE_BGR_TO_RGB(byte[] source, ByteBuffer destination
419423
}
420424

421425
/**
422-
* Copies the 3 byte BGR to 16 bit 2 elements, RG, GB or LA depending on destination format
426+
* Copies the 3 byte BGR to 16 bit 2 elements GB format
423427
*
424428
* @param source
425429
* @param destination
426430
* @param width
427431
* @param height
428432
*/
429-
protected void copyPixels_3BYTE_BGR_TO_RG(byte[] source, ByteBuffer destination, int width, int height) {
433+
protected void copyPixels_3BYTE_BGR_TO_GB(byte[] source, ByteBuffer destination, int width, int height) {
430434
int count = width * height;
431-
byte[] rg = new byte[count * 2];
432-
int length = rg.length;
435+
byte[] gb = new byte[count * 2];
436+
int length = gb.length;
433437
int sourceIndex = 0;
434438
for (int destIndex = 0; destIndex < length;) {
435-
rg[destIndex++] = source[sourceIndex + 1];
436-
rg[destIndex++] = source[sourceIndex];
439+
gb[destIndex++] = source[sourceIndex + 1];
440+
gb[destIndex++] = source[sourceIndex];
437441
sourceIndex += 3;
438442
}
439-
destination.put(rg, 0, rg.length);
443+
destination.put(gb, 0, gb.length);
440444
}
441445

442446
/**
@@ -480,24 +484,45 @@ protected void copyPixels_4BYTE_ABGR_TO_RGB5551(byte[] source, ByteBuffer destin
480484
}
481485

482486
/**
483-
* Copies the 4 byte ABGR to 16 bit 2 ELEMENTS, RG, GB or LA depending on destination texture format.
487+
* Copies the 4 byte ABGR to 16 bit 2 ELEMENTS GB format.
484488
*
485489
* @param source
486490
* @param destination
487491
* @param width
488492
* @param height
489493
*/
490-
protected void copyPixels_4BYTE_ABGR_TO_RG(byte[] source, ByteBuffer destination, int width, int height) {
494+
protected void copyPixels_4BYTE_ABGR_TO_GB(byte[] source, ByteBuffer destination, int width, int height) {
495+
int count = width * height;
496+
byte[] gb = new byte[count * 2];
497+
int length = gb.length;
498+
int sourceIndex = 0;
499+
for (int destIndex = 0; destIndex < length;) {
500+
gb[destIndex++] = source[sourceIndex + 1];
501+
gb[destIndex++] = source[sourceIndex + 2];
502+
sourceIndex += 4;
503+
}
504+
destination.put(gb, 0, gb.length);
505+
}
506+
507+
/**
508+
* Copies the 4 byte ARGB to 16 bit 2 ELEMENTS GB format.
509+
*
510+
* @param source
511+
* @param destination
512+
* @param width
513+
* @param height
514+
*/
515+
protected void copyPixels_4BYTE_ARGB_TO_GB(byte[] source, ByteBuffer destination, int width, int height) {
491516
int count = width * height;
492-
byte[] rg = new byte[count * 2];
493-
int length = rg.length;
517+
byte[] gb = new byte[count * 2];
518+
int length = gb.length;
494519
int sourceIndex = 0;
495520
for (int destIndex = 0; destIndex < length;) {
496-
rg[destIndex++] = source[sourceIndex + 2];
497-
rg[destIndex++] = source[sourceIndex + 1];
521+
gb[destIndex++] = source[sourceIndex + 2];
522+
gb[destIndex++] = source[sourceIndex + 3];
498523
sourceIndex += 4;
499524
}
500-
destination.put(rg, 0, rg.length);
525+
destination.put(gb, 0, gb.length);
501526
}
502527

503528
}

0 commit comments

Comments
 (0)