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