All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ktx.h
Go to the documentation of this file.
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
23 /*
24  * This file copyright (c) 2010 The Khronos Group, Inc.
25  */
26 
124 #define KTX_OPENGL_ES2 1
125 #include <stdio.h>
126 
127 #include "KHR/khrplatform.h"
128 
129 #if KTX_OPENGL
130  #ifdef _WIN32
131  #include <windows.h>
132  #define GL_APIENTRY APIENTRY
133  #endif
134 
135  #include <GL/gl.h>
136 
137  #define KTX_GLFUNCPTRS "gl_funcptrs.h"
138  /* Use runtime checks for sized internalformat support. */
139  #define KTX_SUPPORT_SIZEDINTERNALFORMATS 1
140 
141 #elif KTX_OPENGL_ES1
142 
143  #include <GLES/gl.h>
144  #include <GLES/glext.h>
145 
146  #define KTX_GLFUNCPTRS "gles1_funcptrs.h"
147  #define KTX_SUPPORT_SIZEDINTERNALFORMATS 0
148 
149 #elif KTX_OPENGL_ES2
150 
151  #include <GLES2/gl2.h>
152  #include <GLES2/gl2ext.h>
153 
154  #define KTX_GLFUNCPTRS "gles2_funcptrs.h"
155  #define KTX_SUPPORT_SIZEDINTERNALFORMATS 0
156 
157 #else
158 #error Please #define one of KTX_OPENGL, KTX_OPENGL_ES1, KTX_OPENGL_ES2 as 1
159 #endif
160 
161 
162 #ifdef __cplusplus
163 extern "C" {
164 #endif
165 
169 #define KTX_ORIENTATION_KEY "KTXorientation"
170 
173 #define KTX_ORIENTATION2_FMT "S=%c,T=%c"
174 
177 #define KTX_ORIENTATION3_FMT "S=%c,T=%c,R=%c"
178 
182 typedef enum KTX_error_code_t {
195 
199 typedef struct KTX_texture_info_t
200 {
207  khronos_uint32_t glType;
216  khronos_uint32_t glTypeSize;
223  khronos_uint32_t glFormat;
230  khronos_uint32_t glInternalFormat;
237  khronos_uint32_t glBaseInternalFormat;
239  khronos_uint32_t pixelWidth;
244  khronos_uint32_t pixelHeight;
249  khronos_uint32_t pixelDepth;
254  khronos_uint32_t numberOfArrayElements;
260  khronos_uint32_t numberOfFaces;
268  khronos_uint32_t numberOfMipmapLevels;
270 
271 
275 typedef struct KTX_image_info {
276  GLsizei size;
277  GLubyte* data;
279 
280 
284 typedef struct KTX_dimensions {
285  GLsizei width;
286  GLsizei height;
287  GLsizei depth;
289 
293 typedef void* KTX_hash_table;
294 
295 /* ktxLoadTextureF
296  *
297  * Loads a texture from a stdio FILE.
298  */
300 ktxLoadTextureF(FILE*, GLuint* pTexture, GLenum* pTarget,
301  KTX_dimensions* pDimensions, GLboolean* pIsMipmapped,
302  GLenum* pGlerror,
303  unsigned int* pKvdLen, unsigned char** ppKvd);
304 
305 /* ktxLoadTextureN
306  *
307  * Loads a texture from a KTX file on disk.
308  */
310 ktxLoadTextureN(const char* const filename, GLuint* pTexture, GLenum* pTarget,
311  KTX_dimensions* pDimensions, GLboolean* pIsMipmapped,
312  GLenum* pGlerror,
313  unsigned int* pKvdLen, unsigned char** ppKvd);
314 
315 /* ktxLoadTextureM
316  *
317  * Loads a texture from a KTX file in memory.
318  */
320 ktxLoadTextureM(const void* bytes, GLsizei size, GLuint* pTexture, GLenum* pTarget,
321  KTX_dimensions* pDimensions, GLboolean* pIsMipmapped,
322  GLenum* pGlerror,
323  unsigned int* pKvdLen, unsigned char** ppKvd);
324 
325 /* ktxWriteKTXF
326  *
327  * Writes a KTX file using supplied data.
328  */
330 ktxWriteKTXF(FILE*, const KTX_texture_info* imageInfo,
331  GLsizei bytesOfKeyValueData, const void* keyValueData,
332  GLuint numImages, KTX_image_info images[]);
333 
334 /* ktxWriteKTXN
335  *
336  * Writes a KTX file using supplied data.
337  */
339 ktxWriteKTXN(const char* dstname, const KTX_texture_info* imageInfo,
340  GLsizei bytesOfKeyValueData, const void* keyValueData,
341  GLuint numImages, KTX_image_info images[]);
342 
343 /* ktxHashTable_Create()
344  *
345  * Creates a key-value hash table
346  */
347 KTX_hash_table ktxHashTable_Create();
348 
349 /* ktxHashTable_Destroy()
350  *
351  * Destroys a key-value hash table
352  */
353 void ktxHashTable_Destroy(KTX_hash_table This);
354 
355 /* ktxHashTable_AddKVPair()
356  *
357  * Adds a key-value pair to a hash table.
358  */
360 ktxHashTable_AddKVPair(KTX_hash_table This, const char* key,
361  unsigned int valueLen, const void* value);
362 
363 
364 /* ktxHashTable_FindValue()
365  *
366  * Looks up a key and returns the value.
367  */
369 ktxHashTable_FindValue(KTX_hash_table This, const char* key,
370  unsigned int* pValueLen, void** pValue);
371 
372 
373 /* ktxHashTable_Serialize()
374  *
375  * Serializes the hash table to a block of memory suitable for
376  * writing to a KTX file.
377  */
379 ktxHashTable_Serialize(KTX_hash_table This, unsigned int* kvdLen, unsigned char** kvd);
380 
381 
382 /* ktxHashTable_Deserialize()
383  *
384  * Creates a hash table from the serialized data read from a
385  * a KTX file.
386  */
388 ktxHashTable_Deserialize(unsigned int kvdLen, void* kvd, KTX_hash_table* pKvt);
389 
390 
391 #ifdef __cplusplus
392 }
393 #endif
394