| 1 | From: Sylvain <[email protected]>
|
| 2 | Date: Sat, 10 Apr 2021 21:33:29 +0200
|
| 3 | Subject: [PATCH] Fixed bug 580 - Use 'userdata' instead of 'refcount'
|
| 4 | 'refcount' is a private SDL_Surface field
|
| 5 |
|
| 6 | ---
|
| 7 | src/draw.cpp | 22 +++++++++++-----------
|
| 8 | src/files.cpp | 2 +-
|
| 9 | src/opengl.cpp | 26 +++++++++++++-------------
|
| 10 | src/savepng.cpp | 2 +-
|
| 11 | 4 files changed, 26 insertions(+), 26 deletions(-)
|
| 12 |
|
| 13 | diff --git a/src/draw.cpp b/src/draw.cpp
|
| 14 | index 08f95343f..4e62c751a 100644
|
| 15 | |
| 16 | |
| 17 | @@ -443,7 +443,7 @@ void drawImageRotatedAlpha( SDL_Surface* image, SDL_Rect* src, SDL_Rect* pos, re
|
| 18 | }
|
| 19 |
|
| 20 | // draw a textured quad
|
| 21 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 22 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 23 | glColor4f(1, 1, 1, alpha / 255.1);
|
| 24 | glBegin(GL_QUADS);
|
| 25 | glTexCoord2f(1.0 * ((real_t)src->x / image->w), 1.0 * ((real_t)src->y / image->h));
|
| 26 | @@ -492,7 +492,7 @@ void drawImageColor( SDL_Surface* image, SDL_Rect* src, SDL_Rect* pos, Uint32 co
|
| 27 | }
|
| 28 |
|
| 29 | // draw a textured quad
|
| 30 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 31 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 32 | real_t r = ((Uint8)(color >> mainsurface->format->Rshift)) / 255.f;
|
| 33 | real_t g = ((Uint8)(color >> mainsurface->format->Gshift)) / 255.f;
|
| 34 | real_t b = ((Uint8)(color >> mainsurface->format->Bshift)) / 255.f;
|
| 35 | @@ -546,7 +546,7 @@ void drawImageAlpha( SDL_Surface* image, SDL_Rect* src, SDL_Rect* pos, Uint8 alp
|
| 36 | }
|
| 37 |
|
| 38 | // draw a textured quad
|
| 39 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 40 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 41 | glColor4f(1, 1, 1, alpha / 255.1);
|
| 42 | glPushMatrix();
|
| 43 | glBegin(GL_QUADS);
|
| 44 | @@ -596,7 +596,7 @@ void drawImage( SDL_Surface* image, SDL_Rect* src, SDL_Rect* pos )
|
| 45 | }
|
| 46 |
|
| 47 | // draw a textured quad
|
| 48 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 49 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 50 | glColor4f(1, 1, 1, 1);
|
| 51 | glPushMatrix();
|
| 52 | glBegin(GL_QUADS);
|
| 53 | @@ -646,7 +646,7 @@ void drawImageRing(SDL_Surface* image, SDL_Rect* src, int radius, int thickness,
|
| 54 | }
|
| 55 |
|
| 56 | // draw a textured quad
|
| 57 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 58 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 59 | glColor4f(1, 1, 1, alpha / 255.f);
|
| 60 | glPushMatrix();
|
| 61 |
|
| 62 | @@ -771,7 +771,7 @@ void drawImageScaled( SDL_Surface* image, SDL_Rect* src, SDL_Rect* pos )
|
| 63 | }
|
| 64 |
|
| 65 | // draw a textured quad
|
| 66 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 67 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 68 | glColor4f(1, 1, 1, 1);
|
| 69 | glPushMatrix();
|
| 70 | glBegin(GL_QUADS);
|
| 71 | @@ -826,7 +826,7 @@ void drawImageScaledPartial(SDL_Surface* image, SDL_Rect* src, SDL_Rect* pos, fl
|
| 72 | }
|
| 73 |
|
| 74 | // draw a textured quad
|
| 75 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 76 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 77 | glColor4f(1, 1, 1, 1);
|
| 78 | glPushMatrix();
|
| 79 | glBegin(GL_QUADS);
|
| 80 | @@ -889,7 +889,7 @@ void drawImageScaledColor(SDL_Surface* image, SDL_Rect* src, SDL_Rect* pos, Uint
|
| 81 | }
|
| 82 |
|
| 83 | // draw a textured quad
|
| 84 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 85 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 86 | real_t r = ((Uint8)(color >> mainsurface->format->Rshift)) / 255.f;
|
| 87 | real_t g = ((Uint8)(color >> mainsurface->format->Gshift)) / 255.f;
|
| 88 | real_t b = ((Uint8)(color >> mainsurface->format->Bshift)) / 255.f;
|
| 89 | @@ -985,7 +985,7 @@ void drawImageFancy( SDL_Surface* image, Uint32 color, real_t angle, SDL_Rect* s
|
| 90 | }
|
| 91 |
|
| 92 | // draw a textured quad
|
| 93 | - glBindTexture(GL_TEXTURE_2D, texid[image->refcount]);
|
| 94 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)image->userdata]);
|
| 95 | real_t r = ((Uint8)(color >> mainsurface->format->Rshift)) / 255.f;
|
| 96 | real_t g = ((Uint8)(color >> mainsurface->format->Gshift)) / 255.f;
|
| 97 | real_t b = ((Uint8)(color >> mainsurface->format->Bshift)) / 255.f;
|
| 98 | @@ -2186,7 +2186,7 @@ void drawWindowFancy(int x1, int y1, int x2, int y2)
|
| 99 | glVertex2f(x2 - 1, yres - y1 - 1);
|
| 100 | glEnd();
|
| 101 | glColor3f(.75, .75, .75);
|
| 102 | - glBindTexture(GL_TEXTURE_2D, texid[fancyWindow_bmp->refcount]); // wood texture
|
| 103 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)fancyWindow_bmp->userdata]); // wood texture
|
| 104 | glBegin(GL_QUADS);
|
| 105 | glTexCoord2f(0, 0);
|
| 106 | glVertex2f(x1 + 2, yres - y1 - 2);
|
| 107 | @@ -2322,7 +2322,7 @@ SDL_Rect ttfPrintTextColor( TTF_Font* font, int x, int y, Uint32 color, bool out
|
| 108 | SDL_BlitSurface(textSurf, NULL, surf, &pos);
|
| 109 | // load the text outline surface as a GL texture
|
| 110 | allsurfaces[imgref] = surf;
|
| 111 | - allsurfaces[imgref]->refcount = imgref;
|
| 112 | + allsurfaces[imgref]->userdata = (void*) imgref;
|
| 113 | glLoadTexture(allsurfaces[imgref], imgref);
|
| 114 | imgref++;
|
| 115 | // store the surface in the text surface cache
|
| 116 | diff --git a/src/files.cpp b/src/files.cpp
|
| 117 | index 2beb9a6b9..389ade6d1 100644
|
| 118 | |
| 119 | |
| 120 | @@ -591,7 +591,7 @@ SDL_Surface* loadImage(char const * const filename)
|
| 121 |
|
| 122 | // load the new surface as a GL texture
|
| 123 | allsurfaces[imgref] = newSurface;
|
| 124 | - allsurfaces[imgref]->refcount = imgref + 1;
|
| 125 | + allsurfaces[imgref]->userdata = (void *)(imgref);
|
| 126 | glLoadTexture(allsurfaces[imgref], imgref);
|
| 127 |
|
| 128 | // free the translated surface
|
| 129 | diff --git a/src/opengl.cpp b/src/opengl.cpp
|
| 130 | index f5b81e77a..3ac225825 100644
|
| 131 | |
| 132 | |
| 133 | @@ -500,7 +500,7 @@ void glDrawSprite(view_t* camera, Entity* entity, int mode)
|
| 134 | }
|
| 135 | if ( mode == REALCOLORS )
|
| 136 | {
|
| 137 | - glBindTexture(GL_TEXTURE_2D, texid[sprite->refcount]);
|
| 138 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)sprite->userdata]);
|
| 139 | }
|
| 140 | else
|
| 141 | {
|
| 142 | @@ -586,7 +586,7 @@ void glDrawSpriteFromImage(view_t* camera, Entity* entity, std::string text, int
|
| 143 | //int x, y;
|
| 144 | real_t s = 1;
|
| 145 | SDL_Surface* image = sprites[0];
|
| 146 | - GLuint textureId = texid[sprites[0]->refcount];
|
| 147 | + GLuint textureId = texid[(long int)sprites[0]->userdata];
|
| 148 | char textToRetrieve[128];
|
| 149 |
|
| 150 | if ( text.compare("") == 0 )
|
| 151 | @@ -603,7 +603,7 @@ void glDrawSpriteFromImage(view_t* camera, Entity* entity, std::string text, int
|
| 152 | textToRetrieve[std::min(static_cast<int>(strlen(text.c_str())), 22)] = '\0';
|
| 153 | if ( (image = ttfTextHashRetrieve(ttfTextHash, textToRetrieve, ttf12, true)) != NULL )
|
| 154 | {
|
| 155 | - textureId = texid[image->refcount];
|
| 156 | + textureId = texid[(long int)image->userdata];
|
| 157 | }
|
| 158 | else
|
| 159 | {
|
| 160 | @@ -627,7 +627,7 @@ void glDrawSpriteFromImage(view_t* camera, Entity* entity, std::string text, int
|
| 161 | SDL_BlitSurface(textSurf, NULL, image, &pos);
|
| 162 | // load the text outline surface as a GL texture
|
| 163 | allsurfaces[imgref] = image;
|
| 164 | - allsurfaces[imgref]->refcount = imgref;
|
| 165 | + allsurfaces[imgref]->userdata = (void *)((long int)imgref);
|
| 166 | glLoadTexture(allsurfaces[imgref], imgref);
|
| 167 | imgref++;
|
| 168 | // store the surface in the text surface cache
|
| 169 | @@ -635,7 +635,7 @@ void glDrawSpriteFromImage(view_t* camera, Entity* entity, std::string text, int
|
| 170 | {
|
| 171 | printlog("warning: failed to store text outline surface with imgref %d\n", imgref - 1);
|
| 172 | }
|
| 173 | - textureId = texid[image->refcount];
|
| 174 | + textureId = texid[(long int)image->userdata];
|
| 175 | }
|
| 176 | // setup projection
|
| 177 | glMatrixMode(GL_PROJECTION);
|
| 178 | @@ -864,7 +864,7 @@ void glDrawWorld(view_t* camera, int mode)
|
| 179 |
|
| 180 | // first (higher) sky layer
|
| 181 | glColor4f(1.f, 1.f, 1.f, .5);
|
| 182 | - glBindTexture(GL_TEXTURE_2D, texid[tiles[cloudtile]->refcount]); // sky tile
|
| 183 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)tiles[cloudtile]->userdata]); // sky tile
|
| 184 | glBegin( GL_QUADS );
|
| 185 | glTexCoord2f((real_t)(ticks % 60) / 60, (real_t)(ticks % 60) / 60);
|
| 186 | glVertex3f(-CLIPFAR * 16, 64, -CLIPFAR * 16);
|
| 187 | @@ -881,7 +881,7 @@ void glDrawWorld(view_t* camera, int mode)
|
| 188 |
|
| 189 | // second (closer) sky layer
|
| 190 | glColor4f(1.f, 1.f, 1.f, .5);
|
| 191 | - glBindTexture(GL_TEXTURE_2D, texid[tiles[cloudtile]->refcount]); // sky tile
|
| 192 | + glBindTexture(GL_TEXTURE_2D, texid[(long int)tiles[cloudtile]->userdata]); // sky tile
|
| 193 | glBegin( GL_QUADS );
|
| 194 | glTexCoord2f((real_t)(ticks % 240) / 240, (real_t)(ticks % 240) / 240);
|
| 195 | glVertex3f(-CLIPFAR * 16, 32, -CLIPFAR * 16);
|
| 196 | @@ -954,13 +954,13 @@ void glDrawWorld(view_t* camera, int mode)
|
| 197 | {
|
| 198 | if ( map.tiles[index] < 0 || map.tiles[index] >= numtiles )
|
| 199 | {
|
| 200 | - new_tex = texid[sprites[0]->refcount];
|
| 201 | - //glBindTexture(GL_TEXTURE_2D, texid[sprites[0]->refcount]);
|
| 202 | + new_tex = texid[(long int)sprites[0]->userdata];
|
| 203 | + //glBindTexture(GL_TEXTURE_2D, texid[(long int)sprites[0]->userdata]);
|
| 204 | }
|
| 205 | else
|
| 206 | {
|
| 207 | - new_tex = texid[tiles[map.tiles[index]]->refcount];
|
| 208 | - //glBindTexture(GL_TEXTURE_2D, texid[tiles[map.tiles[index]]->refcount]);
|
| 209 | + new_tex = texid[(long int)tiles[map.tiles[index]]->userdata];
|
| 210 | + //glBindTexture(GL_TEXTURE_2D, texid[(long int)tiles[map.tiles[index]]->userdata]);
|
| 211 | }
|
| 212 | }
|
| 213 | else
|
| 214 | @@ -1282,8 +1282,8 @@ void glDrawWorld(view_t* camera, int mode)
|
| 215 | // bind texture
|
| 216 | if ( mode == REALCOLORS )
|
| 217 | {
|
| 218 | - new_tex = texid[tiles[mapceilingtile]->refcount];
|
| 219 | - //glBindTexture(GL_TEXTURE_2D, texid[tiles[50]->refcount]); // rock tile
|
| 220 | + new_tex = texid[(long int)tiles[mapceilingtile]->userdata];
|
| 221 | + //glBindTexture(GL_TEXTURE_2D, texid[(long int)tiles[50]->userdata]); // rock tile
|
| 222 | if (cur_tex!=new_tex)
|
| 223 | {
|
| 224 | glEnd();
|
| 225 | diff --git a/src/savepng.cpp b/src/savepng.cpp
|
| 226 | index fa7a5d4e2..59e052a5c 100644
|
| 227 | |
| 228 | |
| 229 | @@ -59,7 +59,7 @@ SDL_Surface* SDL_PNGFormatAlpha(SDL_Surface* src)
|
| 230 | /* NO-OP for images < 32bpp and 32bpp images that already have Alpha channel */
|
| 231 | if (src->format->BitsPerPixel <= 24 || src->format->Amask)
|
| 232 | {
|
| 233 | - src->refcount++;
|
| 234 | + src->userdata = (void *)((long int) src->userdata + 1);
|
| 235 | return src;
|
| 236 | }
|
| 237 |
|