ADTF Display Toolbox
Loading...
Searching...
No Matches
gltexture.h
Go to the documentation of this file.
1
7#pragma once
8#include <adtf_base.h>
11
12// Needed for static CalcOpenGLTextureFormat() param types!
13#if defined(_WIN32) || defined(WIN32)
14 #ifndef WIN32_LEAN_AND_MEAN
15 #define WIN32_LEAN_AND_MEAN
16 #endif
17 #ifndef NOMINMAX
18 #define NOMINMAX
19 #endif
20 #include <windows.h>
21 #ifdef GetObject
22 #undef GetObject
23 #endif
24 #include <gl/GL.h>
25#else
26 #include <GL/gl.h>
27#endif
28
29namespace adtf
30{
31
32namespace disptb
33{
34
35namespace graphicslib
36{
37
38namespace dengar
39{
40
41// Since OpenGL 1.2
42#ifndef GL_VERSION_1_2
43 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
44 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
45 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
46 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
47 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
48#endif
49
50#ifndef GL_UNSIGNED_SHORT_5_5_5_1
51 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
52#endif
53
54#ifdef TEXTURE_DONT_USE_BGRA_EXT
55 #define TEXTURE_FORMAT_24BPP GL_RGB
56 #define TEXTURE_FORMAT_32BPP GL_RGBA
57 #define TEXTURE_FORMAT_16BPP GL_RGB
58 #define TEXTURE_FORMAT_16BPPGREY GL_LUMINANCE
59 #define TEXTURE_FORMAT_8BPP GL_LUMINANCE
60#else
61 #define TEXTURE_FORMAT_24BPP GL_BGR_EXT
62 #define TEXTURE_FORMAT_32BPP GL_BGRA_EXT
63 #define TEXTURE_FORMAT_16BPP GL_BGR_EXT
64 #define TEXTURE_FORMAT_16BPPGREY GL_LUMINANCE
65 #define TEXTURE_FORMAT_8BPP GL_LUMINANCE
66#endif
67
68#ifndef GL_BGR
69 #define GL_BGR GL_BGR_EXT
70#endif
71
72#ifndef GL_BGRA
73 #define GL_BGRA GL_BGRA_EXT
74#endif
75
76typedef uint32_t GLenum;
77typedef int32_t GLint;
78
84class cGLTexture : public ITexture
85{
86protected:
87 tUInt m_hTexture;
92
93public:
94 cGLTexture()
95 {
96 m_hTexture = 0;
98
99 adtf::util::cMemoryBlock::MemSet(&m_sFormat, 0, sizeof(m_sFormat));
100 }
101
103 {
104 CleanUp();
105 }
106
113 tResult Create(const tBitmapFormat* psFormat, tInt nMode = 0)
114 {
115 CleanUp();
116
117 RETURN_IF_POINTER_NULL(psFormat);
118
119 if (nMode == 0)
120 {
122 }
123 else
124 {
125 m_nMode = (tTextureMode) nMode;
126 }
127
128 glEnable(GL_TEXTURE_2D);
129
130 GLuint l_nTextureId = 0;
131 glGenTextures(1, &l_nTextureId);
132
133 GLenum l_nStatus = glGetError();
134
135 m_hTexture = l_nTextureId;
136 m_nPhysicalWidth = cImage::GetNextPowerOfTwo(psFormat->nWidth);
137 m_nPhysicalHeight = cImage::GetNextPowerOfTwo(psFormat->nHeight);
138
139 adtf::util::cMemoryBlock::MemCopy(&m_sFormat, psFormat, sizeof(m_sFormat));
140
141 GLenum nPixelType = GL_UNSIGNED_BYTE;
142 GLenum nBitmapFormat = GL_RGB;
143 GLint nInternalFormat = GL_RGB;
144
145 if (IS_FAILED(CalcOpenGLTextureFormat(&m_sFormat, &nPixelType, &nBitmapFormat, &nInternalFormat)))
146 {
147 auto bpp = static_cast<int32_t>(m_sFormat.nBitsPerPixel);
148 auto fmt = static_cast<int32_t>(m_sFormat.nPixelFormat);
149 auto fmtStr = cImage::GetPixelFormatIdentifier(fmt);
150 LOG_ERROR("Unsupported pixel format %" PRIi32 " (%s) with %" PRIi32 " bits.", fmt, fmtStr, bpp);
151 RETURN_ERROR(ERR_NOT_SUPPORTED);
152 }
153
154 cImage oTextureBuffer;
155 oTextureBuffer.Create(m_nPhysicalWidth, m_nPhysicalHeight, m_sFormat.nBitsPerPixel, 0, 0,
156 m_sFormat.nPixelFormat);
157
158 glBindTexture(GL_TEXTURE_2D, (GLuint) m_hTexture);
159
160 l_nStatus = glGetError();
161
162 // Use unpack alignment appropiate to image format
163 tInt nAlignmentBytes = m_sFormat.nBytesPerLine - m_sFormat.nWidth * m_sFormat.nBitsPerPixel / 8;
164 glPixelStorei(GL_UNPACK_ALIGNMENT, (nAlignmentBytes != 0) ? cImage::m_nDefaultLineAlignment : 1);
165
166 const void* pBitmap = oTextureBuffer.GetBitmap();
167 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
168 glTexImage2D(GL_TEXTURE_2D, 0, nInternalFormat, m_nPhysicalWidth, m_nPhysicalHeight, 0, nBitmapFormat,
169 nPixelType, pBitmap);
170
171 l_nStatus = glGetError();
172 if (l_nStatus != GL_NO_ERROR || m_hTexture == 0)
173 {
174 RETURN_ERROR(ERR_UNEXPECTED);
175 }
176
177 glDisable(GL_TEXTURE_2D);
178
179 RETURN_NOERROR;
180 }
181
186 tResult CleanUp()
187 {
188 if (m_hTexture != 0)
189 {
190 GLuint l_nTextureId = (GLuint) m_hTexture;
191 glDeleteTextures(1, &l_nTextureId);
192 m_hTexture = 0;
193 }
194
195 adtf::util::cMemoryBlock::MemSet(&m_sFormat, 0, sizeof(m_sFormat));
196
197 RETURN_NOERROR;
198 }
199
200public:
202 tResult Release()
203 {
204 CleanUp();
205
206 delete this;
207
208 RETURN_NOERROR;
209 }
210
211 tVoid MakeCurrent()
212 {
213 if (m_hTexture == 0)
214 {
215 return;
216 }
217
218 glEnable(GL_TEXTURE_2D);
219 glBindTexture(GL_TEXTURE_2D, (GLuint) m_hTexture);
220
222 {
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
225 }
226 else
227 {
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
230 }
231 }
232
233 tResult SetMode(tInt nMode)
234 {
235 m_nMode = (tTextureMode) nMode;
236
237 RETURN_NOERROR;
238 }
239
240 tResult Copy(IImage* pImage)
241 {
242 RETURN_IF_POINTER_NULL(pImage);
243 RETURN_IF_POINTER_NULL(pImage->GetBitmap());
244
245 if (m_hTexture == 0)
246 {
247 RETURN_ERROR(ERR_UNKNOWN);
248 }
249
250 if (!IsCompatible(pImage->GetFormat()))
251 {
252 RETURN_IF_FAILED(Create(pImage->GetFormat()));
253 }
254
255 cImage oImg;
256 oImg.Attach(pImage->GetBitmap(), pImage->GetFormat(), pImage->GetPalette());
257
258 // Converts any unsupported GPU format to a supported one.
259 // Convert before any GPU upload on CPU side.
260 // Makes temporary copies due to review remarks.
261 if (pImage->GetPixelFormat() == IImage::PF_YUV420P_888)
262 {
263 // Format not supported by GPU. Convert to RGB.
264 oImg = cImage(*pImage);
265 oImg.ChangePixelFormat(IImage::PF_RGB_888);
266 }
267 else if (pImage->GetPixelFormat() == IImage::PF_GREYSCALE_24)
268 {
269 // Format not supported by GPU. Convert to RGB
270 oImg.Create(pImage->GetWidth(), pImage->GetHeight(), 24, 0, nullptr, IImage::PF_RGB_888);
271 constexpr float grey24_to_byte = 255.0f / float((256 * 256 * 256) - 1);
272
273 for (int y = 0; y < oImg.GetHeight(); ++y)
274 {
275 uint8_t const* __restrict pSrc = pImage->GetBitmapLine(y);
276 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
277
278 for (int x = 0; x < oImg.GetWidth(); ++x)
279 {
280 uint32_t const r = *pSrc++;
281 uint32_t const g = *pSrc++;
282 uint32_t const b = *pSrc++;
283 uint32_t const grey24 = (b << 16) | (g << 8) | r;
284 int32_t const igrey24 = static_cast<int32_t>(static_cast<float>(grey24) * grey24_to_byte);
285 uint8_t const grey8 = static_cast<uint8_t>(std::clamp(igrey24, 0, 255));
286 *pDst++ = grey8;
287 *pDst++ = grey8;
288 *pDst++ = grey8;
289 }
290 }
291 }
292 else if (pImage->GetPixelFormat() == IImage::PF_ARGB_8888)
293 {
294 // Format not supported by GPU. Convert to RGBA.
295 oImg.Create(pImage->GetWidth(), pImage->GetHeight(), 32, 0, nullptr, IImage::PF_RGBA_8888);
296
297 for (int y = 0; y < oImg.GetHeight(); ++y)
298 {
299 uint8_t const* __restrict pSrc = pImage->GetBitmapLine(y);
300 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
301
302 for (int x = 0; x < oImg.GetWidth(); ++x)
303 {
304 uint8_t const a = *pSrc++;
305 uint8_t const r = *pSrc++;
306 uint8_t const g = *pSrc++;
307 uint8_t const b = *pSrc++;
308 *pDst++ = r;
309 *pDst++ = g;
310 *pDst++ = b;
311 *pDst++ = a;
312 }
313 }
314 }
315 else if (pImage->GetPixelFormat() == IImage::PF_ABGR_8888)
316 {
317 // Format not supported by GPU. Convert to RGBA.
318 oImg.Create(pImage->GetWidth(), pImage->GetHeight(), 32, 0, nullptr, IImage::PF_RGBA_8888);
319
320 for (int y = 0; y < oImg.GetHeight(); ++y)
321 {
322 uint8_t const* __restrict pSrc = pImage->GetBitmapLine(y);
323 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
324
325 for (int x = 0; x < oImg.GetWidth(); ++x)
326 {
327 uint8_t const a = *pSrc++;
328 uint8_t const b = *pSrc++;
329 uint8_t const g = *pSrc++;
330 uint8_t const r = *pSrc++;
331 *pDst++ = r;
332 *pDst++ = g;
333 *pDst++ = b;
334 *pDst++ = a;
335 }
336 }
337 }
338 else if (pImage->GetPixelFormat() == IImage::PF_RGBx_8888)
339 {
340 // Format RGBA supported by GPU but needs opaque alpha channel.
341 oImg.Create(pImage->GetWidth(), pImage->GetHeight(), 32, 0, nullptr, IImage::PF_RGBA_8888);
342
343 for (int y = 0; y < oImg.GetHeight(); ++y)
344 {
345 uint8_t const* __restrict pSrc = pImage->GetBitmapLine(y);
346 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
347
348 for (int x = 0; x < oImg.GetWidth(); ++x)
349 {
350 uint8_t const r = *pSrc++;
351 uint8_t const g = *pSrc++;
352 uint8_t const b = *pSrc++;
353 pSrc++;
354 *pDst++ = r;
355 *pDst++ = g;
356 *pDst++ = b;
357 *pDst++ = 255;
358 }
359 }
360 }
361 else if (pImage->GetPixelFormat() == IImage::PF_BGRx_8888)
362 {
363 // Format BGRA supported by GPU but needs opaque alpha channel.
364 oImg.Create(pImage->GetWidth(), pImage->GetHeight(), 32, 0, nullptr, IImage::PF_BGRA_8888);
365
366 for (int y = 0; y < oImg.GetHeight(); ++y)
367 {
368 uint8_t const* __restrict pSrc = pImage->GetBitmapLine(y);
369 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
370
371 for (int x = 0; x < oImg.GetWidth(); ++x)
372 {
373 uint8_t const b = *pSrc++;
374 uint8_t const g = *pSrc++;
375 uint8_t const r = *pSrc++;
376 pSrc++;
377 *pDst++ = b;
378 *pDst++ = g;
379 *pDst++ = r;
380 *pDst++ = 255;
381 }
382 }
383 }
384 else if (pImage->GetPixelFormat() == IImage::PF_xRGB_8888)
385 {
386 // Format not supported by GPU.
387 // Convert to RGBA and make opaque alpha channel in one converter
388 oImg.Create(pImage->GetWidth(), pImage->GetHeight(), 32, 0, nullptr, IImage::PF_RGBA_8888);
389
390 for (int y = 0; y < oImg.GetHeight(); ++y)
391 {
392 uint8_t const* __restrict pSrc = pImage->GetBitmapLine(y);
393 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
394
395 for (int x = 0; x < oImg.GetWidth(); ++x)
396 {
397 pSrc++;
398 uint8_t const r = *pSrc++;
399 uint8_t const g = *pSrc++;
400 uint8_t const b = *pSrc++;
401 *pDst++ = r;
402 *pDst++ = g;
403 *pDst++ = b;
404 *pDst++ = 255;
405 }
406 }
407 }
408 else if (pImage->GetPixelFormat() == cImage::PF_xBGR_8888)
409 {
410 // Format not supported by GPU.
411 // Convert to RGBA and make opaque alpha channel in one converter
412 oImg.Create(pImage->GetWidth(), pImage->GetHeight(), 32, 0, nullptr, IImage::PF_RGBA_8888);
413
414 for (int y = 0; y < oImg.GetHeight(); ++y)
415 {
416 uint8_t const* __restrict pSrc = pImage->GetBitmapLine(y);
417 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
418
419 for (int x = 0; x < oImg.GetWidth(); ++x)
420 {
421 pSrc++;
422 uint8_t const b = *pSrc++;
423 uint8_t const g = *pSrc++;
424 uint8_t const r = *pSrc++;
425 *pDst++ = r;
426 *pDst++ = g;
427 *pDst++ = b;
428 *pDst++ = 255;
429 }
430 }
431 }
432
433 GLenum nPixelType = GL_UNSIGNED_BYTE;
434 GLenum nBitmapFormat = GL_RGB;
435 GLint nInternalFormat = GL_RGB;
436
437 RETURN_IF_FAILED(CalcOpenGLTextureFormat(&m_sFormat, &nPixelType, &nBitmapFormat, &nInternalFormat));
438
439 glBindTexture(GL_TEXTURE_2D, (GLuint) m_hTexture);
440
441 // Use unpack alignment appropriate to image format
442 tInt nAlignmentBytes = m_sFormat.nBytesPerLine - m_sFormat.nWidth * m_sFormat.nBitsPerPixel / 8;
443 glPixelStorei(GL_UNPACK_ALIGNMENT, (nAlignmentBytes != 0) ? cImage::m_nDefaultLineAlignment : 1);
444
445 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
446
447 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_sFormat.nWidth, m_sFormat.nHeight, nBitmapFormat, nPixelType,
448 oImg.GetBitmap());
449
450 GLenum l_nStatus = glGetError();
451 if (l_nStatus != GL_NO_ERROR)
452 {
453 RETURN_ERROR(ERR_UNEXPECTED);
454 }
455 RETURN_NOERROR;
456 }
457
458 tInt GetWidth() const
459 {
460 return m_sFormat.nWidth;
461 }
462
463 tInt GetHeight() const
464 {
465 return m_sFormat.nHeight;
466 }
467
468 tInt GetBitsPerPixel() const
469 {
470 return m_sFormat.nBitsPerPixel;
471 }
472
473 tInt GetPixelFormat() const
474 {
475 return m_sFormat.nPixelFormat;
476 }
477
478 tInt GetStride() const
479 {
480 return m_sFormat.nBytesPerLine;
481 }
482
483 tInt GetPhysicalWidth() const
484 {
485 return m_nPhysicalWidth;
486 }
487
488 tInt GetPhysicalHeight() const
489 {
490 return m_nPhysicalHeight;
491 }
493
494public:
500 tBool IsCompatible(const tBitmapFormat* psFormat)
501 {
502 if (m_sFormat.nWidth != psFormat->nWidth || m_sFormat.nHeight != psFormat->nHeight ||
503 m_sFormat.nBitsPerPixel != psFormat->nBitsPerPixel || m_sFormat.nPaletteSize != psFormat->nPaletteSize)
504 {
505 return tFalse;
506 }
507
508 return tTrue;
509 }
510
521 tVoid Blit(tInt x, tInt y, tInt nWidth, tInt nHeight)
522 {
523 if (m_hTexture == 0)
524 {
525 return;
526 }
527
528 MakeCurrent();
529
530 tInt x1 = x;
531 tInt y1 = y;
532 tInt x2 = x + nWidth;
533 tInt y2 = y + nHeight;
534
535 tFloat64 u = (tFloat64) m_sFormat.nWidth / (tFloat64) m_nPhysicalWidth;
536 tFloat64 v = (tFloat64) m_sFormat.nHeight / (tFloat64) m_nPhysicalHeight;
537
538 tFloat32 clTemp[4];
539 glGetFloatv(GL_CURRENT_COLOR, clTemp);
540
541 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
542
543 glBegin(GL_QUADS);
544
545 glTexCoord2d(0, v);
546 glVertex2i(x1, y2);
547
548 glTexCoord2d(0, 0);
549 glVertex2i(x1, y1);
550
551 glTexCoord2d(u, 0);
552 glVertex2i(x2, y1);
553
554 glTexCoord2d(u, v);
555 glVertex2i(x2, y2);
556
557 glEnd();
558
559 glColor4f(clTemp[0], clTemp[1], clTemp[2], clTemp[3]);
560
561 glDisable(GL_TEXTURE_2D);
562 }
563
572 static tResult CalcOpenGLTextureFormat(const tBitmapFormat* pBitmapInfo,
573 GLenum* pPixelType,
574 GLenum* pBitmapFormat,
575 GLint* pBitmapFormatInternal)
576 {
577 RETURN_IF_POINTER_NULL_DESC(pBitmapInfo, "No pBitmapInfo.");
578
579 GLenum oIntFmt = GL_RGB;
580 GLenum oBmpFmt = GL_RGB;
581 GLenum oPixFmt = GL_UNSIGNED_BYTE;
582
583 int32_t const oPixelFormat = static_cast<int32_t>(pBitmapInfo->nPixelFormat);
584
585 // Reference 1:
586 // https://afrantzis.com/pixel-format-guide/opengl.html
587 // Beware: The paragraph about about 32-bit has errors, see "packed" section.
588 // Has 2 nice sentences about RGB_565.
589
590 // Reference 2:
591 // https://www.mvtec.com/doc/halcon/13/en/gen_image_interleaved.html
592 // Beware: Looks nice but who knows actually.
593
594 // Benni Defintions:
595 //
596 // A word like 0bBBBBBGGGGGGRRRRR is little endian
597 // meaning byte[0] is 0bGGGRRRRR and byte[1] is 0bBBBBBGGG
598 // cImage::Convert() seems to swap byte0 and byte1 for 16-bit formats!
599 // This still needs investigation. But i take a correct render as reference now.
600
601 switch (oPixelFormat)
602 {
603 // 32-Bit:
605 {
606 oIntFmt = GL_LUMINANCE;
607 oBmpFmt = GL_LUMINANCE;
608 oPixFmt = GL_UNSIGNED_INT;
609 break;
610 } // Supported by GPU.
611 case IImage::PF_32BIT:
612 {
613 oIntFmt = GL_RGBA;
614 oBmpFmt = GL_RGBA;
615 break;
616 } // Interpreted as RGBA_8888
618 {
619 oIntFmt = GL_RGBA;
620 oBmpFmt = GL_RGBA;
621 break;
622 } // = 0xAABBGGRR. Supported by GPU
624 {
625 oIntFmt = GL_RGBA;
626 oBmpFmt = GL_BGRA;
627 break;
628 } // = 0xAARRGGBB. Supported by GPU
630 {
631 oIntFmt = GL_RGBA;
632 oBmpFmt = GL_RGBA;
633 break;
634 } // = 0xBBGGRRAA. Converted to RGBA_8888.
636 {
637 oIntFmt = GL_RGBA;
638 oBmpFmt = GL_RGBA;
639 break;
640 } // = 0xRRGGBBAA. Converted to RGBA_8888.
642 {
643 oIntFmt = GL_RGBA;
644 oBmpFmt = GL_RGBA;
645 break;
646 } // = 0xFFBBGGRR. Copied and alpha set to 255 (opaque)
648 {
649 oIntFmt = GL_RGBA;
650 oBmpFmt = GL_BGRA;
651 break;
652 } // = 0xFFRRGGBB. Copied and alpha set to 255 (opaque)
654 {
655 oIntFmt = GL_RGBA;
656 oBmpFmt = GL_RGBA;
657 break;
658 } // = 0xBBGGRRFF. Converted to RGBA_8888 and alpha set to 255 (opaque)
660 {
661 oIntFmt = GL_RGBA;
662 oBmpFmt = GL_RGBA;
663 break;
664 } // = 0xRRGGBBAA. Converted to RGBA_8888 and alpha set to 255 (opaque)
665 // 24-Bit:
667 {
668 oIntFmt = GL_LUMINANCE;
669 oBmpFmt = GL_LUMINANCE;
670 break;
671 } // Supported by GPU.
672 case IImage::PF_24BIT:
673 {
674 oIntFmt = GL_RGB;
675 oBmpFmt = GL_RGB;
676 break;
677 } // Interpreted as RGB_888
679 {
680 oIntFmt = GL_RGB;
681 oBmpFmt = GL_RGB;
682 break;
683 } // = 0xAABBGGRR. Supported by GPU
685 {
686 oIntFmt = GL_RGB;
687 oBmpFmt = GL_BGR;
688 break;
689 } // = 0xAARRGGBB. Supported by GPU
691 {
692 oIntFmt = GL_RGB;
693 oBmpFmt = GL_RGB;
694 break;
695 } // Converted to RGB_888
696 // 16-Bit:
698 {
699 oIntFmt = GL_LUMINANCE;
700 oBmpFmt = GL_LUMINANCE;
701 oPixFmt = GL_UNSIGNED_SHORT;
702 break;
703 } // Supported by GPU.
704 case IImage::PF_16BIT:
705 {
706 oIntFmt = GL_RGB;
707 oBmpFmt = GL_RGB;
708 oPixFmt = GL_UNSIGNED_SHORT_5_6_5_REV;
709 break;
710 } // Interpreted as RGB_565
712 {
713 oIntFmt = GL_RGB;
714 oBmpFmt = GL_RGB;
715 oPixFmt = GL_UNSIGNED_SHORT_5_6_5_REV;
716 break;
717 } // = 0bBBBBBGGGGGGRRRRR. Supported by GPU. Still need to check img.Convert()!
718 case IImage::PF_BGR_565:
719 {
720 oIntFmt = GL_RGB;
721 oBmpFmt = GL_RGB;
722 oPixFmt = GL_UNSIGNED_SHORT_5_6_5;
723 break;
724 } // = 0bRRRRRGGGGGGBBBBB. Supported by GPU. GL_BGR not working! Still need to check img.Convert()!
726 {
727 oIntFmt = GL_RGBA;
728 oBmpFmt = GL_RGBA;
729 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
730 break;
731 } // = 0b1BBBBBGGGGGRRRRR. Supported by GPU.
732 case IImage::PF_BGR_555:
733 {
734 oIntFmt = GL_RGBA;
735 oBmpFmt = GL_BGRA;
736 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
737 break;
738 } // = 0b1RRRRRGGGGGBBBBB. Supported by GPU.
740 {
741 oIntFmt = GL_RGBA;
742 oBmpFmt = GL_RGBA;
743 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
744 break;
745 } // = 0bABBBBBGGGGGRRRRR. Supported by GPU.
747 {
748 oIntFmt = GL_RGBA;
749 oBmpFmt = GL_BGRA;
750 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
751 break;
752 } // = 0bARRRRRGGGGGBBBBB. Supported by GPU.
754 {
755 oIntFmt = GL_RGBA;
756 oBmpFmt = GL_BGRA;
757 oPixFmt = GL_UNSIGNED_SHORT_5_5_5_1;
758 break;
759 } // = 0bBBBBBGGGGGRRRRRA. Supported by GPU.
761 {
762 oIntFmt = GL_RGBA;
763 oBmpFmt = GL_RGBA;
764 oPixFmt = GL_UNSIGNED_SHORT_5_5_5_1;
765 break;
766 } // = 0bRRRRRGGGGGBBBBBA. Supported by GPU.
767 // 8-Bit:
769 {
770 oIntFmt = GL_LUMINANCE;
771 oBmpFmt = GL_LUMINANCE;
772 break;
773 } // Supported by GPU.
774 case IImage::PF_8BIT:
775 {
776 oIntFmt = GL_LUMINANCE;
777 oBmpFmt = GL_LUMINANCE;
778 break;
779 } // Interpreted as GREYSCALE_8.
780 // Unsupported:
781 default:
782 {
783 RETURN_ERROR_DESC(ERR_NOT_SUPPORTED, "No support for PixelFormat %d", int(oPixelFormat));
784 }
785 }
786
787 *pPixelType = oPixFmt;
788 *pBitmapFormat = oBmpFmt;
789 *pBitmapFormatInternal = oIntFmt;
790 RETURN_NOERROR;
791 }
792
798 explicit operator ITexture*()
799 {
800 return static_cast<ITexture*>(this);
801 }
802};
803
804} // namespace dengar
805
806using dengar::cGLTexture;
807
808} // namespace graphicslib
809
810} // namespace disptb
811
812} // namespace adtf
@ PF_BGRA_5551
16 bit BGRA (R: 5 bit, G: 5 bit, B: 5 bit, Alpha:1bit)
Definition image_intf.h:152
@ PF_32BIT
32 bit This definition is a placeholder a 32 Bit format, bitorder is undefined.
Definition image_intf.h:117
@ PF_RGB_888
24 bit RGB (R: 8 bit, G: 8 bit, B: 8 bit) - default format for 24 bpp
Definition image_intf.h:111
@ PF_YUV420P_888
24 bit YUV (Y: 8 bit, U: 8 bit, V: 8 bit) - Y = luminance, U+V = chrominance If using this format in ...
Definition image_intf.h:134
@ PF_16BIT
16 bit This definition is a placeholder a 16 Bit format, bitorder is undefined.
Definition image_intf.h:67
@ PF_RGBA_8888
32 bit RGBA (R: 8 bit, G: 8 bit, B: 8 bit, A: 8 bit) with alpha value - default format for 32 bpp
Definition image_intf.h:123
@ PF_RGB_555
15 bit RGB (R: 5 bit, G: 5 bit, B: 5 bit) - default format for 16 bpp
Definition image_intf.h:88
@ PF_xRGB_8888
32 bit aligned memory with only 24 Bit valid RGB data. A=255.
Definition image_intf.h:137
@ PF_RGB_565
16 bit RGB (R: 5 bit, G: 6 bit, B: 5 bit)
Definition image_intf.h:90
@ PF_BGRA_8888
32 bit BGRA (B: 8 bit, G: 8 bit, R: 8 bit, A: 8 bit) with alpha value - inverted RGB + A
Definition image_intf.h:125
@ PF_ARGB_1555
16 bit ARGB (R: 5 bit, G: 5 bit, B: 5 bit, Alpha:1bit)
Definition image_intf.h:146
@ PF_24BIT
24 bit This definition is a placeholder a 24 Bit format, bitorder is undefined.
Definition image_intf.h:104
@ PF_ABGR_1555
16 bit ABGR (R: 5 bit, G: 5 bit, B: 5 bit, Alpha:1bit)
Definition image_intf.h:150
@ PF_BGRx_8888
32 bit aligned memory with only 24 Bit valid RGB data. A=255.
Definition image_intf.h:143
@ PF_RGBx_8888
32 bit aligned memory with only 24 Bit valid RGB data. A=255.
Definition image_intf.h:141
@ PF_ARGB_8888
32 bit ARGB (A: 8 bit, R: 8 bit, G: 8 bit, B: 8 bit) with alpha value
Definition image_intf.h:119
@ PF_ABGR_8888
32 bit ABGR (A: 8 bit, B: 8 bit, G: 8 bit, R: 8 bit) with alpha value - inverted RGBA
Definition image_intf.h:121
@ PF_BGR_888
24 bit BGR (B: 8 bit, G: 8 bit, R: 8 bit) - inverted RGB
Definition image_intf.h:113
@ PF_GREYSCALE_8
8 bit greyscale - default format for 8 bpp
Definition image_intf.h:61
@ PF_xBGR_8888
32 bit aligned memory with only 24 Bit valid RGB data. A=255.
Definition image_intf.h:139
@ PF_RGBA_5551
16 bit RGBA (R: 5 bit, G: 5 bit, B: 5 bit, Alpha:1bit)
Definition image_intf.h:148
The interface for common texture handling.
virtual tInt GetPhysicalWidth() const =0
Gets the physical width of the texture (in byte).
virtual tResult Release()=0
The Function releases the Texture.
virtual tVoid MakeCurrent()=0
Sets this texture as the current texture.
virtual tInt GetWidth() const =0
Gets the width of a texture (in pixel).
virtual tInt GetPhysicalHeight() const =0
Gets the physical height of the texture (in byte).
virtual tResult SetMode(tInt nMode)=0
Set the Mode shown in tTextureMode.
tTextureMode
The enumeration shows the texture modes.
virtual tResult Copy(IImage *pSource)=0
Fills the texture using a IImage.
virtual tInt GetBitsPerPixel() const =0
Gets the number of bits per line of a texture.
virtual tInt GetHeight() const =0
Gets the height of a texture (in pixel).
static tResult CalcOpenGLTextureFormat(const tBitmapFormat *pBitmapInfo, GLenum *pPixelType, GLenum *pBitmapFormat, GLint *pBitmapFormatInternal)
Calculates an OpenGL texture format based on a bitmap format.
Definition gltexture.h:572
tBool IsCompatible(const tBitmapFormat *psFormat)
Definition gltexture.h:500
tResult Create(const tBitmapFormat *psFormat, tInt nMode=0)
Definition gltexture.h:113
tVoid Blit(tInt x, tInt y, tInt nWidth, tInt nHeight)
Blits a texture to the given rectangle.
Definition gltexture.h:521
Image and bitmap handling.
Definition image.h:108
static tInt m_nDefaultLineAlignment
the default line alignment, currently power of 2
Definition image.h:111
static tChar const * GetPixelFormatIdentifier(const tInt nImage)
Returns the image format as string (enum to string)
Definition image.h:2666
tResult Create(tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine=0, const tUInt8 *pBitmap=nullptr, tInt nPixelFormat=0)
Creates a new image.
Definition image.h:186
tUInt8 * GetBitmap() const
Returns a pointer to the raw data.
Definition image.h:897
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Namespace for functionality provided by the Display Toolbox.
Main namespace.
Struct to specifie a bitmap.
tInt32 nWidth
Specifies the width (in pixels) of the image.
tInt16 nBitsPerPixel
Specifies the number of bits used to represent the color of a single pixel.
tInt32 nHeight
Specifies the width (in pixels) of the image.
tInt16 nPixelFormat
Pixel format specified in tPixelFormat. More information ca be found at.
tInt32 nPaletteSize
Size of colour palette.