doc-tex.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. devil1tex.h / devil1tex.c
  2. Handles texture packages.
  3. File Format
  4. Texture packags can be identified with a string "\0 2 3 T" as a starting
  5. tag.
  6. Functions
  7. All functions are static but exposed by a function pointer in a constant
  8. struct called DEVIL1TEX. For example, clients call functions using
  9. DEVIL1TEX.printheader(...);
  10. void printheader(struct TexturePack*);
  11. Prints the attributes and values of a header to standard output.
  12. input: pointer to a TexturePack struct.
  13. void printbatchdesc(struct TextureBatchDescriptor*);
  14. Prints the attributes and values if a TextureBatchDescriptor to
  15. standard output.
  16. bool getheader(struct TexturePack**, const char*);
  17. Retrieves the header for a texture package.
  18. input:
  19. Pointer to a pointer of TexturePack.
  20. This is a pass by reference of a pointer to the function.
  21. The pointer to TexturePack may be NULL and will be set to point to
  22. a region in the buffer.
  23. const char*, the buffer containing the whole texture pack file.
  24. Can not be NULL.
  25. bool getbatchdesc(struct TextureBatchDescriptor**,
  26. unsigned int,
  27. const char *,
  28. unsigned int);
  29. Retrieves the i-th TextureBatchDescriptor from a buffer.
  30. input:
  31. Pointer to a pointer of TextureBatchDescriptor.
  32. This is pass by reference of a pointer to the function.
  33. The pointer to TextureBatchDescriptor can be NULL and will be
  34. set to point to a region in the const char*.
  35. unsigned int, the i-th instance of a TextureBatchDescriptor in
  36. the const char*.
  37. const char*, the buffer containing the whole texture pack file.
  38. unsigned int, the size of the buffer.
  39. output:
  40. true when successfully retrieving a pointer to
  41. TextureBatchDescriptor.
  42. false when unsuccesful in retrieving a pointer to
  43. TextureBatchDescriptor; failed checks against segmentation
  44. faults.
  45. When const char* (buffer) is NULL.
  46. When the location of the TextureBatchDescriptor will exceed
  47. the size of a buffer.
  48. bool getbatch(struct TextureBatch**,
  49. unsigned int,
  50. const char*
  51. unsigned int);
  52. Retrieves i-th instance of a TextureBatch from a buffer.
  53. input:
  54. Pointer to a pointer of TextureBatch.
  55. This is pass by reference of a pointer to the function.
  56. The pointer to a TextureBatch can be NULL and will be set to
  57. point to a region in the const char*.
  58. unsigned int, the i-th instance of a TextureBatch in the
  59. const char*.
  60. const char*, the buffer containing the whole texture pack file.
  61. unsigned int, the size of the buffer.
  62. output:
  63. true on success.
  64. false when failing checks against segmentation faults.
  65. When const char* is NULL.
  66. When the location of the Texture Batch will exceed the size
  67. of the buffer.
  68. bool gettextures(struct Texture*,
  69. unsigned int,
  70. const char*,
  71. unsigned int);
  72. Retrieves textures of the i-th batch from a buffer.
  73. input:
  74. Pointer to Texture. This can be an array of Textures.
  75. This parameter can not be NULL.
  76. unsigned int, the i-th instance the TextureBatch containing
  77. the files.
  78. const char*, the buffer containing the whole texture pack file.
  79. unsigned int, size of the buffer.
  80. output:
  81. true on success.
  82. false when failing checks against segmentation faults.
  83. Example logic to interact with all textures:
  84. {
  85. // After reading the file in...
  86. // Need to know how many batches are in the package.
  87. struct TexturePack *p = (struct TexturePack*)filedata;
  88. // Need to know about each batch in the package.
  89. struct TextureBatchDescriptor *d = NULL;
  90. struct Texture *t = NULL;
  91. unsigned int i;
  92. for (i = 0; i < p -> batchNumber; i++) {
  93. DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize);
  94. // Batch descriptor tells how many textures are in the batch.
  95. t = (struct Texture*)
  96. malloc(sizeof(struct Texture) * (d -> texNumber));
  97. DEVIL1TEX.gettextures(t, i, filedata, filesize);
  98. // There are now textures in 't'.
  99. for (j = 0; j < d -> texNumber; j++) {
  100. // Do whatever you want with however many textures there are.
  101. }
  102. free(t);
  103. }
  104. }