@@ -73,7 +73,7 @@ SDL_Shader* SDL_createShader_RW( SDL_Renderer *renderer,
73
73
74
74
}
75
75
76
- void SDL_hint ( sdl_shader_hint flag , void * value ){
76
+ void SDL_shader_hint ( sdl_shader_hint flag , void * value ){
77
77
#ifdef SDL_SHADER_OPENGL
78
78
SDL_GL_hint ( flag , value );
79
79
#endif
@@ -181,52 +181,121 @@ int SDL_destroyShader( SDL_Shader* shader ){
181
181
int SDL_bindShader ( SDL_Shader * shader ){
182
182
return shader -> bindShader ( shader );
183
183
}
184
+ void SDL_updateViewport ( SDL_Shader * shader ){
185
+ shader -> updateViewport ( shader );
186
+ }
187
+ int SDL_renderVertexBuffer ( SDL_Shader * shader , SDL_Vertex * vertices ,
188
+ SDL_Texture * * textures , unsigned num_of_tex )
189
+ {
190
+ unsigned i ;
191
+ SDL_Renderer * renderer = shader -> renderer ;
192
+
193
+ if ( num_of_tex == 0 )
194
+ return 0 ;
195
+ if ( num_of_tex >= 8 )
196
+ return SDL_SetError ("SDL_Shader: only 8 textures are supported" );
197
+ for ( i = 0 ; i < num_of_tex ; i ++ ) {
198
+ if (( textures [i ]-> w != textures [0 ]-> w ||
199
+ textures [i ]-> h != textures [0 ]-> h ) && i != 0 )
200
+ {
201
+ return SDL_SetError ("SDL_Shader: Textures must have the same size" );
202
+ }
203
+ if (( textures [i ]-> format != textures [0 ]-> format ) && i != 0 ) {
204
+ return SDL_SetError ("SDL_Shader: Textures must have the same format" );
205
+ }
206
+ if (renderer != textures [i ]-> renderer ) {
207
+ return SDL_SetError ("SDL_Shader: Texture was not created with this renderer" );
208
+ }
209
+ }
184
210
185
- int SDL_renderCopyShd ( SDL_Shader * shader , SDL_Texture * texture ,
186
- const SDL_Rect * srcrect , const SDL_Rect * dstrect ){
211
+ return shader -> renderCopyShd ( shader , textures , num_of_tex ,
212
+ vertices , vertices -> size );
213
+ }
214
+
215
+ int SDL_renderCopyShdArray ( SDL_Shader * shader , SDL_Texture * * textures ,
216
+ const SDL_Rect * srcrect , const SDL_Rect * dstrect , unsigned num_of_tex )
217
+ {
187
218
188
219
SDL_Renderer * renderer = shader -> renderer ;
220
+
221
+ if (renderer -> hidden ) {
222
+ return 0 ;
223
+ }
224
+
189
225
SDL_Rect real_srcrect = { 0 , 0 , 0 , 0 };
190
226
SDL_Rect real_dstrect = { 0 , 0 , 0 , 0 };
191
-
192
- if (renderer != texture -> renderer ) {
193
- return SDL_SetError ("Texture was not created with this renderer" );
194
- }
227
+ unsigned i ;
195
228
196
229
real_srcrect .x = 0 ;
197
230
real_srcrect .y = 0 ;
198
- real_srcrect .w = texture -> w ;
199
- real_srcrect .h = texture -> h ;
231
+ real_srcrect .w = textures [ 0 ] -> w ;
232
+ real_srcrect .h = textures [ 0 ] -> h ;
200
233
if (srcrect ) {
201
234
if (!SDL_IntersectRect (srcrect , & real_srcrect , & real_srcrect )) {
202
235
return 0 ;
203
236
}
204
237
}
205
238
206
- SDL_RenderGetViewport (renderer , & real_dstrect );
207
- real_dstrect .x = 0 ;
208
- real_dstrect .y = 0 ;
239
+ //XXX bug here
240
+ //SDL_RenderGetViewport(renderer, &real_dstrect);
209
241
if (dstrect ) {
210
- if (!SDL_HasIntersection (dstrect , & real_dstrect )) {
242
+ /* if (!SDL_HasIntersection(dstrect, &real_dstrect)) {
211
243
return 0;
212
- }
244
+ }*/
213
245
real_dstrect = * dstrect ;
214
246
}
215
247
216
- if (texture -> native ) {
217
- texture = texture -> native ;
218
- }
219
-
220
- if (renderer -> hidden ) {
221
- return 0 ;
222
- }
248
+ for ( i = 0 ; i < num_of_tex ; i ++ ) {
249
+ if (textures [i ]-> native ) {
250
+ textures [i ] = textures [i ]-> native ;
251
+ }
252
+ }
223
253
224
- real_dstrect .x *= renderer -> scale .x ;
254
+ /* real_dstrect.x *= renderer->scale.x;
225
255
real_dstrect.y *= renderer->scale.y;
226
256
real_dstrect.w *= renderer->scale.x;
227
- real_dstrect .h *= renderer -> scale .y ;
257
+ real_dstrect.h *= renderer->scale.y;*/
258
+
259
+ SDL_Vertex * vertices = shader -> createVertexBuffer (4 );
260
+
261
+ int r ,g ,b ,a ;
262
+ r = textures [0 ]-> r ;
263
+ g = textures [0 ]-> g ;
264
+ b = textures [0 ]-> b ;
265
+ a = textures [0 ]-> a ;
266
+ vertices -> setVertexColor ( vertices , 0 ,4 , r ,g ,b ,a );
267
+
268
+ vertices -> setVertexPosition ( vertices , 0 ,1 ,
269
+ real_dstrect .x , real_dstrect .y , 0.0f );
270
+ vertices -> setVertexPosition ( vertices , 1 ,1 ,
271
+ (real_dstrect .x + real_dstrect .w ), real_dstrect .y , 0.0f );
272
+ vertices -> setVertexPosition ( vertices , 2 ,1 ,
273
+ real_dstrect .x , (real_dstrect .y + real_dstrect .h ), 0.0f );
274
+ vertices -> setVertexPosition ( vertices , 3 ,1 ,
275
+ (real_dstrect .x + real_dstrect .w ),
276
+ (real_dstrect .y + real_dstrect .h ), 0.0f );
277
+
278
+ float minu , maxu , minv , maxv ;
279
+ minu = real_srcrect .x / textures [0 ]-> w ;
280
+ maxu = (real_srcrect .x + real_srcrect .w ) / textures [0 ]-> w ;
281
+ minv = real_srcrect .y / textures [0 ]-> h ;
282
+ maxv = (real_srcrect .y + real_srcrect .h ) / textures [0 ]-> h ;
283
+ vertices -> setVertexTexCoord ( vertices , 0 ,1 , minu , minv );
284
+ vertices -> setVertexTexCoord ( vertices , 1 ,1 , maxu , minv );
285
+ vertices -> setVertexTexCoord ( vertices , 2 ,1 , minu , maxv );
286
+ vertices -> setVertexTexCoord ( vertices , 3 ,1 , maxu , maxv );
287
+
288
+ int res = SDL_renderVertexBuffer ( shader , vertices , textures , num_of_tex );
289
+ shader -> destroyVertexBuffer ( vertices );
290
+ return res ;
291
+ }
228
292
229
- return shader -> renderCopyShd ( shader , texture , & real_srcrect , & real_dstrect );
293
+
294
+ int SDL_renderCopyShd ( SDL_Shader * shader , SDL_Texture * texture ,
295
+ const SDL_Rect * srcrect , const SDL_Rect * dstrect )
296
+ {
297
+ SDL_Texture * textures [] = {texture };
298
+ return SDL_renderCopyShdArray ( shader , textures , srcrect , dstrect , 1 );
230
299
}
231
300
232
301
char * SDL_Shader_readRW ( SDL_RWops * rwop ) {
0 commit comments