Previous 199869 Revisions Next

r28771 Friday 21st March, 2014 at 01:51:58 UTC by R. Belmont
SDL: Next stage cleanup, aligned texture conversion with current Windows/D3D code, and fixed overzealous GL texture caching. [R. Belmont]


nw: this fixes brightness/gamma/contrast on RGB32 format games (which has been broken since 2008, clearly a well-loved feature ;-) and breaks prescale.  Prescale will be fixed soon.
[src/osd/sdl]drawogl.c sdl.mak texcopy.c texsrc.h

trunk/src/osd/sdl/texsrc.h
r28770r28771
1
2#ifdef DEST_TYPE
3#undef DEST_TYPE
4#endif
5
6#ifdef DEST_NAME
7#undef DEST_NAME
8#endif
9
10#ifdef TEXSRC_TYPE
11#undef TEXSRC_TYPE
12#endif
13
14#ifdef TEXSRC_TO_DEST
15#undef TEXSRC_TO_DEST
16#endif
17
18#ifdef SRC_EQUALS_DEST
19#undef SRC_EQUALS_DEST
20#endif
21
22#ifdef FUNC_NAME
23#undef FUNC_NAME
24#endif
25
26#if SDL_TEXFORMAT == SDL_TEXFORMAT_ARGB32
27   #define DEST_TYPE UINT32
28   #define DEST_NAME(name) name ## _32bpp
29   #define TEXSRC_TYPE UINT32
30   #define TEXSRC_TO_DEST(src) (src)
31   #define SRC_EQUALS_DEST
32   #define FUNC_NAME(name) name ## _argb32
33#elif SDL_TEXFORMAT == SDL_TEXFORMAT_RGB32
34   #define DEST_TYPE UINT32
35   #define DEST_NAME(name) name ## _32bpp
36   #define TEXSRC_TYPE UINT32
37   #define TEXSRC_TO_DEST(src) ((src) | 0xff000000)
38   #define FUNC_NAME(name) name ## _rgb32
39#elif SDL_TEXFORMAT == SDL_TEXFORMAT_RGB32_PALETTED
40   #define DEST_TYPE UINT32
41   #define DEST_NAME(name) name ## _32bpp
42   #define TEXSRC_TYPE UINT32
43   #define TEXSRC_TO_DEST(src) \
44      (texsource->palette[0x200 + (((src) >> 16) & 0xff) ]   | \
45         texsource->palette[0x100 + (((src) >> 8) & 0xff) ] | \
46         texsource->palette[((src) & 0xff) ] | 0xff000000)
47   #define FUNC_NAME(name) name ## _rgb32_paletted
48#elif SDL_TEXFORMAT == SDL_TEXFORMAT_PALETTE16
49   #define DEST_TYPE UINT32
50   #define DEST_NAME(name) name ## _32bpp
51   #define TEXSRC_TYPE UINT16
52   #define TEXSRC_TO_DEST(src) \
53      (0xff000000 | texsource->palette[src])
54   #define FUNC_NAME(name) name ## _palette16
55#elif SDL_TEXFORMAT == SDL_TEXFORMAT_PALETTE16A
56   #define DEST_TYPE UINT32
57   #define DEST_NAME(name) name ## _32bpp
58   #define TEXSRC_TYPE UINT16
59   #define TEXSRC_TO_DEST(src) \
60      (texsource->palette[src])
61   #define FUNC_NAME(name) name ## _palette16a
62#elif SDL_TEXFORMAT == SDL_TEXFORMAT_RGB15
63   #define DEST_TYPE UINT32
64   #define DEST_NAME(name) name ## _32bpp
65   #define TEXSRC_TYPE UINT16
66   #define TEXSRC_TO_DEST(src) (0xff000000 | ((src & 0x7c00) << 9) | ((src & 0x03e0) << 6) | ((src & 0x001f) << 3) | \
67      ((((src & 0x7c00) << 9) | ((src & 0x03e0) << 6) | ((src & 0x001f) << 3) >> 5) & 0x070707))
68   #define FUNC_NAME(name) name ## _rgb15
69#elif SDL_TEXFORMAT == SDL_TEXFORMAT_RGB15_PALETTED
70   #define DEST_TYPE UINT32
71   #define DEST_NAME(name) name ## _32bpp
72   #define TEXSRC_TYPE UINT16
73   #define TEXSRC_TO_DEST(src) (0xff000000 | texsource->palette[0x40 + ((src >> 10) & 0x1f)] | \
74      texsource->palette[0x20 + ((src >> 5) & 0x1f)] | texsource->palette[0x00 + ((src >> 0) & 0x1f)])
75   #define FUNC_NAME(name) name ## _rgb15_paletted
76#elif SDL_TEXFORMAT == SDL_TEXFORMAT_YUY16 && defined(SDLMAME_MACOSX)
77   #define DEST_TYPE UINT16
78   #define DEST_NAME(name) name ## _16bpp
79   #define TEXSRC_TYPE UINT16
80   #define TEXSRC_TO_DEST(src) ((src >> 8) | (src << 8))
81   #define FUNC_NAME(name) name ## _yuv16_apple
82#elif SDL_TEXFORMAT == SDL_TEXFORMAT_YUY16_PALETTED && defined(SDLMAME_MACOSX)
83   #define DEST_TYPE UINT16
84   #define DEST_NAME(name) name ## _16bpp
85   #define TEXSRC_TYPE UINT16
86   #define TEXSRC_TO_DEST(src) (texsource->palette[0x000 + (src >> 8)] | (src << 8))
87   #define FUNC_NAME(name) name ## _yuv16_paletted_apple
88#elif SDL_TEXFORMAT == SDL_TEXFORMAT_PALETTE16_ARGB1555
89   #define DEST_TYPE UINT16
90   #define DEST_NAME(name) name ## _16bpp
91   #define TEXSRC_TYPE UINT16
92   #define TEXSRC_TO_DEST(src) \
93      ((texsource->palette[src]&0xf80000) >> 9 | \
94         (texsource->palette[src]&0x00f800) >> 6 | \
95         (texsource->palette[src]&0x0000f8) >> 3 | 0x8000)
96   #define FUNC_NAME(name) name ## _palette16_argb1555
97#elif SDL_TEXFORMAT == SDL_TEXFORMAT_RGB15_ARGB1555
98   #define DEST_TYPE UINT16
99   #define DEST_NAME(name) name ## _16bpp
100   #define TEXSRC_TYPE UINT16
101   #define TEXSRC_TO_DEST(src) ((src) | 0x8000)
102   #define FUNC_NAME(name) name ## _rgb15_argb1555
103#elif SDL_TEXFORMAT == SDL_TEXFORMAT_RGB15_PALETTED_ARGB1555
104   #define DEST_TYPE UINT16
105   #define DEST_NAME(name) name ## _16bpp
106   #define TEXSRC_TYPE UINT16
107   #define TEXSRC_TO_DEST(src) \
108      ((texsource->palette[(src) >> 10] & 0xf8) << 7 | \
109         (texsource->palette[((src) >> 5) & 0x1f] & 0xf8) << 2 | \
110         (texsource->palette[(src) & 0x1f] & 0xf8) >> 3 | 0x8000)
111   #define FUNC_NAME(name) name ## _rgb15_paletted_argb1555
112#else
113   #error Unknown SRC_TEXFORMAT
114#endif
trunk/src/osd/sdl/texcopy.c
r28770r28771
1
2#ifndef SDL_TEXFORMAT
3
4#if 0
5INLINE 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
48static int clamp_lu[256+128+128] = { 255 };
49static int coff_cr[256][2] = {  {0, 0} };
50static int coff_cb[256][2] = { {0, 0} };
51
52static 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
71INLINE int clamp(int x) {   return (const int) clamp_lu[(x >> 8) + 128] ; }
72
73INLINE 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
113static 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
153static 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
215static 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
r28770r28771
117117#define GL_DEPTH_COMPONENT32                0x81A7
118118#endif
119119
120//#define OLD_CODE  1
121
122#ifndef OLD_CODE
123120#define HASH_SIZE       ((1<<10)+1)
124121#define OVERFLOW_SIZE   (1<<10)
125#endif
126122
127123// OSD headers
128124#include "osdsdl.h"
r28770r28771
162158
163159struct texture_info;
164160
165#if USE_OPENGL
166typedef void (*texture_copy_func)(texture_info *texture, const render_texinfo *texsource);
167#endif
168
169161/* texture_info holds information about a texture */
170162struct texture_info
171163{
172#ifdef OLD_CODE
173   texture_info *      next;               // next texture in the list
174#endif
175164   HashT               hash;               // hash value for the texture (must be >= pointer size)
176165   UINT32              flags;              // rendering flags
177166   render_texinfo      texinfo;            // copy of the texture info
r28770r28771
187176
188177   UINT32              texture;            // OpenGL texture "name"/ID
189178
190   const GLint *       texProperties;      // texture properties
191   texture_copy_func   texCopyFn;          // texture copy function, !=NULL if !nocopy
192179   GLenum              texTarget;          // OpenGL texture target
193180   int                 texpow2;            // Is this texture pow2
194181
r28770r28771
227214
228215   int             initialized;        // is everything well initialized, i.e. all GL stuff etc.
229216   // 3D info (GL mode only)
230#ifdef OLD_CODE
231   texture_info *  texlist;        // list of active textures
232#else
233217   texture_info *  texhash[HASH_SIZE + OVERFLOW_SIZE];
234#endif
235218   int             last_blendmode;     // previous blendmode
236219   INT32           texture_max_width;      // texture maximum width
237220   INT32           texture_max_height;     // texture maximum height
r28770r28771
292275//  INLINES
293276//============================================================
294277
295#ifdef OLD_CODE
296278INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags)
297279{
298   return (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
299}
300#else
301INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags)
302{
303280   HashT h = (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
304281   //printf("hash %d\n", (int) h % HASH_SIZE);
305282   return (h >> 8) % HASH_SIZE;
306283}
307#endif
308284
309285INLINE void set_blendmode(sdl_info *sdl, int blendmode)
310286{
r28770r28771
383359static int glsl_shader_feature = GLSL_SHADER_FEAT_PLAIN;
384360
385361//============================================================
386//  TEXCOPY FUNCS
387//============================================================
388
389static void texcopy_argb32(texture_info *texture, const render_texinfo *texsource);
390static void texcopy_rgb32(texture_info *texture, const render_texinfo *texsource);
391static void texcopy_rgb32_paletted(texture_info *texture, const render_texinfo *texsource);
392static void texcopy_palette16(texture_info *texture, const render_texinfo *texsource);
393static void texcopy_palette16a(texture_info *texture, const render_texinfo *texsource);
394static void texcopy_rgb15(texture_info *texture, const render_texinfo *texsource);
395static void texcopy_rgb15_paletted(texture_info *texture, const render_texinfo *texsource);
396static void texcopy_yuv16(texture_info *texture, const render_texinfo *texsource);
397static void texcopy_yuv16_paletted(texture_info *texture, const render_texinfo *texsource);
398
399//============================================================
400362//  Textures
401363//============================================================
402364
403static void texture_set_data(texture_info *texture, const render_texinfo *texsource);
365static void texture_set_data(texture_info *texture, const render_texinfo *texsource, UINT32 flags);
404366static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, UINT32 flags);
405367static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim);
406368static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim, int shaderIdx);
r28770r28771
15611523   { FALSE, TRUE  }    // SDL_TEXFORMAT_PALETTE16A
15621524};
15631525
1564// 6 properties (per format)
1565// right order according to glTexImage2D: internal, format, type, ..
1566enum { SDL_TEXFORMAT_INTERNAL, SDL_TEXFORMAT_FORMAT, SDL_TEXFORMAT_TYPE, SDL_TEXFORMAT_PIXEL_SIZE };
1567
1568static 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
1580static 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
1592static 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
1604static 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
1616static 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
16281526//============================================================
16291527//  drawogl_exit
16301528//============================================================
r28770r28771
17061604            texture->texpow2   = (sdl->usetexturerect)?0:sdl->texpoweroftwo;
17071605   }
17081606
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
17291607   // determine if we can skip the copy step
17301608   // 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] &&
17331610         !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] &&
17341611         texture->xprescale == 1 && texture->yprescale == 1 &&
1735         !texture->borderpix &&
1612         !texture->borderpix && !texsource->palette &&
17361613         texsource->rowpixels <= sdl->texture_max_width )
17371614   {
17381615      texture->nocopy = TRUE;
1739      }
1616   }
17401617
17411618   if( texture->type == TEXTURE_TYPE_NONE &&
17421619      sdl->usepbo && !texture->nocopy )
17431620   {
17441621      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;
17471624   }
17481625
17491626   if( texture->type == TEXTURE_TYPE_NONE )
17501627   {
17511628      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   }
17681632}
17691633
17701634INLINE int get_valid_pow2_value(int v, int needPow2)
r28770r28771
18831747         (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE],
18841748         texture->xprescale, texture->yprescale,
18851749         texture->borderpix, texsource->rowpixels, finalwidth, sdl->texture_max_width,
1886         (int)texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]
1750         (int)sizeof(UINT32)
18871751         );
18881752   }
18891753
r28770r28771
21542018
21552019   UINT32 * dummy = NULL;
21562020   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,
21582022               texture->rawwidth_create, texture->rawheight_create,
21592023               0,
2160               texture->texProperties[SDL_TEXFORMAT_FORMAT],
2161               texture->texProperties[SDL_TEXFORMAT_TYPE],
2024               GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
21622025               &_width, &_height, 1) )
21632026   {
21642027      mame_printf_error("cannot create bitmap texture, req: %dx%d, avail: %dx%d - bail out\n",
r28770r28771
21662029      return -1;
21672030   }
21682031
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,
21742035         texture->rawwidth_create, texture->rawheight_create,
21752036         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);
21782038         glFinish(); // should not be necessary, .. but make sure we won't access the memory after free
21792039   free(dummy);
21802040
r28770r28771
23062166      glBindTexture(texture->texTarget, texture->texture);
23072167
23082168      // 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,
23102170            texture->rawwidth_create, texture->rawheight_create,
23112171            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);
23142173
23152174      if ((PRIMFLAG_GET_SCREENTEX(flags)) && video_config.filter)
23162175      {
r28770r28771
23562215
23572216      // set up the PBO dimension, ..
23582217      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),
23602219               NULL, GL_STREAM_DRAW);
23612220   }
23622221
23632222   if ( !texture->nocopy && texture->type!=TEXTURE_TYPE_DYNAMIC )
23642223   {
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));
23662225      texture->data_own=TRUE;
23672226   }
23682227
23692228   // add us to the texture list
2370#ifdef OLD_CODE
2371   texture->next = sdl->texlist;
2372   sdl->texlist = texture;
2373#else
23742229   if (sdl->texhash[texture->hash] == NULL)
23752230      sdl->texhash[texture->hash] = texture;
23762231   else
r28770r28771
23842239         }
23852240      assert(i < HASH_SIZE + OVERFLOW_SIZE);
23862241   }
2387#endif
2242
23882243   if(sdl->usevbo)
23892244   {
23902245      // Generate And Bind The Texture Coordinate Buffer
r28770r28771
24032258}
24042259
24052260//============================================================
2261//  copyline_palette16
2262//============================================================
2263
2264INLINE 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
2283INLINE 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
2302INLINE 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
2344INLINE 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
2382INLINE 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
2427INLINE 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//============================================================
24062500//  texture_set_data
24072501//============================================================
24082502
2409static void texture_set_data(texture_info *texture, const render_texinfo *texsource)
2503static void texture_set_data(texture_info *texture, const render_texinfo *texsource, UINT32 flags)
24102504{
24112505   if ( texture->type == TEXTURE_TYPE_DYNAMIC )
24122506   {
r28770r28771
24202514   // they cannot be both true, thus this cannot lead to the
24212515   // borderpix code below writing to texsource->base .
24222516   if (texture->nocopy)
2517   {
24232518      texture->data = (UINT32 *) texsource->base;
2519   }
24242520
24252521   // always fill non-wrapping textures with an extra pixel on the top
24262522   if (texture->borderpix)
24272523   {
24282524      memset(texture->data, 0,
2429            (texsource->width * texture->xprescale + 2) * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]);
2525            (texsource->width * texture->xprescale + 2) * sizeof(UINT32));
24302526   }
24312527
24322528   // when nescesarry copy (and convert) the data
24332529   if (!texture->nocopy)
24342530   {
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      }
24372565   }
24382566
24392567   // always fill non-wrapping textures with an extra pixel on the bottom
24402568   if (texture->borderpix)
24412569   {
24422570      memset((UINT8 *)texture->data +
2443            (texsource->height + 1) * texture->rawwidth * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE],
2571            (texsource->height + 1) * texture->rawwidth * sizeof(UINT32),
24442572            0,
2445         (texsource->width * texture->xprescale + 2) * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]);
2573         (texsource->width * texture->xprescale + 2) * sizeof(UINT32));
24462574   }
24472575
24482576   if ( texture->type == TEXTURE_TYPE_SHADER )
r28770r28771
24652593
24662594      // and upload the image
24672595      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);
24702597   }
24712598   else if ( texture->type == TEXTURE_TYPE_DYNAMIC )
24722599   {
r28770r28771
24792606
24802607      // kick off the DMA
24812608      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);
24842610   }
24852611   else
24862612   {
r28770r28771
24942620
24952621      // and upload the image
24962622      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);
24992624   }
25002625}
25012626
r28770r28771
25032628//  texture_find
25042629//============================================================
25052630
2506#ifdef OLD_CODE
2507static 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
2528static 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
25402631static int compare_texture_primitive(const texture_info *texture, const render_primitive *prim)
25412632{
25422633   if (texture->texinfo.base == prim->texture.base &&
25432634      texture->texinfo.width == prim->texture.width &&
25442635      texture->texinfo.height == prim->texture.height &&
25452636      texture->texinfo.rowpixels == prim->texture.rowpixels &&
2637      texture->texinfo.palette == prim->texture.palette &&
25462638      ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
25472639      return 1;
25482640   else
r28770r28771
25702662   return NULL;
25712663}
25722664
2573#endif
2574
25752665//============================================================
25762666//  texture_update
25772667//============================================================
r28770r28771
27842874   // if we didn't find one, create a new texture
27852875   if (texture == NULL && prim->texture.base != NULL)
27862876   {
2787         texture = texture_create(window, &prim->texture, prim->flags);
2788
2877      texture = texture_create(window, &prim->texture, prim->flags);
27892878   }
27902879   else if (texture != NULL)
27912880   {
r28770r28771
28232912            texture->texinfo.seqid = prim->texture.seqid;
28242913
28252914            // 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);
28272916            texBound=1;
28282917         }
28292918      }
r28770r28771
29082997   sdl_info *sdl = (sdl_info *) window->dxdata;
29092998   texture_info *texture = NULL;
29102999   int lock=FALSE;
2911#ifdef OLD_CODE
2912   texture_info *next_texture=NULL;
2913#else
29143000   int i;
2915#endif
29163001
29173002   if (sdl == NULL)
29183003      return;
r28770r28771
29363021   glFinish();
29373022   glDisableClientState(GL_VERTEX_ARRAY);
29383023
2939#ifdef OLD_CODE
2940   texture = sdl->texlist;
2941   while (texture)
2942   {
2943      next_texture = texture->next;
2944#else
29453024   i=0;
29463025   while (i<HASH_SIZE+OVERFLOW_SIZE)
29473026   {
r28770r28771
29493028      sdl->texhash[i] = NULL;
29503029      if (texture != NULL)
29513030      {
2952#endif
2953
29543031      if(sdl->usevbo)
29553032      {
29563033         pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) );
r28770r28771
29883065         texture->data_own=FALSE;
29893066      }
29903067      free(texture);
2991#ifdef OLD_CODE
2992      texture = next_texture;
2993   }
2994   sdl->texlist = NULL;
2995#else
29963068      }
29973069      i++;
29983070   }
2999#endif
30003071   if ( sdl->useglsl )
30013072   {
30023073      glsl_shader_free(sdl->glsl);
r28770r28771
30213092   sdl->blittimer = 3;
30223093}
30233094
3024
3025//============================================================
3026//  TEXCOPY FUNCS
3027//============================================================
3028
3029#include "texcopy.c"
trunk/src/osd/sdl/sdl.mak
r28770r28771
772772
773773# drawSDL depends on the core software renderer, so make sure it exists
774774$(SDLOBJ)/drawsdl.o : $(SRC)/emu/rendersw.inc $(SDLSRC)/drawogl.c
775$(SDLOBJ)/drawogl.o : $(SDLSRC)/texcopy.c $(SDLSRC)/texsrc.h
776775
777776# draw13 depends on blit13.h
778777$(SDLOBJ)/draw13.o : $(SDLSRC)/blit13.h

Previous 199869 Revisions Next


© 1997-2024 The MAME Team