-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDevILUT.pas
337 lines (280 loc) · 13.7 KB
/
DevILUT.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
DevILUT - header file for the ImageLib utility toolkit
Direct translation of C header file ilut.h, a part of bindings for DevIL
library, into pascal.
More info about the DevIL library can be found at:
https://openil.sourceforge.net
Translation notes:
- macros were expanded in-place or implemented as normal functions
- some function parameters and structure fields were renamed (usually by
prepending the name with "a") because they collide with pascal reserved
words (eg. Type, File, ...)
- most inline comments present in header files were copied into the
translation at corresponding place
- DevILU requires DevIL (DevIL.dll) to be already loaded and initialized,
similarly DevILUT require both DevIL and DevILU to be already loaded
and initialized
- if you plan to use unicode version of the api, remember to also use
proper linked libraries (DLLs) builds
- DevILUT provides only GDI and OpenGL interfaces, as these are the only
ones exported by provided binaries (DLLs)
- some helper function are provided for conversions between usual pascal
types and types used in the API (booleans, strings)
- current translation is for Windows OS only (Linux is planned)
WARNING - the DevIL library is, as far as I know, NOT thread safe. You can
use it in any number of threads, but make sure it will never
execute any of its code concurrently (in more than one thread at
any given time).
Version 1.0.2 (2024-10-14)
Build against DevIL library version 1.8.0
Last change 2024-10-14
©2023-2024 František Milt
Contacts:
František Milt: [email protected]
Support:
If you find this code useful, please consider supporting its author(s) by
making a small donation using the following link(s):
https://www.paypal.me/FMilt
Changelog:
For detailed changelog and history please refer to this git repository:
github.com/TheLazyTomcat/Bnd.DevIL
Dependencies:
* AuxExceptions - github.com/TheLazyTomcat/Lib.AuxExceptions
AuxTypes - github.com/TheLazyTomcat/Lib.AuxTypes
DynLibUtils - github.com/TheLazyTomcat/Lib.DynLibUtils
StrRect - github.com/TheLazyTomcat/Lib.StrRect
Library AuxExceptions is required only when rebasing local exception classes
(see symbol DevIL_UseAuxExceptions for details).
Library AuxExceptions might also be required as an indirect dependency.
Indirect dependencies:
InterlockedOps - github.com/TheLazyTomcat/Lib.InterlockedOps
SimpleCPUID - github.com/TheLazyTomcat/Lib.SimpleCPUID
UInt64Utils - github.com/TheLazyTomcat/Lib.UInt64Utils
WindowsVersion - github.com/TheLazyTomcat/Lib.WindowsVersion
WinFileInfo - github.com/TheLazyTomcat/Lib.WinFileInfo
===============================================================================}
unit DevILUT;
{$INCLUDE '.\DevIL_defs.inc'}
interface
uses
{$IFDEF DevILUT_UseOpenGL}{$IFDEF FPC}GL,{$ELSE}OpenGL,{$ENDIF}{$ENDIF}
{$IFDEF DevILUT_UseWin32}Windows,{$ENDIF}
DevIL;
{===============================================================================
Constants
===============================================================================}
const
ILUT_VERSION = 180;
// Attribute Bits
ILUT_OPENGL_BIT = $00000001;
ILUT_D3D_BIT = $00000002;
ILUT_ALL_ATTRIB_BITS = $000FFFFF;
// Error Types
ILUT_INVALID_ENUM = $0501;
ILUT_OUT_OF_MEMORY = $0502;
ILUT_INVALID_VALUE = $0505;
ILUT_ILLEGAL_OPERATION = $0506;
ILUT_INVALID_PARAM = $0509;
ILUT_COULD_NOT_OPEN_FILE = $050A;
ILUT_STACK_OVERFLOW = $050E;
ILUT_STACK_UNDERFLOW = $050F;
ILUT_BAD_DIMENSIONS = $0511;
ILUT_NOT_SUPPORTED = $0550;
// State Definitions
ILUT_PALETTE_MODE = $0600;
ILUT_OPENGL_CONV = $0610;
ILUT_D3D_MIPLEVELS = $0620;
ILUT_MAXTEX_WIDTH = $0630;
ILUT_MAXTEX_HEIGHT = $0631;
ILUT_MAXTEX_DEPTH = $0632;
ILUT_GL_USE_S3TC = $0634;
ILUT_D3D_USE_DXTC = $0634;
ILUT_GL_GEN_S3TC = $0635;
ILUT_D3D_GEN_DXTC = $0635;
ILUT_S3TC_FORMAT = $0705;
ILUT_DXTC_FORMAT = $0705;
ILUT_D3D_POOL = $0706;
ILUT_D3D_ALPHA_KEY_COLOR = $0707;
ILUT_D3D_ALPHA_KEY_COLOUR = $0707;
ILUT_FORCE_INTEGER_FORMAT = $0636;
//This new state does automatic texture target detection
//if enabled. Currently, only cubemap detection is supported.
//if the current image is no cubemap, the 2d texture is chosen.
ILUT_GL_AUTODETECT_TEXTURE_TARGET = $0807;
// Values
ILUT_VERSION_NUM = IL_VERSION_NUM;
ILUT_VENDOR = IL_VENDOR;
// The different rendering api's...more to be added later?
ILUT_OPENGL = 0;
ILUT_ALLEGRO = 1;
ILUT_WIN32 = 2;
ILUT_DIRECT3D8 = 3;
ILUT_DIRECT3D9 = 4;
ILUT_X11 = 5;
ILUT_DIRECT3D10 = 6;
{===============================================================================
API functions (as procedural variables)
===============================================================================}
var
// ImageLib Utility Toolkit Functions
ilutDisable: Function(Mode: ILenum): ILboolean; stdcall = nil;
ilutEnable: Function(Mode: ILenum): ILboolean; stdcall = nil;
ilutGetBoolean: Function(Mode: ILenum): ILboolean; stdcall = nil;
ilutGetBooleanv: procedure(Mode: ILenum; Param: ILboolean_p); stdcall = nil;
ilutGetInteger: Function(Mode: ILenum): ILint; stdcall = nil;
ilutGetIntegerv: procedure(Mode: ILenum; Param: ILint_p); stdcall = nil;
ilutGetString: Function(StringName: ILenum): ILstring; stdcall = nil;
ilutInit: procedure; stdcall = nil;
ilutIsDisabled: Function(Mode: ILenum): ILboolean; stdcall = nil;
ilutIsEnabled: Function(Mode: ILenum): ILboolean; stdcall = nil;
ilutPopAttrib: procedure; stdcall = nil;
ilutPushAttrib: procedure(Bits: ILuint); stdcall = nil;
ilutSetInteger: procedure(Mode: ILenum; Param: ILint); stdcall = nil;
ilutRenderer: Function(Renderer: ILenum): ILboolean; stdcall = nil;
{$IFDEF DevILUT_UseOpenGL}
// ImageLib Utility Toolkit's OpenGL Functions
ilutGLBindTexImage: Function: GLuint; stdcall = nil;
ilutGLBindMipmaps: Function: GLuint; stdcall = nil;
ilutGLBuildMipmaps: Function: ILboolean; stdcall = nil;
ilutGLLoadImage: Function(FileName: ILstring): GLuint; stdcall = nil;
ilutGLScreen: Function: ILboolean; stdcall = nil;
ilutGLScreenie: Function: ILboolean; stdcall = nil;
ilutGLSaveImage: Function(FileName: ILstring; TexID: GLuint): ILboolean; stdcall = nil;
ilutGLSubTex2D: Function(TexID: GLuint; XOff,YOff: ILuint): ILboolean; stdcall = nil;
ilutGLSubTex3D: Function(TexID: GLuint; XOff,YOff,ZOff: ILuint): ILboolean; stdcall = nil;
ilutGLSetTex2D: Function(TexID: GLuint): ILboolean; stdcall = nil;
ilutGLSetTex3D: Function(TexID: GLuint): ILboolean; stdcall = nil;
ilutGLTexImage: Function(Level: GLuint): ILboolean; stdcall = nil;
ilutGLSetTex: Function(TexID: GLuint): ILboolean; stdcall = nil; // Deprecated - use ilutGLSetTex2D.
ilutGLSubTex: Function(TexID: GLuint; XOff,YOff: ILuint): ILboolean; stdcall = nil; // Use ilutGLSubTex2D.
{$ENDIF}
{$IFDEF DevILUT_UseWin32}
// ImageLib Utility Toolkit's Win32 GDI Functions
ilutConvertToHBitmap: Function(hDC: HDC): HBITMAP; stdcall = nil;
ilutConvertSliceToHBitmap: Function(hDC: HDC; slice: ILuint): HBITMAP; stdcall = nil;
ilutFreePaddedData: procedure(Data: ILubyte_p); stdcall = nil;
ilutGetBmpInfo: procedure(Info: PBITMAPINFO); stdcall = nil;
ilutGetHPal: Function: HPALETTE; stdcall = nil;
ilutGetPaddedData: Function: ILubyte_p; stdcall = nil;
ilutGetWinClipboard: Function: ILboolean; stdcall = nil;
ilutLoadResource: Function(hInst: HINST; ID: ILint; ResourceType: ILstring; aType: ILenum): ILboolean; stdcall = nil;
ilutSetHBitmap: Function(Bitmap: HBITMAP): ILboolean; stdcall = nil;
ilutSetHPal: Function(Pal: HPALETTE): ILboolean; stdcall = nil;
ilutSetWinClipboard: Function: ILboolean; stdcall = nil;
ilutWinLoadImage: Function(FileName: ILstring; hDC: HDC): HBITMAP; stdcall = nil;
ilutWinLoadUrl: Function(Url: ILstring): ILboolean; stdcall = nil;
ilutWinPrint: Function(XPos,YPos,Width,Height: ILuint; hDC: HDC): ILboolean; stdcall = nil;
ilutWinSaveImage: Function(FileName: ILstring; Bitmap: HBITMAP): ILboolean; stdcall = nil;
{$ENDIF}
{===============================================================================
Library loading - declaration
===============================================================================}
const
DevILUT_LibFileName = 'ILUT.dll';
Function DevILUT_Initialized: Boolean;
Function DevILUT_Initialize(const LibPath: String = DevIL_LibFileName; InitLib: Boolean = True): Boolean;
Function DevILUT_InitializeWithRenderer(const LibPath: String = DevIL_LibFileName;
Renderer: ILenum = {$IFDEF Windows}ILUT_WIN32{$ELSE}ILUT_OPENGL{$ENDIF}): Boolean;
procedure DevILUT_Finalize(FinalLib: Boolean = True);
implementation
uses
DynLibUtils;
{===============================================================================
Library loading - implementation
===============================================================================}
var
DevILUT_LibraryContext: TDLULibraryContext;
//------------------------------------------------------------------------------
Function DevILUT_Initialized: Boolean;
begin
Result := CheckLibrary(DevILUT_LibraryContext);
end;
//------------------------------------------------------------------------------
Function DevILUT_Initialize(const LibPath: String = DevIL_LibFileName; InitLib: Boolean = True): Boolean;
begin
Result := OpenLibraryAndResolveSymbols(LibPath,DevILUT_LibraryContext,[
Symbol(@@ilutDisable, 'ilutDisable'),
Symbol(@@ilutEnable, 'ilutEnable'),
Symbol(@@ilutGetBoolean, 'ilutGetBoolean'),
Symbol(@@ilutGetBooleanv,'ilutGetBooleanv'),
Symbol(@@ilutGetInteger, 'ilutGetInteger'),
Symbol(@@ilutGetIntegerv,'ilutGetIntegerv'),
Symbol(@@ilutGetString, 'ilutGetString'),
Symbol(@@ilutInit, 'ilutInit'),
Symbol(@@ilutIsDisabled, 'ilutIsDisabled'),
Symbol(@@ilutIsEnabled, 'ilutIsEnabled'),
Symbol(@@ilutPopAttrib, 'ilutPopAttrib'),
Symbol(@@ilutPushAttrib, 'ilutPushAttrib'),
Symbol(@@ilutSetInteger, 'ilutSetInteger'),
Symbol(@@ilutRenderer, 'ilutRenderer')
{$IFDEF DevILUT_UseOpenGL},
Symbol(@@ilutGLBindTexImage,'ilutGLBindTexImage'),
Symbol(@@ilutGLBindMipmaps, 'ilutGLBindMipmaps'),
Symbol(@@ilutGLBuildMipmaps,'ilutGLBuildMipmaps'),
Symbol(@@ilutGLLoadImage, 'ilutGLLoadImage'),
Symbol(@@ilutGLScreen, 'ilutGLScreen'),
Symbol(@@ilutGLScreenie, 'ilutGLScreenie'),
Symbol(@@ilutGLSaveImage, 'ilutGLSaveImage'),
{$IF Defined(Windows) and Defined(x86)}
Symbol(@@ilutGLSubTex2D, '_ilutGLSubTex2D@12'),
Symbol(@@ilutGLSubTex3D, '_ilutGLSubTex3D@16'),
Symbol(@@ilutGLSetTex2D, '_ilutGLSetTex2D@4'),
Symbol(@@ilutGLSetTex3D, '_ilutGLSetTex3D@4'),
{$ELSE}
Symbol(@@ilutGLSubTex2D, 'ilutGLSubTex2D'),
Symbol(@@ilutGLSubTex3D, 'ilutGLSubTex3D'),
Symbol(@@ilutGLSetTex2D, 'ilutGLSetTex2D'),
Symbol(@@ilutGLSetTex3D, 'ilutGLSetTex3D'),
{$IFEND}
Symbol(@@ilutGLTexImage, 'ilutGLTexImage'),
Symbol(@@ilutGLSetTex, 'ilutGLSetTex'),
Symbol(@@ilutGLSubTex, 'ilutGLSubTex')
{$ENDIF}
{$IFDEF DevILUT_UseWin32},
Symbol(@@ilutConvertToHBitmap, 'ilutConvertToHBitmap'),
Symbol(@@ilutConvertSliceToHBitmap,'ilutConvertSliceToHBitmap'),
Symbol(@@ilutFreePaddedData, 'ilutFreePaddedData'),
Symbol(@@ilutGetBmpInfo, 'ilutGetBmpInfo'),
Symbol(@@ilutGetHPal, 'ilutGetHPal'),
Symbol(@@ilutGetPaddedData, 'ilutGetPaddedData'),
Symbol(@@ilutGetWinClipboard, 'ilutGetWinClipboard'),
Symbol(@@ilutLoadResource, 'ilutLoadResource'),
Symbol(@@ilutSetHBitmap, 'ilutSetHBitmap'),
Symbol(@@ilutSetHPal, 'ilutSetHPal'),
Symbol(@@ilutSetWinClipboard, 'ilutSetWinClipboard'),
Symbol(@@ilutWinLoadImage, 'ilutWinLoadImage'),
Symbol(@@ilutWinLoadUrl, 'ilutWinLoadUrl'),
Symbol(@@ilutWinPrint, 'ilutWinPrint'),
Symbol(@@ilutWinSaveImage, 'ilutWinSaveImage')
{$ENDIF}
],[optExceptionOnFailure]) = 14 {$IFDEF DevILUT_UseOpenGL}+14{$ENDIF}{$IFDEF DevILUT_UseWin32}+15{$ENDIF};
// init
If Result and InitLib then
ilutInit;
end;
//------------------------------------------------------------------------------
Function DevILUT_InitializeWithRenderer(const LibPath: String = DevIL_LibFileName;
Renderer: ILenum = {$IFDEF Windows}ILUT_WIN32{$ELSE}ILUT_OPENGL{$ENDIF}): Boolean;
begin
If DevILUT_Initialize(LibPath,True) then
Result := ILBoolDecode(ilutRenderer(Renderer))
else
Result := False;
end;
//------------------------------------------------------------------------------
procedure DevILUT_Finalize(FinalLib: Boolean = True);
begin
If FinalLib then; // do nothing
CloseLibrary(DevILUT_LibraryContext);
end;
{===============================================================================
Global variables initialization
===============================================================================}
initialization
DevILUT_LibraryContext := DefaultLibraryContext;
end.