117 RETURN_IF_POINTER_NULL(psFormat);
128 glEnable(GL_TEXTURE_2D);
130 GLuint l_nTextureId = 0;
131 glGenTextures(1, &l_nTextureId);
133 GLenum l_nStatus = glGetError();
141 GLenum nPixelType = GL_UNSIGNED_BYTE;
142 GLenum nBitmapFormat = GL_RGB;
143 GLint nInternalFormat = GL_RGB;
147 auto bpp =
static_cast<int32_t
>(
m_sFormat.nBitsPerPixel);
148 auto fmt =
static_cast<int32_t
>(
m_sFormat.nPixelFormat);
150 LOG_ERROR(
"Unsupported pixel format %" PRIi32
" (%s) with %" PRIi32
" bits.", fmt, fmtStr, bpp);
151 RETURN_ERROR(ERR_NOT_SUPPORTED);
158 glBindTexture(GL_TEXTURE_2D, (GLuint)
m_hTexture);
160 l_nStatus = glGetError();
166 const void* pBitmap = oTextureBuffer.
GetBitmap();
167 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
169 nPixelType, pBitmap);
171 l_nStatus = glGetError();
172 if (l_nStatus != GL_NO_ERROR ||
m_hTexture == 0)
174 RETURN_ERROR(ERR_UNEXPECTED);
177 glDisable(GL_TEXTURE_2D);
191 glDeleteTextures(1, &l_nTextureId);
218 glEnable(GL_TEXTURE_2D);
219 glBindTexture(GL_TEXTURE_2D, (GLuint)
m_hTexture);
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
240 tResult
Copy(IImage* pImage)
242 RETURN_IF_POINTER_NULL(pImage);
243 RETURN_IF_POINTER_NULL(pImage->GetBitmap());
247 RETURN_ERROR(ERR_UNKNOWN);
252 RETURN_IF_FAILED(
Create(pImage->GetFormat()));
256 oImg.Attach(pImage->GetBitmap(), pImage->GetFormat(), pImage->GetPalette());
264 oImg = cImage(*pImage);
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);
273 for (
int y = 0; y < oImg.GetHeight(); ++y)
275 uint8_t
const* __restrict pSrc = pImage->GetBitmapLine(y);
276 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
278 for (
int x = 0; x < oImg.GetWidth(); ++x)
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));
297 for (
int y = 0; y < oImg.GetHeight(); ++y)
299 uint8_t
const* __restrict pSrc = pImage->GetBitmapLine(y);
300 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
302 for (
int x = 0; x < oImg.GetWidth(); ++x)
304 uint8_t
const a = *pSrc++;
305 uint8_t
const r = *pSrc++;
306 uint8_t
const g = *pSrc++;
307 uint8_t
const b = *pSrc++;
320 for (
int y = 0; y < oImg.GetHeight(); ++y)
322 uint8_t
const* __restrict pSrc = pImage->GetBitmapLine(y);
323 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
325 for (
int x = 0; x < oImg.GetWidth(); ++x)
327 uint8_t
const a = *pSrc++;
328 uint8_t
const b = *pSrc++;
329 uint8_t
const g = *pSrc++;
330 uint8_t
const r = *pSrc++;
343 for (
int y = 0; y < oImg.GetHeight(); ++y)
345 uint8_t
const* __restrict pSrc = pImage->GetBitmapLine(y);
346 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
348 for (
int x = 0; x < oImg.GetWidth(); ++x)
350 uint8_t
const r = *pSrc++;
351 uint8_t
const g = *pSrc++;
352 uint8_t
const b = *pSrc++;
366 for (
int y = 0; y < oImg.GetHeight(); ++y)
368 uint8_t
const* __restrict pSrc = pImage->GetBitmapLine(y);
369 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
371 for (
int x = 0; x < oImg.GetWidth(); ++x)
373 uint8_t
const b = *pSrc++;
374 uint8_t
const g = *pSrc++;
375 uint8_t
const r = *pSrc++;
390 for (
int y = 0; y < oImg.GetHeight(); ++y)
392 uint8_t
const* __restrict pSrc = pImage->GetBitmapLine(y);
393 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
395 for (
int x = 0; x < oImg.GetWidth(); ++x)
398 uint8_t
const r = *pSrc++;
399 uint8_t
const g = *pSrc++;
400 uint8_t
const b = *pSrc++;
414 for (
int y = 0; y < oImg.GetHeight(); ++y)
416 uint8_t
const* __restrict pSrc = pImage->GetBitmapLine(y);
417 uint8_t* __restrict pDst = oImg.GetBitmapLine(y);
419 for (
int x = 0; x < oImg.GetWidth(); ++x)
422 uint8_t
const b = *pSrc++;
423 uint8_t
const g = *pSrc++;
424 uint8_t
const r = *pSrc++;
433 GLenum nPixelType = GL_UNSIGNED_BYTE;
434 GLenum nBitmapFormat = GL_RGB;
435 GLint nInternalFormat = GL_RGB;
439 glBindTexture(GL_TEXTURE_2D, (GLuint)
m_hTexture);
445 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
447 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
m_sFormat.nWidth,
m_sFormat.nHeight, nBitmapFormat, nPixelType,
450 GLenum l_nStatus = glGetError();
451 if (l_nStatus != GL_NO_ERROR)
453 RETURN_ERROR(ERR_UNEXPECTED);
473 tInt GetPixelFormat()
const
478 tInt GetStride()
const
521 tVoid
Blit(tInt x, tInt y, tInt nWidth, tInt nHeight)
532 tInt x2 = x + nWidth;
533 tInt y2 = y + nHeight;
539 glGetFloatv(GL_CURRENT_COLOR, clTemp);
541 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
559 glColor4f(clTemp[0], clTemp[1], clTemp[2], clTemp[3]);
561 glDisable(GL_TEXTURE_2D);
574 GLenum* pBitmapFormat,
575 GLint* pBitmapFormatInternal)
577 RETURN_IF_POINTER_NULL_DESC(pBitmapInfo,
"No pBitmapInfo.");
579 GLenum oIntFmt = GL_RGB;
580 GLenum oBmpFmt = GL_RGB;
581 GLenum oPixFmt = GL_UNSIGNED_BYTE;
583 int32_t
const oPixelFormat =
static_cast<int32_t
>(pBitmapInfo->
nPixelFormat);
601 switch (oPixelFormat)
606 oIntFmt = GL_LUMINANCE;
607 oBmpFmt = GL_LUMINANCE;
608 oPixFmt = GL_UNSIGNED_INT;
668 oIntFmt = GL_LUMINANCE;
669 oBmpFmt = GL_LUMINANCE;
699 oIntFmt = GL_LUMINANCE;
700 oBmpFmt = GL_LUMINANCE;
701 oPixFmt = GL_UNSIGNED_SHORT;
708 oPixFmt = GL_UNSIGNED_SHORT_5_6_5_REV;
715 oPixFmt = GL_UNSIGNED_SHORT_5_6_5_REV;
718 case IImage::PF_BGR_565:
722 oPixFmt = GL_UNSIGNED_SHORT_5_6_5;
729 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
732 case IImage::PF_BGR_555:
736 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
743 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
750 oPixFmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
757 oPixFmt = GL_UNSIGNED_SHORT_5_5_5_1;
764 oPixFmt = GL_UNSIGNED_SHORT_5_5_5_1;
770 oIntFmt = GL_LUMINANCE;
771 oBmpFmt = GL_LUMINANCE;
776 oIntFmt = GL_LUMINANCE;
777 oBmpFmt = GL_LUMINANCE;
783 RETURN_ERROR_DESC(ERR_NOT_SUPPORTED,
"No support for PixelFormat %d",
int(oPixelFormat));
787 *pPixelType = oPixFmt;
788 *pBitmapFormat = oBmpFmt;
789 *pBitmapFormatInternal = oIntFmt;
800 return static_cast<ITexture*
>(
this);
virtual tInt GetPhysicalWidth() const =0
Gets the physical width of the texture (in byte).
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.
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.
tVoid Blit(tInt x, tInt y, tInt nWidth, tInt nHeight)
Blits a texture to the given rectangle.