trunk/src/osd/sdl/texcopy.c
| r28770 | r28771 | |
| 1 | | |
| 2 | | #ifndef SDL_TEXFORMAT |
| 3 | | |
| 4 | | #if 0 |
| 5 | | INLINE UINT32 ycc_to_rgb(unsigned y, unsigned cb, unsigned cr) |
| 6 | | { |
| 7 | | /* original equations: |
| 8 | | |
| 9 | | C = Y - 16 |
| 10 | | D = Cb - 128 |
| 11 | | E = Cr - 128 |
| 12 | | |
| 13 | | R = clip(( 298 * C + 409 * E + 128) >> 8) |
| 14 | | G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8) |
| 15 | | B = clip(( 298 * C + 516 * D + 128) >> 8) |
| 16 | | |
| 17 | | R = clip(( 298 * (Y - 16) + 409 * (Cr - 128) + 128) >> 8) |
| 18 | | G = clip(( 298 * (Y - 16) - 100 * (Cb - 128) - 208 * (Cr - 128) + 128) >> 8) |
| 19 | | B = clip(( 298 * (Y - 16) + 516 * (Cb - 128) + 128) >> 8) |
| 20 | | |
| 21 | | R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) |
| 22 | | G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) |
| 23 | | B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) |
| 24 | | |
| 25 | | R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) |
| 26 | | G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) |
| 27 | | B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) |
| 28 | | */ |
| 29 | | //int r, g, b, common; |
| 30 | | unsigned int r, g, b, common; |
| 31 | | |
| 32 | | common = 298 * y - 56992; |
| 33 | | r = (common + 409 * cr); |
| 34 | | g = (common - 100 * cb - 208 * cr + 91776); |
| 35 | | b = (common + 516 * cb - 13696); |
| 36 | | |
| 37 | | if ((int) r < 0) r = 0; |
| 38 | | if ((int) g < 0) g = 0; |
| 39 | | if ((int) b < 0) b = 0; |
| 40 | | |
| 41 | | /* MAME_RGB does upper clamping */ |
| 42 | | |
| 43 | | return rgb_t(r >> 8, g >> 8, b >> 8); |
| 44 | | } |
| 45 | | #else |
| 46 | | |
| 47 | | |
| 48 | | static int clamp_lu[256+128+128] = { 255 }; |
| 49 | | static int coff_cr[256][2] = { {0, 0} }; |
| 50 | | static int coff_cb[256][2] = { {0, 0} }; |
| 51 | | |
| 52 | | static void init_clamp(void) |
| 53 | | { |
| 54 | | int i; |
| 55 | | for (i=0;i<128;i++) |
| 56 | | { |
| 57 | | clamp_lu[i] = 0; |
| 58 | | clamp_lu[i + 256 + 128] = 255; |
| 59 | | } |
| 60 | | for (i=0;i<256;i++) |
| 61 | | { |
| 62 | | clamp_lu[i + 128] = i; |
| 63 | | |
| 64 | | coff_cr[i][0] = + 409 * i - 56992; |
| 65 | | coff_cr[i][1] = - 208 * i; |
| 66 | | coff_cb[i][0] = - 100 * i /* - 208 * cr */ + 34784; |
| 67 | | coff_cb[i][1] = + 516 * i - 70688; |
| 68 | | } |
| 69 | | } |
| 70 | | |
| 71 | | INLINE int clamp(int x) { return (const int) clamp_lu[(x >> 8) + 128] ; } |
| 72 | | |
| 73 | | INLINE UINT32 ycc_to_rgb(unsigned y, unsigned cb, unsigned cr) |
| 74 | | { |
| 75 | | int r, g, b, common; |
| 76 | | common = y * 298; |
| 77 | | |
| 78 | | r = (const int) coff_cr[cr][0]; // 409 * cr - 56992; |
| 79 | | g = (const int) coff_cb[cb][0] + (const int) coff_cr[cr][1]; //- 100 * cb - 208 * cr + 34784; |
| 80 | | b = (const int) coff_cb[cb][1]; //+ 516 * cb - 70688; |
| 81 | | return 0xff000000 | (clamp(r + common)<<16) | (clamp(g + common)<<8) | (clamp(b + common)); |
| 82 | | } |
| 83 | | |
| 84 | | #endif |
| 85 | | |
| 86 | | #define SDL_TEXFORMAT SDL_TEXFORMAT_ARGB32 |
| 87 | | #include "texcopy.c" |
| 88 | | |
| 89 | | #define SDL_TEXFORMAT SDL_TEXFORMAT_RGB32 |
| 90 | | #include "texcopy.c" |
| 91 | | |
| 92 | | #define SDL_TEXFORMAT SDL_TEXFORMAT_RGB32_PALETTED |
| 93 | | #include "texcopy.c" |
| 94 | | |
| 95 | | #define SDL_TEXFORMAT SDL_TEXFORMAT_PALETTE16 |
| 96 | | #include "texcopy.c" |
| 97 | | |
| 98 | | #define SDL_TEXFORMAT SDL_TEXFORMAT_PALETTE16A |
| 99 | | #include "texcopy.c" |
| 100 | | |
| 101 | | #define SDL_TEXFORMAT SDL_TEXFORMAT_RGB15 |
| 102 | | #include "texcopy.c" |
| 103 | | |
| 104 | | #define SDL_TEXFORMAT SDL_TEXFORMAT_RGB15_PALETTED |
| 105 | | #include "texcopy.c" |
| 106 | | |
| 107 | | //============================================================ |
| 108 | | // MANUAL TEXCOPY FUNCS |
| 109 | | // (YUY format is weird and doesn't fit the assumptions of the |
| 110 | | // standard macros so we handle it here |
| 111 | | //============================================================ |
| 112 | | #if 1 //ndef SDLMAME_MACOSX |
| 113 | | static void texcopy_yuv16(texture_info *texture, const render_texinfo *texsource) |
| 114 | | { |
| 115 | | int x, y; |
| 116 | | UINT32 *dst; |
| 117 | | UINT16 *src; |
| 118 | | |
| 119 | | if (clamp_lu[0]>0) |
| 120 | | init_clamp(); |
| 121 | | |
| 122 | | // loop over Y |
| 123 | | for (y = 0; y < texsource->height; y++) |
| 124 | | { |
| 125 | | src = (UINT16 *)texsource->base + y * texsource->rowpixels; |
| 126 | | dst = (UINT32 *)texture->data + (y * texture->yprescale + texture->borderpix) * texture->rawwidth; |
| 127 | | |
| 128 | | // always fill non-wrapping textures with an extra pixel on the left |
| 129 | | if (texture->borderpix) |
| 130 | | *dst++ = 0; |
| 131 | | |
| 132 | | // we don't support prescale for YUV textures |
| 133 | | for (x = texsource->width/2; x > 0 ; x--) |
| 134 | | { |
| 135 | | UINT16 srcpix0 = *src++; |
| 136 | | UINT16 srcpix1 = *src++; |
| 137 | | UINT8 cb = srcpix0 & 0xff; |
| 138 | | UINT8 cr = srcpix1 & 0xff; |
| 139 | | |
| 140 | | *dst++ = ycc_to_rgb(srcpix0 >> 8, cb, cr); |
| 141 | | *dst++ = ycc_to_rgb(srcpix1 >> 8, cb, cr); |
| 142 | | } |
| 143 | | |
| 144 | | // always fill non-wrapping textures with an extra pixel on the right |
| 145 | | #if 0 |
| 146 | | if (texture->borderpix) |
| 147 | | *dst++ = 0; |
| 148 | | #endif |
| 149 | | } |
| 150 | | } |
| 151 | | |
| 152 | | |
| 153 | | static void texcopy_yuv16_paletted(texture_info *texture, const render_texinfo *texsource) |
| 154 | | { |
| 155 | | int x, y; |
| 156 | | UINT32 *dst; |
| 157 | | UINT16 *src; |
| 158 | | int lookup[256]; |
| 159 | | |
| 160 | | if (clamp_lu[0]>0) |
| 161 | | init_clamp(); |
| 162 | | |
| 163 | | /* preprocess lookup */ |
| 164 | | for (x=0; x<256; x++) |
| 165 | | lookup[x] = texsource->palette[x] * 298; |
| 166 | | |
| 167 | | // loop over Y |
| 168 | | for (y = 0; y < texsource->height; y++) |
| 169 | | { |
| 170 | | src = (UINT16 *)texsource->base + y * texsource->rowpixels; |
| 171 | | dst = (UINT32 *)texture->data + (y * texture->yprescale + texture->borderpix) * texture->rawwidth; |
| 172 | | |
| 173 | | // always fill non-wrapping textures with an extra pixel on the left |
| 174 | | if (texture->borderpix) |
| 175 | | *dst++ = 0; |
| 176 | | |
| 177 | | // we don't support prescale for YUV textures |
| 178 | | for (x = texsource->width/2; x > 0 ; x--) |
| 179 | | { |
| 180 | | UINT16 srcpix0 = *src++; |
| 181 | | UINT16 srcpix1 = *src++; |
| 182 | | UINT8 cb = srcpix0 & 0xff; |
| 183 | | UINT8 cr = srcpix1 & 0xff; |
| 184 | | |
| 185 | | #if 0 |
| 186 | | *dst++ = ycc_to_rgb(texsource->palette[0x000 + (srcpix0 >> 8)], cb, cr); |
| 187 | | *dst++ = ycc_to_rgb(texsource->palette[0x000 + (srcpix1 >> 8)], cb, cr); |
| 188 | | #else |
| 189 | | int r = (const int) coff_cr[cr][0]; |
| 190 | | int g = (const int) coff_cb[cb][0] + (const int) coff_cr[cr][1]; |
| 191 | | int b = (const int) coff_cb[cb][1]; |
| 192 | | int y1 = (const int) lookup[(srcpix0 >> 8)]; |
| 193 | | int y2 = (const int) lookup[(srcpix1 >> 8)]; |
| 194 | | |
| 195 | | |
| 196 | | *dst++ = 0xff000000 | (clamp(r + y1)<<16) | (clamp(g + y1)<<8) | (clamp(b + y1)); |
| 197 | | *dst++ = 0xff000000 | (clamp(r + y2)<<16) | (clamp(g + y2)<<8) | (clamp(b + y2)); |
| 198 | | #endif |
| 199 | | } |
| 200 | | |
| 201 | | // always fill non-wrapping textures with an extra pixel on the right |
| 202 | | #if 0 |
| 203 | | if (texture->borderpix) |
| 204 | | *dst++ = 0; |
| 205 | | #endif |
| 206 | | } |
| 207 | | } |
| 208 | | |
| 209 | | #endif |
| 210 | | |
| 211 | | #else // recursive include |
| 212 | | |
| 213 | | #include "texsrc.h" |
| 214 | | |
| 215 | | static void FUNC_NAME(texcopy)(texture_info *texture, const render_texinfo *texsource) |
| 216 | | { |
| 217 | | int x, y; |
| 218 | | DEST_TYPE *dst; |
| 219 | | TEXSRC_TYPE *src; |
| 220 | | |
| 221 | | // loop over Y |
| 222 | | for (y = 0; y < texsource->height; y++) |
| 223 | | { |
| 224 | | src = (TEXSRC_TYPE *)texsource->base + y * texsource->rowpixels; |
| 225 | | dst = (DEST_TYPE *)texture->data + (y * texture->yprescale + texture->borderpix) * texture->rawwidth; |
| 226 | | |
| 227 | | // always fill non-wrapping textures with an extra pixel on the left |
| 228 | | if (texture->borderpix) |
| 229 | | *dst++ = 0; |
| 230 | | |
| 231 | | switch(texture->xprescale) |
| 232 | | { |
| 233 | | case 1: |
| 234 | | for (x = 0; x < texsource->width; x++) |
| 235 | | { |
| 236 | | *dst++ = TEXSRC_TO_DEST(*src); |
| 237 | | src++; |
| 238 | | } |
| 239 | | break; |
| 240 | | case 2: |
| 241 | | for (x = 0; x < texsource->width; x++) |
| 242 | | { |
| 243 | | DEST_TYPE pixel = TEXSRC_TO_DEST(*src); |
| 244 | | *dst++ = pixel; |
| 245 | | *dst++ = pixel; |
| 246 | | src++; |
| 247 | | } |
| 248 | | break; |
| 249 | | case 3: |
| 250 | | for (x = 0; x < texsource->width; x++) |
| 251 | | { |
| 252 | | DEST_TYPE pixel = TEXSRC_TO_DEST(*src); |
| 253 | | *dst++ = pixel; |
| 254 | | *dst++ = pixel; |
| 255 | | *dst++ = pixel; |
| 256 | | src++; |
| 257 | | } |
| 258 | | break; |
| 259 | | } |
| 260 | | |
| 261 | | // always fill non-wrapping textures with an extra pixel on the right |
| 262 | | if (texture->borderpix) |
| 263 | | *dst++ = 0; |
| 264 | | |
| 265 | | /* abuse x var to act as line counter while copying */ |
| 266 | | for (x = 1; x < texture->yprescale; x++) |
| 267 | | { |
| 268 | | DEST_TYPE *src1 = (DEST_TYPE *)texture->data + (y * texture->yprescale + texture->borderpix) * texture->rawwidth; |
| 269 | | dst = (DEST_TYPE *)texture->data + (y * texture->yprescale + texture->borderpix + x) * texture->rawwidth; |
| 270 | | memcpy(dst, src1, (texture->rawwidth + 2*texture->borderpix) * sizeof(DEST_TYPE)); |
| 271 | | } |
| 272 | | } |
| 273 | | } |
| 274 | | |
| 275 | | #undef SDL_TEXFORMAT |
| 276 | | #endif |
trunk/src/osd/sdl/drawogl.c
| r28770 | r28771 | |
| 117 | 117 | #define GL_DEPTH_COMPONENT32 0x81A7 |
| 118 | 118 | #endif |
| 119 | 119 | |
| 120 | | //#define OLD_CODE 1 |
| 121 | | |
| 122 | | #ifndef OLD_CODE |
| 123 | 120 | #define HASH_SIZE ((1<<10)+1) |
| 124 | 121 | #define OVERFLOW_SIZE (1<<10) |
| 125 | | #endif |
| 126 | 122 | |
| 127 | 123 | // OSD headers |
| 128 | 124 | #include "osdsdl.h" |
| r28770 | r28771 | |
| 162 | 158 | |
| 163 | 159 | struct texture_info; |
| 164 | 160 | |
| 165 | | #if USE_OPENGL |
| 166 | | typedef void (*texture_copy_func)(texture_info *texture, const render_texinfo *texsource); |
| 167 | | #endif |
| 168 | | |
| 169 | 161 | /* texture_info holds information about a texture */ |
| 170 | 162 | struct texture_info |
| 171 | 163 | { |
| 172 | | #ifdef OLD_CODE |
| 173 | | texture_info * next; // next texture in the list |
| 174 | | #endif |
| 175 | 164 | HashT hash; // hash value for the texture (must be >= pointer size) |
| 176 | 165 | UINT32 flags; // rendering flags |
| 177 | 166 | render_texinfo texinfo; // copy of the texture info |
| r28770 | r28771 | |
| 187 | 176 | |
| 188 | 177 | UINT32 texture; // OpenGL texture "name"/ID |
| 189 | 178 | |
| 190 | | const GLint * texProperties; // texture properties |
| 191 | | texture_copy_func texCopyFn; // texture copy function, !=NULL if !nocopy |
| 192 | 179 | GLenum texTarget; // OpenGL texture target |
| 193 | 180 | int texpow2; // Is this texture pow2 |
| 194 | 181 | |
| r28770 | r28771 | |
| 227 | 214 | |
| 228 | 215 | int initialized; // is everything well initialized, i.e. all GL stuff etc. |
| 229 | 216 | // 3D info (GL mode only) |
| 230 | | #ifdef OLD_CODE |
| 231 | | texture_info * texlist; // list of active textures |
| 232 | | #else |
| 233 | 217 | texture_info * texhash[HASH_SIZE + OVERFLOW_SIZE]; |
| 234 | | #endif |
| 235 | 218 | int last_blendmode; // previous blendmode |
| 236 | 219 | INT32 texture_max_width; // texture maximum width |
| 237 | 220 | INT32 texture_max_height; // texture maximum height |
| r28770 | r28771 | |
| 292 | 275 | // INLINES |
| 293 | 276 | //============================================================ |
| 294 | 277 | |
| 295 | | #ifdef OLD_CODE |
| 296 | 278 | INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags) |
| 297 | 279 | { |
| 298 | | return (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)); |
| 299 | | } |
| 300 | | #else |
| 301 | | INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags) |
| 302 | | { |
| 303 | 280 | HashT h = (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)); |
| 304 | 281 | //printf("hash %d\n", (int) h % HASH_SIZE); |
| 305 | 282 | return (h >> 8) % HASH_SIZE; |
| 306 | 283 | } |
| 307 | | #endif |
| 308 | 284 | |
| 309 | 285 | INLINE void set_blendmode(sdl_info *sdl, int blendmode) |
| 310 | 286 | { |
| r28770 | r28771 | |
| 383 | 359 | static int glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN; |
| 384 | 360 | |
| 385 | 361 | //============================================================ |
| 386 | | // TEXCOPY FUNCS |
| 387 | | //============================================================ |
| 388 | | |
| 389 | | static void texcopy_argb32(texture_info *texture, const render_texinfo *texsource); |
| 390 | | static void texcopy_rgb32(texture_info *texture, const render_texinfo *texsource); |
| 391 | | static void texcopy_rgb32_paletted(texture_info *texture, const render_texinfo *texsource); |
| 392 | | static void texcopy_palette16(texture_info *texture, const render_texinfo *texsource); |
| 393 | | static void texcopy_palette16a(texture_info *texture, const render_texinfo *texsource); |
| 394 | | static void texcopy_rgb15(texture_info *texture, const render_texinfo *texsource); |
| 395 | | static void texcopy_rgb15_paletted(texture_info *texture, const render_texinfo *texsource); |
| 396 | | static void texcopy_yuv16(texture_info *texture, const render_texinfo *texsource); |
| 397 | | static void texcopy_yuv16_paletted(texture_info *texture, const render_texinfo *texsource); |
| 398 | | |
| 399 | | //============================================================ |
| 400 | 362 | // Textures |
| 401 | 363 | //============================================================ |
| 402 | 364 | |
| 403 | | static void texture_set_data(texture_info *texture, const render_texinfo *texsource); |
| 365 | static void texture_set_data(texture_info *texture, const render_texinfo *texsource, UINT32 flags); |
| 404 | 366 | static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags); |
| 405 | 367 | static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim); |
| 406 | 368 | static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx); |
| r28770 | r28771 | |
| 1561 | 1523 | { FALSE, TRUE } // SDL_TEXFORMAT_PALETTE16A |
| 1562 | 1524 | }; |
| 1563 | 1525 | |
| 1564 | | // 6 properties (per format) |
| 1565 | | // right order according to glTexImage2D: internal, format, type, .. |
| 1566 | | enum { SDL_TEXFORMAT_INTERNAL, SDL_TEXFORMAT_FORMAT, SDL_TEXFORMAT_TYPE, SDL_TEXFORMAT_PIXEL_SIZE }; |
| 1567 | | |
| 1568 | | static const GLint texture_gl_properties_srcNative_intNative[9][6] = { |
| 1569 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_ARGB32 |
| 1570 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB32 |
| 1571 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB32_PALETTED |
| 1572 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_YUY16 |
| 1573 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_YUY16_PALETTED |
| 1574 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_PALETTE16 |
| 1575 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB15 |
| 1576 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB15_PALETTED |
| 1577 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) } // SDL_TEXFORMAT_PALETTE16A |
| 1578 | | }; |
| 1579 | | |
| 1580 | | static const GLint texture_gl_properties_srcNative_int32bpp[9][6] = { |
| 1581 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_ARGB32 |
| 1582 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB32 |
| 1583 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB32_PALETTED |
| 1584 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_YUY16 |
| 1585 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_YUY16_PALETTED |
| 1586 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_PALETTE16 |
| 1587 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB15 |
| 1588 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB15_PALETTED |
| 1589 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) } // SDL_TEXFORMAT_PALETTE16A |
| 1590 | | }; |
| 1591 | | |
| 1592 | | static const GLint texture_gl_properties_srcCopy_int32bpp[9][6] = { |
| 1593 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_ARGB32 |
| 1594 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB32 |
| 1595 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB32_PALETTED |
| 1596 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_YUY16 |
| 1597 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_YUY16_PALETTED |
| 1598 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_PALETTE16 |
| 1599 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB15 |
| 1600 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) }, // SDL_TEXFORMAT_RGB15_PALETTED |
| 1601 | | { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sizeof(UINT32) } // SDL_TEXFORMAT_PALETTE16A |
| 1602 | | }; |
| 1603 | | |
| 1604 | | static const texture_copy_func texcopy_dstNative_f[9] = { |
| 1605 | | texcopy_argb32, |
| 1606 | | texcopy_rgb32, |
| 1607 | | texcopy_rgb32_paletted, |
| 1608 | | texcopy_yuv16, |
| 1609 | | texcopy_yuv16_paletted, |
| 1610 | | texcopy_palette16, |
| 1611 | | texcopy_rgb15, |
| 1612 | | texcopy_rgb15_paletted, |
| 1613 | | texcopy_palette16a |
| 1614 | | }; |
| 1615 | | |
| 1616 | | static const texture_copy_func texcopy_dst32bpp_f[9] = { |
| 1617 | | texcopy_argb32, |
| 1618 | | texcopy_rgb32, |
| 1619 | | texcopy_rgb32_paletted, |
| 1620 | | texcopy_yuv16, |
| 1621 | | texcopy_yuv16_paletted, |
| 1622 | | texcopy_palette16, |
| 1623 | | texcopy_rgb15, |
| 1624 | | texcopy_rgb15_paletted, |
| 1625 | | texcopy_palette16a |
| 1626 | | }; |
| 1627 | | |
| 1628 | 1526 | //============================================================ |
| 1629 | 1527 | // drawogl_exit |
| 1630 | 1528 | //============================================================ |
| r28770 | r28771 | |
| 1706 | 1604 | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1707 | 1605 | } |
| 1708 | 1606 | |
| 1709 | | // currently glsl supports idx and rgb palette lookups, |
| 1710 | | // no special quality scaling, so we could drop the prescale criteria below .. |
| 1711 | | if ( texture->type == TEXTURE_TYPE_NONE && |
| 1712 | | sdl->useglsl && |
| 1713 | | ( |
| 1714 | | texture->format==SDL_TEXFORMAT_RGB32_PALETTED || // glsl rgb32 lut/direct |
| 1715 | | texture->format==SDL_TEXFORMAT_RGB32 || |
| 1716 | | texture->format==SDL_TEXFORMAT_RGB15_PALETTED || // glsl rgb15 lut/direct |
| 1717 | | texture->format==SDL_TEXFORMAT_RGB15 |
| 1718 | | ) && |
| 1719 | | texture->xprescale == 1 && texture->yprescale == 1 && |
| 1720 | | texsource->rowpixels <= sdl->texture_max_width |
| 1721 | | ) |
| 1722 | | { |
| 1723 | | texture->type = TEXTURE_TYPE_SHADER; |
| 1724 | | texture->nocopy = TRUE; |
| 1725 | | texture->texTarget = GL_TEXTURE_2D; |
| 1726 | | texture->texpow2 = sdl->texpoweroftwo; |
| 1727 | | } |
| 1728 | | |
| 1729 | 1607 | // determine if we can skip the copy step |
| 1730 | 1608 | // if this was not already decided by the shader condition above |
| 1731 | | if ( !texture->nocopy && |
| 1732 | | texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST] && |
| 1609 | if ( texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST] && |
| 1733 | 1610 | !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] && |
| 1734 | 1611 | texture->xprescale == 1 && texture->yprescale == 1 && |
| 1735 | | !texture->borderpix && |
| 1612 | !texture->borderpix && !texsource->palette && |
| 1736 | 1613 | texsource->rowpixels <= sdl->texture_max_width ) |
| 1737 | 1614 | { |
| 1738 | 1615 | texture->nocopy = TRUE; |
| 1739 | | } |
| 1616 | } |
| 1740 | 1617 | |
| 1741 | 1618 | if( texture->type == TEXTURE_TYPE_NONE && |
| 1742 | 1619 | sdl->usepbo && !texture->nocopy ) |
| 1743 | 1620 | { |
| 1744 | 1621 | texture->type = TEXTURE_TYPE_DYNAMIC; |
| 1745 | | texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1746 | | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1622 | texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1623 | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1747 | 1624 | } |
| 1748 | 1625 | |
| 1749 | 1626 | if( texture->type == TEXTURE_TYPE_NONE ) |
| 1750 | 1627 | { |
| 1751 | 1628 | texture->type = TEXTURE_TYPE_SURFACE; |
| 1752 | | texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1753 | | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1754 | | } |
| 1755 | | |
| 1756 | | if ( texture->type!=TEXTURE_TYPE_SHADER ) |
| 1757 | | { |
| 1758 | | texture->texProperties = texture_gl_properties_srcNative_intNative[texture->format]; |
| 1759 | | texture->texCopyFn = texcopy_dstNative_f[texture->format]; |
| 1760 | | } else if ( texture->nocopy ) |
| 1761 | | { |
| 1762 | | texture->texProperties = texture_gl_properties_srcNative_int32bpp[texture->format]; |
| 1763 | | texture->texCopyFn = NULL; |
| 1764 | | } else { |
| 1765 | | texture->texProperties = texture_gl_properties_srcCopy_int32bpp[texture->format]; |
| 1766 | | texture->texCopyFn = texcopy_dst32bpp_f[texture->format]; |
| 1767 | | } |
| 1629 | texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; |
| 1630 | texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; |
| 1631 | } |
| 1768 | 1632 | } |
| 1769 | 1633 | |
| 1770 | 1634 | INLINE int get_valid_pow2_value(int v, int needPow2) |
| r28770 | r28771 | |
| 1883 | 1747 | (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE], |
| 1884 | 1748 | texture->xprescale, texture->yprescale, |
| 1885 | 1749 | texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width, |
| 1886 | | (int)texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE] |
| 1750 | (int)sizeof(UINT32) |
| 1887 | 1751 | ); |
| 1888 | 1752 | } |
| 1889 | 1753 | |
| r28770 | r28771 | |
| 2154 | 2018 | |
| 2155 | 2019 | UINT32 * dummy = NULL; |
| 2156 | 2020 | GLint _width, _height; |
| 2157 | | if ( gl_texture_check_size(GL_TEXTURE_2D, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], |
| 2021 | if ( gl_texture_check_size(GL_TEXTURE_2D, 0, GL_RGBA8, |
| 2158 | 2022 | texture->rawwidth_create, texture->rawheight_create, |
| 2159 | 2023 | 0, |
| 2160 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2161 | | texture->texProperties[SDL_TEXFORMAT_TYPE], |
| 2024 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, |
| 2162 | 2025 | &_width, &_height, 1) ) |
| 2163 | 2026 | { |
| 2164 | 2027 | mame_printf_error("cannot create bitmap texture, req: %dx%d, avail: %dx%d - bail out\n", |
| r28770 | r28771 | |
| 2166 | 2029 | return -1; |
| 2167 | 2030 | } |
| 2168 | 2031 | |
| 2169 | | dummy = (UINT32 *) malloc(texture->rawwidth_create * texture->rawheight_create * |
| 2170 | | texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| 2171 | | memset(dummy, 0, texture->rawwidth_create * texture->rawheight_create * |
| 2172 | | texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| 2173 | | glTexImage2D(GL_TEXTURE_2D, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], |
| 2032 | dummy = (UINT32 *) malloc(texture->rawwidth_create * texture->rawheight_create * sizeof(UINT32)); |
| 2033 | memset(dummy, 0, texture->rawwidth_create * texture->rawheight_create * sizeof(UINT32)); |
| 2034 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, |
| 2174 | 2035 | texture->rawwidth_create, texture->rawheight_create, |
| 2175 | 2036 | 0, |
| 2176 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2177 | | texture->texProperties[SDL_TEXFORMAT_TYPE], dummy); |
| 2037 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, dummy); |
| 2178 | 2038 | glFinish(); // should not be necessary, .. but make sure we won't access the memory after free |
| 2179 | 2039 | free(dummy); |
| 2180 | 2040 | |
| r28770 | r28771 | |
| 2306 | 2166 | glBindTexture(texture->texTarget, texture->texture); |
| 2307 | 2167 | |
| 2308 | 2168 | // this doesn't actually upload, it just sets up the PBO's parameters |
| 2309 | | glTexImage2D(texture->texTarget, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], |
| 2169 | glTexImage2D(texture->texTarget, 0, GL_RGBA8, |
| 2310 | 2170 | texture->rawwidth_create, texture->rawheight_create, |
| 2311 | 2171 | texture->borderpix ? 1 : 0, |
| 2312 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2313 | | texture->texProperties[SDL_TEXFORMAT_TYPE], NULL); |
| 2172 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); |
| 2314 | 2173 | |
| 2315 | 2174 | if ((PRIMFLAG_GET_SCREENTEX(flags)) && video_config.filter) |
| 2316 | 2175 | { |
| r28770 | r28771 | |
| 2356 | 2215 | |
| 2357 | 2216 | // set up the PBO dimension, .. |
| 2358 | 2217 | pfn_glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, |
| 2359 | | texture->rawwidth * texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE], |
| 2218 | texture->rawwidth * texture->rawheight * sizeof(UINT32), |
| 2360 | 2219 | NULL, GL_STREAM_DRAW); |
| 2361 | 2220 | } |
| 2362 | 2221 | |
| 2363 | 2222 | if ( !texture->nocopy && texture->type!=TEXTURE_TYPE_DYNAMIC ) |
| 2364 | 2223 | { |
| 2365 | | texture->data = (UINT32 *) malloc(texture->rawwidth* texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| 2224 | texture->data = (UINT32 *) malloc(texture->rawwidth* texture->rawheight * sizeof(UINT32)); |
| 2366 | 2225 | texture->data_own=TRUE; |
| 2367 | 2226 | } |
| 2368 | 2227 | |
| 2369 | 2228 | // add us to the texture list |
| 2370 | | #ifdef OLD_CODE |
| 2371 | | texture->next = sdl->texlist; |
| 2372 | | sdl->texlist = texture; |
| 2373 | | #else |
| 2374 | 2229 | if (sdl->texhash[texture->hash] == NULL) |
| 2375 | 2230 | sdl->texhash[texture->hash] = texture; |
| 2376 | 2231 | else |
| r28770 | r28771 | |
| 2384 | 2239 | } |
| 2385 | 2240 | assert(i < HASH_SIZE + OVERFLOW_SIZE); |
| 2386 | 2241 | } |
| 2387 | | #endif |
| 2242 | |
| 2388 | 2243 | if(sdl->usevbo) |
| 2389 | 2244 | { |
| 2390 | 2245 | // Generate And Bind The Texture Coordinate Buffer |
| r28770 | r28771 | |
| 2403 | 2258 | } |
| 2404 | 2259 | |
| 2405 | 2260 | //============================================================ |
| 2261 | // copyline_palette16 |
| 2262 | //============================================================ |
| 2263 | |
| 2264 | INLINE void copyline_palette16(UINT32 *dst, const UINT16 *src, int width, const rgb_t *palette, int xborderpix) |
| 2265 | { |
| 2266 | int x; |
| 2267 | |
| 2268 | assert(xborderpix == 0 || xborderpix == 1); |
| 2269 | if (xborderpix) |
| 2270 | *dst++ = 0xff000000 | palette[*src]; |
| 2271 | for (x = 0; x < width; x++) |
| 2272 | *dst++ = 0xff000000 | palette[*src++]; |
| 2273 | if (xborderpix) |
| 2274 | *dst++ = 0xff000000 | palette[*--src]; |
| 2275 | } |
| 2276 | |
| 2277 | |
| 2278 | |
| 2279 | //============================================================ |
| 2280 | // copyline_palettea16 |
| 2281 | //============================================================ |
| 2282 | |
| 2283 | INLINE void copyline_palettea16(UINT32 *dst, const UINT16 *src, int width, const rgb_t *palette, int xborderpix) |
| 2284 | { |
| 2285 | int x; |
| 2286 | |
| 2287 | assert(xborderpix == 0 || xborderpix == 1); |
| 2288 | if (xborderpix) |
| 2289 | *dst++ = palette[*src]; |
| 2290 | for (x = 0; x < width; x++) |
| 2291 | *dst++ = palette[*src++]; |
| 2292 | if (xborderpix) |
| 2293 | *dst++ = palette[*--src]; |
| 2294 | } |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | //============================================================ |
| 2299 | // copyline_rgb32 |
| 2300 | //============================================================ |
| 2301 | |
| 2302 | INLINE void copyline_rgb32(UINT32 *dst, const UINT32 *src, int width, const rgb_t *palette, int xborderpix) |
| 2303 | { |
| 2304 | int x; |
| 2305 | |
| 2306 | assert(xborderpix == 0 || xborderpix == 1); |
| 2307 | |
| 2308 | // palette (really RGB map) case |
| 2309 | if (palette != NULL) |
| 2310 | { |
| 2311 | if (xborderpix) |
| 2312 | { |
| 2313 | rgb_t srcpix = *src; |
| 2314 | *dst++ = 0xff000000 | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; |
| 2315 | } |
| 2316 | for (x = 0; x < width; x++) |
| 2317 | { |
| 2318 | rgb_t srcpix = *src++; |
| 2319 | *dst++ = 0xff000000 | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; |
| 2320 | } |
| 2321 | if (xborderpix) |
| 2322 | { |
| 2323 | rgb_t srcpix = *--src; |
| 2324 | *dst++ = 0xff000000 | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; |
| 2325 | } |
| 2326 | } |
| 2327 | |
| 2328 | // direct case |
| 2329 | else |
| 2330 | { |
| 2331 | if (xborderpix) |
| 2332 | *dst++ = 0xff000000 | *src; |
| 2333 | for (x = 0; x < width; x++) |
| 2334 | *dst++ = 0xff000000 | *src++; |
| 2335 | if (xborderpix) |
| 2336 | *dst++ = 0xff000000 | *--src; |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | //============================================================ |
| 2341 | // copyline_argb32 |
| 2342 | //============================================================ |
| 2343 | |
| 2344 | INLINE void copyline_argb32(UINT32 *dst, const UINT32 *src, int width, const rgb_t *palette, int xborderpix) |
| 2345 | { |
| 2346 | int x; |
| 2347 | |
| 2348 | assert(xborderpix == 0 || xborderpix == 1); |
| 2349 | |
| 2350 | // palette (really RGB map) case |
| 2351 | if (palette != NULL) |
| 2352 | { |
| 2353 | if (xborderpix) |
| 2354 | { |
| 2355 | rgb_t srcpix = *src; |
| 2356 | *dst++ = (srcpix & 0xff000000) | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; |
| 2357 | } |
| 2358 | for (x = 0; x < width; x++) |
| 2359 | { |
| 2360 | rgb_t srcpix = *src++; |
| 2361 | *dst++ = (srcpix & 0xff000000) | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; |
| 2362 | } |
| 2363 | if (xborderpix) |
| 2364 | { |
| 2365 | rgb_t srcpix = *--src; |
| 2366 | *dst++ = (srcpix & 0xff000000) | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | // direct case |
| 2371 | else |
| 2372 | { |
| 2373 | if (xborderpix) |
| 2374 | *dst++ = *src; |
| 2375 | for (x = 0; x < width; x++) |
| 2376 | *dst++ = *src++; |
| 2377 | if (xborderpix) |
| 2378 | *dst++ = *--src; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | INLINE UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr) |
| 2383 | { |
| 2384 | /* original equations: |
| 2385 | |
| 2386 | C = Y - 16 |
| 2387 | D = Cb - 128 |
| 2388 | E = Cr - 128 |
| 2389 | |
| 2390 | R = clip(( 298 * C + 409 * E + 128) >> 8) |
| 2391 | G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8) |
| 2392 | B = clip(( 298 * C + 516 * D + 128) >> 8) |
| 2393 | |
| 2394 | R = clip(( 298 * (Y - 16) + 409 * (Cr - 128) + 128) >> 8) |
| 2395 | G = clip(( 298 * (Y - 16) - 100 * (Cb - 128) - 208 * (Cr - 128) + 128) >> 8) |
| 2396 | B = clip(( 298 * (Y - 16) + 516 * (Cb - 128) + 128) >> 8) |
| 2397 | |
| 2398 | R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) |
| 2399 | G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) |
| 2400 | B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) |
| 2401 | |
| 2402 | R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) |
| 2403 | G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) |
| 2404 | B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) |
| 2405 | */ |
| 2406 | int r, g, b, common; |
| 2407 | |
| 2408 | common = 298 * y - 298 * 16; |
| 2409 | r = (common + 409 * cr - 409 * 128 + 128) >> 8; |
| 2410 | g = (common - 100 * cb + 100 * 128 - 208 * cr + 208 * 128 + 128) >> 8; |
| 2411 | b = (common + 516 * cb - 516 * 128 + 128) >> 8; |
| 2412 | |
| 2413 | if (r < 0) r = 0; |
| 2414 | else if (r > 255) r = 255; |
| 2415 | if (g < 0) g = 0; |
| 2416 | else if (g > 255) g = 255; |
| 2417 | if (b < 0) b = 0; |
| 2418 | else if (b > 255) b = 255; |
| 2419 | |
| 2420 | return rgb_t(0xff, r, g, b); |
| 2421 | } |
| 2422 | |
| 2423 | //============================================================ |
| 2424 | // copyline_yuy16_to_argb |
| 2425 | //============================================================ |
| 2426 | |
| 2427 | INLINE void copyline_yuy16_to_argb(UINT32 *dst, const UINT16 *src, int width, const rgb_t *palette, int xborderpix) |
| 2428 | { |
| 2429 | int x; |
| 2430 | |
| 2431 | assert(xborderpix == 0 || xborderpix == 2); |
| 2432 | assert(width % 2 == 0); |
| 2433 | |
| 2434 | // palette (really RGB map) case |
| 2435 | if (palette != NULL) |
| 2436 | { |
| 2437 | if (xborderpix) |
| 2438 | { |
| 2439 | UINT16 srcpix0 = src[0]; |
| 2440 | UINT16 srcpix1 = src[1]; |
| 2441 | UINT8 cb = srcpix0 & 0xff; |
| 2442 | UINT8 cr = srcpix1 & 0xff; |
| 2443 | *dst++ = ycc_to_rgb(palette[0x000 + (srcpix0 >> 8)], cb, cr); |
| 2444 | *dst++ = ycc_to_rgb(palette[0x000 + (srcpix0 >> 8)], cb, cr); |
| 2445 | } |
| 2446 | for (x = 0; x < width / 2; x++) |
| 2447 | { |
| 2448 | UINT16 srcpix0 = *src++; |
| 2449 | UINT16 srcpix1 = *src++; |
| 2450 | UINT8 cb = srcpix0 & 0xff; |
| 2451 | UINT8 cr = srcpix1 & 0xff; |
| 2452 | *dst++ = ycc_to_rgb(palette[0x000 + (srcpix0 >> 8)], cb, cr); |
| 2453 | *dst++ = ycc_to_rgb(palette[0x000 + (srcpix1 >> 8)], cb, cr); |
| 2454 | } |
| 2455 | if (xborderpix) |
| 2456 | { |
| 2457 | UINT16 srcpix1 = *--src; |
| 2458 | UINT16 srcpix0 = *--src; |
| 2459 | UINT8 cb = srcpix0 & 0xff; |
| 2460 | UINT8 cr = srcpix1 & 0xff; |
| 2461 | *dst++ = ycc_to_rgb(palette[0x000 + (srcpix1 >> 8)], cb, cr); |
| 2462 | *dst++ = ycc_to_rgb(palette[0x000 + (srcpix1 >> 8)], cb, cr); |
| 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | // direct case |
| 2467 | else |
| 2468 | { |
| 2469 | if (xborderpix) |
| 2470 | { |
| 2471 | UINT16 srcpix0 = src[0]; |
| 2472 | UINT16 srcpix1 = src[1]; |
| 2473 | UINT8 cb = srcpix0 & 0xff; |
| 2474 | UINT8 cr = srcpix1 & 0xff; |
| 2475 | *dst++ = ycc_to_rgb(srcpix0 >> 8, cb, cr); |
| 2476 | *dst++ = ycc_to_rgb(srcpix0 >> 8, cb, cr); |
| 2477 | } |
| 2478 | for (x = 0; x < width; x += 2) |
| 2479 | { |
| 2480 | UINT16 srcpix0 = *src++; |
| 2481 | UINT16 srcpix1 = *src++; |
| 2482 | UINT8 cb = srcpix0 & 0xff; |
| 2483 | UINT8 cr = srcpix1 & 0xff; |
| 2484 | *dst++ = ycc_to_rgb(srcpix0 >> 8, cb, cr); |
| 2485 | *dst++ = ycc_to_rgb(srcpix1 >> 8, cb, cr); |
| 2486 | } |
| 2487 | if (xborderpix) |
| 2488 | { |
| 2489 | UINT16 srcpix1 = *--src; |
| 2490 | UINT16 srcpix0 = *--src; |
| 2491 | UINT8 cb = srcpix0 & 0xff; |
| 2492 | UINT8 cr = srcpix1 & 0xff; |
| 2493 | *dst++ = ycc_to_rgb(srcpix1 >> 8, cb, cr); |
| 2494 | *dst++ = ycc_to_rgb(srcpix1 >> 8, cb, cr); |
| 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | //============================================================ |
| 2406 | 2500 | // texture_set_data |
| 2407 | 2501 | //============================================================ |
| 2408 | 2502 | |
| 2409 | | static void texture_set_data(texture_info *texture, const render_texinfo *texsource) |
| 2503 | static void texture_set_data(texture_info *texture, const render_texinfo *texsource, UINT32 flags) |
| 2410 | 2504 | { |
| 2411 | 2505 | if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2412 | 2506 | { |
| r28770 | r28771 | |
| 2420 | 2514 | // they cannot be both true, thus this cannot lead to the |
| 2421 | 2515 | // borderpix code below writing to texsource->base . |
| 2422 | 2516 | if (texture->nocopy) |
| 2517 | { |
| 2423 | 2518 | texture->data = (UINT32 *) texsource->base; |
| 2519 | } |
| 2424 | 2520 | |
| 2425 | 2521 | // always fill non-wrapping textures with an extra pixel on the top |
| 2426 | 2522 | if (texture->borderpix) |
| 2427 | 2523 | { |
| 2428 | 2524 | memset(texture->data, 0, |
| 2429 | | (texsource->width * texture->xprescale + 2) * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| 2525 | (texsource->width * texture->xprescale + 2) * sizeof(UINT32)); |
| 2430 | 2526 | } |
| 2431 | 2527 | |
| 2432 | 2528 | // when nescesarry copy (and convert) the data |
| 2433 | 2529 | if (!texture->nocopy) |
| 2434 | 2530 | { |
| 2435 | | assert(texture->texCopyFn); |
| 2436 | | texture->texCopyFn(texture, texsource); |
| 2531 | int x, y; |
| 2532 | UINT8 *dst; |
| 2533 | |
| 2534 | for (y = 0; y < texsource->height; y++) |
| 2535 | { |
| 2536 | dst = (UINT8 *)(texture->data + (y * texture->yprescale + texture->borderpix) * texture->rawwidth); |
| 2537 | |
| 2538 | switch (PRIMFLAG_GET_TEXFORMAT(flags)) |
| 2539 | { |
| 2540 | case TEXFORMAT_PALETTE16: |
| 2541 | copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix); |
| 2542 | break; |
| 2543 | |
| 2544 | case TEXFORMAT_PALETTEA16: |
| 2545 | copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix); |
| 2546 | break; |
| 2547 | |
| 2548 | case TEXFORMAT_RGB32: |
| 2549 | copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix); |
| 2550 | break; |
| 2551 | |
| 2552 | case TEXFORMAT_ARGB32: |
| 2553 | copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix); |
| 2554 | break; |
| 2555 | |
| 2556 | case TEXFORMAT_YUY16: |
| 2557 | copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette, texture->borderpix); |
| 2558 | break; |
| 2559 | |
| 2560 | default: |
| 2561 | mame_printf_error("Unknown texture blendmode=%d format=%d\n", PRIMFLAG_GET_BLENDMODE(flags), PRIMFLAG_GET_TEXFORMAT(flags)); |
| 2562 | break; |
| 2563 | } |
| 2564 | } |
| 2437 | 2565 | } |
| 2438 | 2566 | |
| 2439 | 2567 | // always fill non-wrapping textures with an extra pixel on the bottom |
| 2440 | 2568 | if (texture->borderpix) |
| 2441 | 2569 | { |
| 2442 | 2570 | memset((UINT8 *)texture->data + |
| 2443 | | (texsource->height + 1) * texture->rawwidth * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE], |
| 2571 | (texsource->height + 1) * texture->rawwidth * sizeof(UINT32), |
| 2444 | 2572 | 0, |
| 2445 | | (texsource->width * texture->xprescale + 2) * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); |
| 2573 | (texsource->width * texture->xprescale + 2) * sizeof(UINT32)); |
| 2446 | 2574 | } |
| 2447 | 2575 | |
| 2448 | 2576 | if ( texture->type == TEXTURE_TYPE_SHADER ) |
| r28770 | r28771 | |
| 2465 | 2593 | |
| 2466 | 2594 | // and upload the image |
| 2467 | 2595 | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2468 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2469 | | texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data); |
| 2596 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, texture->data); |
| 2470 | 2597 | } |
| 2471 | 2598 | else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) |
| 2472 | 2599 | { |
| r28770 | r28771 | |
| 2479 | 2606 | |
| 2480 | 2607 | // kick off the DMA |
| 2481 | 2608 | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2482 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2483 | | texture->texProperties[SDL_TEXFORMAT_TYPE], NULL); |
| 2609 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); |
| 2484 | 2610 | } |
| 2485 | 2611 | else |
| 2486 | 2612 | { |
| r28770 | r28771 | |
| 2494 | 2620 | |
| 2495 | 2621 | // and upload the image |
| 2496 | 2622 | glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, |
| 2497 | | texture->texProperties[SDL_TEXFORMAT_FORMAT], |
| 2498 | | texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data); |
| 2623 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, texture->data); |
| 2499 | 2624 | } |
| 2500 | 2625 | } |
| 2501 | 2626 | |
| r28770 | r28771 | |
| 2503 | 2628 | // texture_find |
| 2504 | 2629 | //============================================================ |
| 2505 | 2630 | |
| 2506 | | #ifdef OLD_CODE |
| 2507 | | static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim) |
| 2508 | | { |
| 2509 | | HashT texhash = texture_compute_hash(&prim->texture, prim->flags); |
| 2510 | | texture_info *texture; |
| 2511 | | |
| 2512 | | // find a match |
| 2513 | | for (texture = sdl->texlist; texture != NULL; texture = texture->next) |
| 2514 | | if (texture->hash == texhash && |
| 2515 | | texture->texinfo.base == prim->texture.base && |
| 2516 | | texture->texinfo.width == prim->texture.width && |
| 2517 | | texture->texinfo.height == prim->texture.height && |
| 2518 | | texture->texinfo.rowpixels == prim->texture.rowpixels && |
| 2519 | | ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0) |
| 2520 | | return texture; |
| 2521 | | |
| 2522 | | // nothing found |
| 2523 | | return NULL; |
| 2524 | | } |
| 2525 | | #else |
| 2526 | | |
| 2527 | | #if 0 |
| 2528 | | static int compare_texinfo(render_texinfo *t1, render_texinfo *t2) |
| 2529 | | { |
| 2530 | | if (t1->base == t2->base && |
| 2531 | | t1->width == t2->width && |
| 2532 | | t1->height == t2->height && |
| 2533 | | t1->rowpixels == t2->rowpixels) |
| 2534 | | return 1; |
| 2535 | | else |
| 2536 | | return 0; |
| 2537 | | } |
| 2538 | | #endif |
| 2539 | | |
| 2540 | 2631 | static int compare_texture_primitive(const texture_info *texture, const render_primitive *prim) |
| 2541 | 2632 | { |
| 2542 | 2633 | if (texture->texinfo.base == prim->texture.base && |
| 2543 | 2634 | texture->texinfo.width == prim->texture.width && |
| 2544 | 2635 | texture->texinfo.height == prim->texture.height && |
| 2545 | 2636 | texture->texinfo.rowpixels == prim->texture.rowpixels && |
| 2637 | texture->texinfo.palette == prim->texture.palette && |
| 2546 | 2638 | ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0) |
| 2547 | 2639 | return 1; |
| 2548 | 2640 | else |
| r28770 | r28771 | |
| 2570 | 2662 | return NULL; |
| 2571 | 2663 | } |
| 2572 | 2664 | |
| 2573 | | #endif |
| 2574 | | |
| 2575 | 2665 | //============================================================ |
| 2576 | 2666 | // texture_update |
| 2577 | 2667 | //============================================================ |
| r28770 | r28771 | |
| 2784 | 2874 | // if we didn't find one, create a new texture |
| 2785 | 2875 | if (texture == NULL && prim->texture.base != NULL) |
| 2786 | 2876 | { |
| 2787 | | texture = texture_create(window, &prim->texture, prim->flags); |
| 2788 | | |
| 2877 | texture = texture_create(window, &prim->texture, prim->flags); |
| 2789 | 2878 | } |
| 2790 | 2879 | else if (texture != NULL) |
| 2791 | 2880 | { |
| r28770 | r28771 | |
| 2823 | 2912 | texture->texinfo.seqid = prim->texture.seqid; |
| 2824 | 2913 | |
| 2825 | 2914 | // if we found it, but with a different seqid, copy the data |
| 2826 | | texture_set_data(texture, &prim->texture); |
| 2915 | texture_set_data(texture, &prim->texture, prim->flags); |
| 2827 | 2916 | texBound=1; |
| 2828 | 2917 | } |
| 2829 | 2918 | } |
| r28770 | r28771 | |
| 2908 | 2997 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 2909 | 2998 | texture_info *texture = NULL; |
| 2910 | 2999 | int lock=FALSE; |
| 2911 | | #ifdef OLD_CODE |
| 2912 | | texture_info *next_texture=NULL; |
| 2913 | | #else |
| 2914 | 3000 | int i; |
| 2915 | | #endif |
| 2916 | 3001 | |
| 2917 | 3002 | if (sdl == NULL) |
| 2918 | 3003 | return; |
| r28770 | r28771 | |
| 2936 | 3021 | glFinish(); |
| 2937 | 3022 | glDisableClientState(GL_VERTEX_ARRAY); |
| 2938 | 3023 | |
| 2939 | | #ifdef OLD_CODE |
| 2940 | | texture = sdl->texlist; |
| 2941 | | while (texture) |
| 2942 | | { |
| 2943 | | next_texture = texture->next; |
| 2944 | | #else |
| 2945 | 3024 | i=0; |
| 2946 | 3025 | while (i<HASH_SIZE+OVERFLOW_SIZE) |
| 2947 | 3026 | { |
| r28770 | r28771 | |
| 2949 | 3028 | sdl->texhash[i] = NULL; |
| 2950 | 3029 | if (texture != NULL) |
| 2951 | 3030 | { |
| 2952 | | #endif |
| 2953 | | |
| 2954 | 3031 | if(sdl->usevbo) |
| 2955 | 3032 | { |
| 2956 | 3033 | pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); |
| r28770 | r28771 | |
| 2988 | 3065 | texture->data_own=FALSE; |
| 2989 | 3066 | } |
| 2990 | 3067 | free(texture); |
| 2991 | | #ifdef OLD_CODE |
| 2992 | | texture = next_texture; |
| 2993 | | } |
| 2994 | | sdl->texlist = NULL; |
| 2995 | | #else |
| 2996 | 3068 | } |
| 2997 | 3069 | i++; |
| 2998 | 3070 | } |
| 2999 | | #endif |
| 3000 | 3071 | if ( sdl->useglsl ) |
| 3001 | 3072 | { |
| 3002 | 3073 | glsl_shader_free(sdl->glsl); |
| r28770 | r28771 | |
| 3021 | 3092 | sdl->blittimer = 3; |
| 3022 | 3093 | } |
| 3023 | 3094 | |
| 3024 | | |
| 3025 | | //============================================================ |
| 3026 | | // TEXCOPY FUNCS |
| 3027 | | //============================================================ |
| 3028 | | |
| 3029 | | #include "texcopy.c" |