| 1 |
{%MainUnit castleglimages.pas} |
| 2 |
{ |
| 3 |
Copyright 2001-2023 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Part of CastleGLImages unit: packing helpers. } |
| 18 |
|
| 19 |
{$ifdef read_interface} |
| 20 |
|
| 21 |
{$ifdef read_interface_func} |
| 22 |
{ Save / restore OpenGL pixel store for unpacking / packing given TCastleImage. |
| 23 |
Before you pass this image to some OpenGL procedures |
| 24 |
(like glDrawPixels for unpacking, glReadPixels for packing), |
| 25 |
call BeforeXxx, and later call AfterXxx to restore original state. |
| 26 |
These will take care of setting / restoring pixel alignment. |
| 27 |
@groupBegin } |
| 28 |
procedure BeforeUnpackImage(const Image: TCastleImage); |
| 29 |
procedure AfterUnpackImage(const Image: TCastleImage); |
| 30 |
procedure BeforePackImage(const Image: TCastleImage); |
| 31 |
procedure AfterPackImage(const Image: TCastleImage); |
| 32 |
{ @groupEnd } |
| 33 |
{$endif read_interface_func} |
| 34 |
|
| 35 |
{$endif read_interface} |
| 36 |
|
| 37 |
{$ifdef read_implementation} |
| 38 |
|
| 39 |
const |
| 40 |
DefaultGLUnpackAlignment = 4; |
| 41 |
|
| 42 |
{ We assume here that nothing else changes glPixelStorei, |
| 43 |
so it's always Default*Alignment at start. |
| 44 |
We can avoid querying it with glGetInteger, |
| 45 |
or storing in per-context or global variable, this way. } |
| 46 |
|
| 47 |
procedure BeforeUnpackImage(const Image: TCastleImage); |
| 48 |
begin |
| 49 |
if (Image.Width * Image.PixelSize mod DefaultGLUnpackAlignment) <> 0 then |
| 50 |
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 51 |
end; |
| 52 |
|
| 53 |
procedure AfterUnpackImage(const Image: TCastleImage); |
| 54 |
begin |
| 55 |
if (Image.Width * Image.PixelSize mod DefaultGLUnpackAlignment) <> 0 then |
| 56 |
glPixelStorei(GL_UNPACK_ALIGNMENT, DefaultGLUnpackAlignment); |
| 57 |
end; |
| 58 |
|
| 59 |
const |
| 60 |
DefaultGLPackAlignment = 4; |
| 61 |
|
| 62 |
procedure BeforePackImage(const Image: TCastleImage); |
| 63 |
begin |
| 64 |
if (Image.Width * Image.PixelSize mod DefaultGLPackAlignment) <> 0 then |
| 65 |
glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 66 |
end; |
| 67 |
|
| 68 |
procedure AfterPackImage(const Image: TCastleImage); |
| 69 |
begin |
| 70 |
if (Image.Width * Image.PixelSize mod DefaultGLPackAlignment) <> 0 then |
| 71 |
glPixelStorei(GL_PACK_ALIGNMENT, DefaultGLPackAlignment); |
| 72 |
end; |
| 73 |
|
| 74 |
{$endif read_implementation} |