diff modules/sdl.tp @ 279:eb83863fd33e

Store renderer pointer in texture object since the texture can only be used with the renderer it was created with
author Michael Pavone <pavone@retrodev.com>
date Mon, 21 Jul 2014 19:11:15 -0700
parents 1205c7a43cb4
children 0ec4f1b68a38
line wrap: on
line diff
--- a/modules/sdl.tp	Mon Jul 21 12:51:38 2014 -0700
+++ b/modules/sdl.tp	Mon Jul 21 19:11:15 2014 -0700
@@ -105,7 +105,7 @@
 			texOpaque <- make_object: (addr_of: cpointer_meta) NULL 0
 			texOpaque val!: (SDL_CreateTextureFromSurface: (rendOpaque val) (surfOpaque val))
 			if: (texOpaque val) {
-				tex <- ccall: makeTexture 1 (texOpaque castTo: (object ptr))
+				tex <- ccall: makeTexture 1 (rendOpaque castTo: (object ptr)) (texOpaque castTo: (object ptr))
 				mcall: value 2 option tex
 			} else: {
 				mcall: none 1 option
@@ -113,9 +113,10 @@
 		}
 	}
 
-	_makeTexture <- :ptr {
+	_makeTexture <- :rendptr texptr {
 		#{
 			includeSystemHeader: "SDL.h"
+			llProperty: renderer withType: (SDL_Renderer ptr)
 			llProperty: texture withType: (SDL_Texture ptr)
 			llMessage: opaque withVars: {
 				ptr <- cpointer ptr
@@ -125,20 +126,19 @@
 				ptr
 			}
 			llMessage: _ptr_init withVars: {
-				ptr <- cpointer ptr
-			} andCode: :ptr{
-				texture <- ptr val
+				rendptr <- cpointer ptr
+				texptr <- cpointer ptr
+			} andCode: :rendptr texptr{
+				renderer <- rendptr val
+				texture <- texptr val
 				self
 			}
 
-			llMessage: copyTo withVars: {
-				renderer <- object ptr
-				rendOpaque <- cpointer ptr
+			llMessage: copy withVars: {
 				intret <- obj_int32 ptr
-			} andCode: :renderer {
-				rendOpaque <- (mcall: opaque 1 renderer) castTo: (cpointer ptr)
+			} andCode: {
 				intret <- make_object: (addr_of: obj_int32_meta) NULL 0
-				intret num!: (SDL_RenderCopy: (rendOpaque val) texture NULL NULL)
+				intret num!: (SDL_RenderCopy: renderer texture NULL NULL)
 				intret
 			}
 
@@ -146,7 +146,7 @@
 				SDL_DestroyTexture: texture
 				true
 			}
-		} _ptr_init: ptr
+		} _ptr_init: rendptr texptr
 	}
 
 	_makeSurface <- :ptr {