irrlicht-texturehack.patch 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. --- irrlicht/source/Irrlicht/COGLESTexture.cpp.orig 2014-06-22 17:01:13.266568869 +0200
  2. +++ irrlicht/source/Irrlicht/COGLESTexture.cpp 2014-06-22 17:03:59.298572810 +0200
  3. @@ -366,112 +366,140 @@
  4. void(*convert)(const void*, s32, void*) = 0;
  5. getFormatParameters(ColorFormat, InternalFormat, filtering, PixelFormat, PixelType, convert);
  6. - // make sure we don't change the internal format of existing images
  7. - if (!newTexture)
  8. - InternalFormat = oldInternalFormat;
  9. -
  10. - Driver->setActiveTexture(0, this);
  11. -
  12. - if (Driver->testGLError())
  13. - os::Printer::log("Could not bind Texture", ELL_ERROR);
  14. -
  15. - // mipmap handling for main texture
  16. - if (!level && newTexture)
  17. - {
  18. - // auto generate if possible and no mipmap data is given
  19. - if (!IsCompressed && HasMipMaps && !mipmapData && Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE))
  20. - {
  21. - if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
  22. - glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
  23. - else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY))
  24. - glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
  25. - else
  26. - glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);
  27. + bool retry = false;
  28. +
  29. + do {
  30. + if (retry) {
  31. + InternalFormat = GL_RGBA;
  32. + PixelFormat = GL_RGBA;
  33. + convert = CColorConverter::convert_A8R8G8B8toA8B8G8R8;
  34. + }
  35. + // make sure we don't change the internal format of existing images
  36. + if (!newTexture)
  37. + InternalFormat = oldInternalFormat;
  38. - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
  39. - AutomaticMipmapUpdate=true;
  40. - }
  41. + Driver->setActiveTexture(0, this);
  42. - // enable bilinear filter without mipmaps
  43. - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
  44. - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
  45. - }
  46. + if (Driver->testGLError())
  47. + os::Printer::log("Could not bind Texture", ELL_ERROR);
  48. - // now get image data and upload to GPU
  49. + // mipmap handling for main texture
  50. + if (!level && newTexture)
  51. + {
  52. + // auto generate if possible and no mipmap data is given
  53. + if (!IsCompressed && HasMipMaps && !mipmapData && Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE))
  54. + {
  55. + if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
  56. + glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
  57. + else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY))
  58. + glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
  59. + else
  60. + glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);
  61. +
  62. + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
  63. + AutomaticMipmapUpdate=true;
  64. + }
  65. +
  66. + // enable bilinear filter without mipmaps
  67. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
  68. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
  69. + }
  70. - u32 compressedImageSize = IImage::getCompressedImageSize(ColorFormat, image->getDimension().Width, image->getDimension().Height);
  71. + // now get image data and upload to GPU
  72. - void* source = image->lock();
  73. + u32 compressedImageSize = IImage::getCompressedImageSize(ColorFormat, image->getDimension().Width, image->getDimension().Height);
  74. - IImage* tmpImage = 0;
  75. + void* source = image->lock();
  76. - if (convert)
  77. - {
  78. - tmpImage = new CImage(image->getColorFormat(), image->getDimension());
  79. - void* dest = tmpImage->lock();
  80. - convert(source, image->getDimension().getArea(), dest);
  81. - image->unlock();
  82. - source = dest;
  83. - }
  84. + IImage* tmpImage = 0;
  85. - if (newTexture)
  86. - {
  87. - if (IsCompressed)
  88. + if (convert)
  89. {
  90. - glCompressedTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, image->getDimension().Width,
  91. - image->getDimension().Height, 0, compressedImageSize, source);
  92. + tmpImage = new CImage(image->getColorFormat(), image->getDimension());
  93. + void* dest = tmpImage->lock();
  94. + convert(source, image->getDimension().getArea(), dest);
  95. + image->unlock();
  96. + source = dest;
  97. }
  98. - else
  99. - glTexImage2D(GL_TEXTURE_2D, level, InternalFormat, image->getDimension().Width,
  100. - image->getDimension().Height, 0, PixelFormat, PixelType, source);
  101. - }
  102. - else
  103. - {
  104. - if (IsCompressed)
  105. +
  106. + if (newTexture)
  107. {
  108. - glCompressedTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width,
  109. - image->getDimension().Height, PixelFormat, compressedImageSize, source);
  110. + if (IsCompressed)
  111. + {
  112. + glCompressedTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, image->getDimension().Width,
  113. + image->getDimension().Height, 0, compressedImageSize, source);
  114. + }
  115. + else
  116. + glTexImage2D(GL_TEXTURE_2D, level, InternalFormat, image->getDimension().Width,
  117. + image->getDimension().Height, 0, PixelFormat, PixelType, source);
  118. }
  119. else
  120. - glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width,
  121. - image->getDimension().Height, PixelFormat, PixelType, source);
  122. - }
  123. -
  124. - if (convert)
  125. - {
  126. - tmpImage->unlock();
  127. - tmpImage->drop();
  128. - }
  129. - else
  130. - image->unlock();
  131. -
  132. - if (!level && newTexture)
  133. - {
  134. - if (IsCompressed && !mipmapData)
  135. {
  136. - if (image->hasMipMaps())
  137. - mipmapData = static_cast<u8*>(image->lock())+compressedImageSize;
  138. + if (IsCompressed)
  139. + {
  140. + glCompressedTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width,
  141. + image->getDimension().Height, PixelFormat, compressedImageSize, source);
  142. + }
  143. else
  144. - HasMipMaps = false;
  145. + glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width,
  146. + image->getDimension().Height, PixelFormat, PixelType, source);
  147. }
  148. - regenerateMipMapLevels(mipmapData);
  149. -
  150. - if (HasMipMaps) // might have changed in regenerateMipMapLevels
  151. + if (convert)
  152. {
  153. - // enable bilinear mipmap filter
  154. - GLint filteringMipMaps = GL_LINEAR_MIPMAP_NEAREST;
  155. -
  156. - if (filtering != GL_LINEAR)
  157. - filteringMipMaps = GL_NEAREST_MIPMAP_NEAREST;
  158. + tmpImage->unlock();
  159. + tmpImage->drop();
  160. + }
  161. + else
  162. + image->unlock();
  163. +
  164. + if (glGetError() != GL_NO_ERROR) {
  165. + static bool warned = false;
  166. + if ((!retry) && (ColorFormat == ECF_A8R8G8B8)) {
  167. +
  168. + if (!warned) {
  169. + os::Printer::log("Your driver claims to support GL_BGRA but fails on trying to upload a texture, converting to GL_RGBA and trying again", ELL_ERROR);
  170. + warned = true;
  171. + }
  172. + }
  173. + else if (retry) {
  174. + os::Printer::log("Neither uploading texture as GL_BGRA nor, converted one using GL_RGBA succeeded", ELL_ERROR);
  175. + }
  176. + retry = !retry;
  177. + continue;
  178. + } else {
  179. + retry = false;
  180. + }
  181. - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filteringMipMaps);
  182. - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
  183. + if (!level && newTexture)
  184. + {
  185. + if (IsCompressed && !mipmapData)
  186. + {
  187. + if (image->hasMipMaps())
  188. + mipmapData = static_cast<u8*>(image->lock())+compressedImageSize;
  189. + else
  190. + HasMipMaps = false;
  191. + }
  192. +
  193. + regenerateMipMapLevels(mipmapData);
  194. +
  195. + if (HasMipMaps) // might have changed in regenerateMipMapLevels
  196. + {
  197. + // enable bilinear mipmap filter
  198. + GLint filteringMipMaps = GL_LINEAR_MIPMAP_NEAREST;
  199. +
  200. + if (filtering != GL_LINEAR)
  201. + filteringMipMaps = GL_NEAREST_MIPMAP_NEAREST;
  202. +
  203. + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filteringMipMaps);
  204. + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
  205. + }
  206. }
  207. - }
  208. - if (Driver->testGLError())
  209. - os::Printer::log("Could not glTexImage2D", ELL_ERROR);
  210. + if (Driver->testGLError())
  211. + os::Printer::log("Could not glTexImage2D", ELL_ERROR);
  212. + }
  213. + while(retry);
  214. }
  215. --- irrlicht/source/Irrlicht/COGLESTexture.cpp.orig 2014-06-25 00:28:50.820501856 +0200
  216. +++ irrlicht/source/Irrlicht/COGLESTexture.cpp 2014-06-25 00:08:37.712544692 +0200
  217. @@ -422,6 +422,9 @@
  218. source = dest;
  219. }
  220. + //clear old error
  221. + glGetError();
  222. +
  223. if (newTexture)
  224. {
  225. if (IsCompressed)