Mercurial > sdl-ios-xcode
annotate src/render/software/SDL_renderer_sw.c @ 5160:657543cc92f9
Making the API simpler, removed the writepixels interface
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 03 Feb 2011 00:22:18 -0800 |
parents | 307ccc9c135e |
children | d72793305335 |
rev | line source |
---|---|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
24 #include "../SDL_sysrender.h" |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
25 #include "../../video/SDL_pixels_c.h" |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 /* SDL surface based renderer implementation */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
30 static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags); |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
31 static void SW_WindowEvent(SDL_Renderer * renderer, |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
32 const SDL_WindowEvent *event); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
33 static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
34 static int SW_SetTextureColorMod(SDL_Renderer * renderer, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
35 SDL_Texture * texture); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
36 static int SW_SetTextureAlphaMod(SDL_Renderer * renderer, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
37 SDL_Texture * texture); |
5144
31e7f523ab3d
Making the API simpler, texture color and alpha modulation are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
38 static int SW_SetTextureBlendMode(SDL_Renderer * renderer, |
31e7f523ab3d
Making the API simpler, texture color and alpha modulation are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents:
5143
diff
changeset
|
39 SDL_Texture * texture); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
40 static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
41 const SDL_Rect * rect, const void *pixels, |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
42 int pitch); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
43 static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
44 const SDL_Rect * rect, void **pixels, int *pitch); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
45 static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
46 static int SW_RenderDrawPoints(SDL_Renderer * renderer, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
47 const SDL_Point * points, int count); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
48 static int SW_RenderDrawLines(SDL_Renderer * renderer, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
49 const SDL_Point * points, int count); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
50 static int SW_RenderFillRects(SDL_Renderer * renderer, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
51 const SDL_Rect ** rects, int count); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
52 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
53 const SDL_Rect * srcrect, const SDL_Rect * dstrect); |
3427
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
54 static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
3435
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3427
diff
changeset
|
55 Uint32 format, void * pixels, int pitch); |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
56 static void SW_RenderPresent(SDL_Renderer * renderer); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
57 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
58 static void SW_DestroyRenderer(SDL_Renderer * renderer); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
61 SDL_RenderDriver SW_RenderDriver = { |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
62 SW_CreateRenderer, |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 "software", |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
65 (SDL_RENDERER_PRESENTVSYNC), |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
66 8, |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 { |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
68 SDL_PIXELFORMAT_RGB555, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
69 SDL_PIXELFORMAT_RGB565, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
70 SDL_PIXELFORMAT_RGB888, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
71 SDL_PIXELFORMAT_BGR888, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
72 SDL_PIXELFORMAT_ARGB8888, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
73 SDL_PIXELFORMAT_RGBA8888, |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
74 SDL_PIXELFORMAT_ABGR8888, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
75 SDL_PIXELFORMAT_BGRA8888 |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
76 }, |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 0, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 0} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 }; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 typedef struct |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 { |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
83 Uint32 format; |
1972
a0e278364188
Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents:
1971
diff
changeset
|
84 SDL_bool updateSize; |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
85 SDL_Texture *texture; |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
86 SDL_Surface surface; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 SDL_Renderer *renderer; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
88 } SW_RenderData; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
90 static SDL_Texture * |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
91 CreateTexture(SDL_Renderer * renderer, Uint32 format, int w, int h) |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
92 { |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
93 SDL_Texture *texture; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
94 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1918
diff
changeset
|
95 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
96 if (!texture) { |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
97 SDL_OutOfMemory(); |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
98 return NULL; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
99 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
100 |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
101 texture->format = format; |
2222
926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
102 texture->access = SDL_TEXTUREACCESS_STREAMING; |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
103 texture->w = w; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
104 texture->h = h; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
105 texture->renderer = renderer; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
106 |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
107 if (renderer->CreateTexture(renderer, texture) < 0) { |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
108 SDL_free(texture); |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
109 return NULL; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
110 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
111 return texture; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
112 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
113 |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
114 static void |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
115 DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
116 { |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
117 renderer->DestroyTexture(renderer, texture); |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
118 SDL_free(texture); |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
119 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
120 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 SDL_Renderer * |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
122 SW_CreateRenderer(SDL_Window * window, Uint32 flags) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 SDL_Renderer *renderer; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
125 SW_RenderData *data; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
126 int i; |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
127 int w, h; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
128 Uint32 format; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 int bpp; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 Uint32 Rmask, Gmask, Bmask, Amask; |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
131 Uint32 renderer_flags; |
1929
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
132 const char *desired_driver; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
134 format = SDL_GetWindowPixelFormat(window); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 if (!SDL_PixelFormatEnumToMasks |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
136 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 SDL_SetError("Unknown display format"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 return NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 if (!renderer) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 return NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
1920
8a162bfdc838
Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents:
1918
diff
changeset
|
147 data = (SW_RenderData *) SDL_calloc(1, sizeof(*data)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 if (!data) { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
149 SW_DestroyRenderer(renderer); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 return NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 } |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
153 renderer->WindowEvent = SW_WindowEvent; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
154 renderer->CreateTexture = SW_CreateTexture; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
155 renderer->SetTextureColorMod = SW_SetTextureColorMod; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
156 renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
157 renderer->SetTextureBlendMode = SW_SetTextureBlendMode; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
158 renderer->UpdateTexture = SW_UpdateTexture; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
159 renderer->LockTexture = SW_LockTexture; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
160 renderer->UnlockTexture = SW_UnlockTexture; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
161 renderer->DestroyTexture = SW_DestroyTexture; |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
162 renderer->RenderDrawPoints = SW_RenderDrawPoints; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
163 renderer->RenderDrawLines = SW_RenderDrawLines; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
164 renderer->RenderFillRects = SW_RenderFillRects; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
165 renderer->RenderCopy = SW_RenderCopy; |
3427
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
166 renderer->RenderReadPixels = SW_RenderReadPixels; |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
167 renderer->RenderPresent = SW_RenderPresent; |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
168 renderer->DestroyRenderer = SW_DestroyRenderer; |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
169 renderer->info = SW_RenderDriver.info; |
2227
b252359547ed
Exported the software renderer texture functions to make easier to create
Sam Lantinga <slouken@libsdl.org>
parents:
2222
diff
changeset
|
170 renderer->info.flags = 0; |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
171 renderer->window = window; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 renderer->driverdata = data; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
174 data->format = format; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 /* Find a render driver that we can use to display data */ |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
177 renderer_flags = 0; |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
178 if (flags & SDL_RENDERER_PRESENTVSYNC) { |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
179 renderer_flags |= SDL_RENDERER_PRESENTVSYNC; |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
180 } |
1929
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
181 desired_driver = SDL_getenv("SDL_VIDEO_RENDERER_SWDRIVER"); |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
182 for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) { |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
183 SDL_RendererInfo info; |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
184 SDL_GetRenderDriverInfo(i, &info); |
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
185 if (SDL_strcmp(info.name, SW_RenderDriver.info.name) == 0) { |
1929
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
186 continue; |
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
187 } |
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
188 if (desired_driver |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
189 && SDL_strcasecmp(desired_driver, info.name) != 0) { |
1929
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
190 continue; |
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
191 } |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
192 data->renderer = SDL_CreateRenderer(window, i, renderer_flags); |
1929
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
193 if (data->renderer) { |
595ac54a8f9f
Added an environment variable to select which driver the software renderer will use.
Sam Lantinga <slouken@libsdl.org>
parents:
1920
diff
changeset
|
194 break; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 } |
5157
fb424691cfc7
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents:
5152
diff
changeset
|
197 if (i == SDL_GetNumRenderDrivers()) { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
198 SW_DestroyRenderer(renderer); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 SDL_SetError("Couldn't find display render driver"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 return NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 } |
1965
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
202 if (data->renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { |
a788656ca29a
SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents:
1930
diff
changeset
|
203 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
204 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
205 |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
206 /* Create the textures we'll use for display */ |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
207 SDL_GetWindowSize(window, &w, &h); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
208 data->texture = CreateTexture(data->renderer, data->format, w, h); |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
209 if (!data->texture) { |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
210 SW_DestroyRenderer(renderer); |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
211 return NULL; |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
212 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
213 |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
214 /* Create a surface we'll use for rendering */ |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
215 data->surface.flags = SDL_PREALLOC; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
216 data->surface.format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
217 if (!data->surface.format) { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
218 SW_DestroyRenderer(renderer); |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
219 return NULL; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
220 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
221 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 return renderer; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
225 static SDL_Texture * |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
226 SW_ActivateRenderer(SDL_Renderer * renderer) |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
227 { |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
228 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
229 SDL_Window *window = renderer->window; |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
230 |
1972
a0e278364188
Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents:
1971
diff
changeset
|
231 if (data->updateSize) { |
a0e278364188
Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents:
1971
diff
changeset
|
232 /* Recreate the textures for the new window size */ |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
233 int w, h; |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
234 if (data->texture) { |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
235 DestroyTexture(data->renderer, data->texture); |
1972
a0e278364188
Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents:
1971
diff
changeset
|
236 } |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
237 SDL_GetWindowSize(window, &w, &h); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
238 data->texture = CreateTexture(data->renderer, data->format, w, h); |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
239 if (data->texture) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
240 data->updateSize = SDL_FALSE; |
1972
a0e278364188
Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents:
1971
diff
changeset
|
241 } |
a0e278364188
Fixed bug recreating OpenGL textures on window resize
Sam Lantinga <slouken@libsdl.org>
parents:
1971
diff
changeset
|
242 } |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
243 return data->texture; |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
244 } |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
245 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
246 static void |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
247 SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
248 { |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
249 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
250 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
251 if (event->event == SDL_WINDOWEVENT_RESIZED) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
252 data->updateSize = SDL_TRUE; |
1970
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
253 } |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
254 } |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
255 |
db3ba6c0d0df
Allow the render context to do necessary work when the video mode changes.
Sam Lantinga <slouken@libsdl.org>
parents:
1965
diff
changeset
|
256 static int |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
257 SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 { |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
259 int bpp; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
260 Uint32 Rmask, Gmask, Bmask, Amask; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
261 |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
262 if (!SDL_PixelFormatEnumToMasks |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
263 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
264 SDL_SetError("Unknown texture format"); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
265 return -1; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
266 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
268 texture->driverdata = |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
269 SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask, |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
270 Bmask, Amask); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
271 SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g, |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
272 texture->b); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
273 SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
274 SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
276 if (texture->access == SDL_TEXTUREACCESS_STATIC) { |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
277 SDL_SetSurfaceRLE(texture->driverdata, 1); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 if (!texture->driverdata) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 return 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 static int |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
287 SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
288 { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2262
diff
changeset
|
289 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2262
diff
changeset
|
290 return SDL_SetSurfaceColorMod(surface, texture->r, texture->g, |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2262
diff
changeset
|
291 texture->b); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
292 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
293 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
294 static int |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
295 SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
296 { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2262
diff
changeset
|
297 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2262
diff
changeset
|
298 return SDL_SetSurfaceAlphaMod(surface, texture->a); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
299 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
300 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
301 static int |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
302 SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
303 { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2262
diff
changeset
|
304 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2262
diff
changeset
|
305 return SDL_SetSurfaceBlendMode(surface, texture->blendMode); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
306 } |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
307 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
308 static int |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
309 SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
310 const SDL_Rect * rect, const void *pixels, int pitch) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 { |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
312 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
313 Uint8 *src, *dst; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
314 int row; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
315 size_t length; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
317 src = (Uint8 *) pixels; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
318 dst = (Uint8 *) surface->pixels + |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
319 rect->y * surface->pitch + |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
320 rect->x * surface->format->BytesPerPixel; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
321 length = rect->w * surface->format->BytesPerPixel; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
322 for (row = 0; row < rect->h; ++row) { |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
323 SDL_memcpy(dst, src, length); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
324 src += pitch; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
325 dst += surface->pitch; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 } |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
327 return 0; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 static int |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
331 SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
332 const SDL_Rect * rect, void **pixels, int *pitch) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 { |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
334 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
336 *pixels = |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
337 (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch + |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
338 rect->x * surface->format->BytesPerPixel); |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
339 *pitch = surface->pitch; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
340 return 0; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 static void |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
344 SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 static int |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
349 SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
350 int count) |
2901 | 351 { |
352 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; | |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
353 SDL_Texture *texture = SW_ActivateRenderer(renderer); |
2904
fa81cc1ef3d0
Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
354 SDL_Rect rect; |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
355 int i; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
356 int x, y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
357 int status = 0; |
2901 | 358 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
359 if (!texture) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
360 return -1; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
361 } |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
362 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
363 /* Get the smallest rectangle that contains everything */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
364 rect.x = 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
365 rect.y = 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
366 rect.w = texture->w; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
367 rect.h = texture->h; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
368 if (!SDL_EnclosePoints(points, count, &rect, &rect)) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
369 /* Nothing to draw */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
370 return 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
371 } |
2904
fa81cc1ef3d0
Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
372 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
373 if (data->renderer->LockTexture(data->renderer, texture, &rect, |
2901 | 374 &data->surface.pixels, |
375 &data->surface.pitch) < 0) { | |
376 return -1; | |
377 } | |
378 | |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
379 data->surface.clip_rect.w = data->surface.w = rect.w; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
380 data->surface.clip_rect.h = data->surface.h = rect.h; |
2904
fa81cc1ef3d0
Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
381 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
382 /* Draw the points! */ |
5143
e743b9c3f6d6
Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents:
5141
diff
changeset
|
383 if (renderer->blendMode == SDL_BLENDMODE_NONE) { |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
384 Uint32 color = SDL_MapRGBA(data->surface.format, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
385 renderer->r, renderer->g, renderer->b, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
386 renderer->a); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
387 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
388 for (i = 0; i < count; ++i) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
389 x = points[i].x - rect.x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
390 y = points[i].y - rect.y; |
2901 | 391 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
392 status = SDL_DrawPoint(&data->surface, x, y, color); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
393 } |
2901 | 394 } else { |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
395 for (i = 0; i < count; ++i) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
396 x = points[i].x - rect.x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
397 y = points[i].y - rect.y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
398 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
399 status = SDL_BlendPoint(&data->surface, x, y, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
400 renderer->blendMode, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
401 renderer->r, renderer->g, renderer->b, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
402 renderer->a); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
403 } |
2901 | 404 } |
405 | |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
406 data->renderer->UnlockTexture(data->renderer, texture); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
407 |
2901 | 408 return status; |
409 } | |
410 | |
411 static int | |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
412 SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
413 int count) |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
414 { |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
415 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
416 SDL_Texture *texture = SW_ActivateRenderer(renderer); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
417 SDL_Rect clip, rect; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
418 int i; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
419 int x1, y1, x2, y2; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
420 int status = 0; |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
421 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
422 if (!texture) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
423 return -1; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
424 } |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
425 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
426 /* Get the smallest rectangle that contains everything */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
427 clip.x = 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
428 clip.y = 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
429 clip.w = texture->w; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
430 clip.h = texture->h; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
431 SDL_EnclosePoints(points, count, NULL, &rect); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
432 if (!SDL_IntersectRect(&rect, &clip, &rect)) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
433 /* Nothing to draw */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
434 return 0; |
2904
fa81cc1ef3d0
Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
435 } |
fa81cc1ef3d0
Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
436 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
437 if (data->renderer->LockTexture(data->renderer, texture, &rect, |
2891 | 438 &data->surface.pixels, |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
439 &data->surface.pitch) < 0) { |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
440 return -1; |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
441 } |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
442 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
443 data->surface.clip_rect.w = data->surface.w = rect.w; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
444 data->surface.clip_rect.h = data->surface.h = rect.h; |
2904
fa81cc1ef3d0
Fixed clip_rect when drawing points and lines with software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
445 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
446 /* Draw the points! */ |
5143
e743b9c3f6d6
Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents:
5141
diff
changeset
|
447 if (renderer->blendMode == SDL_BLENDMODE_NONE) { |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
448 Uint32 color = SDL_MapRGBA(data->surface.format, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
449 renderer->r, renderer->g, renderer->b, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
450 renderer->a); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
451 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
452 for (i = 1; i < count; ++i) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
453 x1 = points[i-1].x - rect.x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
454 y1 = points[i-1].y - rect.y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
455 x2 = points[i].x - rect.x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
456 y2 = points[i].y - rect.y; |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
457 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
458 status = SDL_DrawLine(&data->surface, x1, y1, x2, y2, color); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
459 } |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
460 } else { |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
461 for (i = 1; i < count; ++i) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
462 x1 = points[i-1].x - rect.x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
463 y1 = points[i-1].y - rect.y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
464 x2 = points[i].x - rect.x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
465 y2 = points[i].y - rect.y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
466 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
467 status = SDL_BlendLine(&data->surface, x1, y1, x2, y2, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
468 renderer->blendMode, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
469 renderer->r, renderer->g, renderer->b, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
470 renderer->a); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
471 } |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
472 } |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
473 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
474 data->renderer->UnlockTexture(data->renderer, texture); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
475 |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
476 return status; |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
477 } |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
478 |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
479 static int |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
480 SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
481 int count) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
483 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
484 SDL_Texture *texture = SW_ActivateRenderer(renderer); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
485 SDL_Rect clip, rect; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
486 Uint32 color = 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
487 int i; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
488 int status = 0; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
490 if (!texture) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
491 return -1; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
492 } |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
493 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
494 clip.x = 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
495 clip.y = 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
496 clip.w = texture->w; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
497 clip.h = texture->h; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 |
5143
e743b9c3f6d6
Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents:
5141
diff
changeset
|
499 if (renderer->blendMode == SDL_BLENDMODE_NONE) { |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
500 color = SDL_MapRGBA(data->surface.format, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
501 renderer->r, renderer->g, renderer->b, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
502 renderer->a); |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
503 } |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
504 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
505 for (i = 0; i < count; ++i) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
506 if (!SDL_IntersectRect(rects[i], &clip, &rect)) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
507 /* Nothing to draw */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
508 continue; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
509 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
510 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
511 if (data->renderer->LockTexture(data->renderer, texture, &rect, |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
512 &data->surface.pixels, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
513 &data->surface.pitch) < 0) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
514 return -1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
515 } |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
516 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
517 data->surface.clip_rect.w = data->surface.w = rect.w; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
518 data->surface.clip_rect.h = data->surface.h = rect.h; |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
519 |
5143
e743b9c3f6d6
Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents:
5141
diff
changeset
|
520 if (renderer->blendMode == SDL_BLENDMODE_NONE) { |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
521 status = SDL_FillRect(&data->surface, NULL, color); |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
522 } else { |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
523 status = SDL_BlendFillRect(&data->surface, NULL, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
524 renderer->blendMode, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
525 renderer->r, renderer->g, renderer->b, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
526 renderer->a); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
527 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
528 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3435
diff
changeset
|
529 data->renderer->UnlockTexture(data->renderer, texture); |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2884
diff
changeset
|
530 } |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
531 return status; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
534 static int |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
535 SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
536 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
537 { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
538 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
539 SDL_Surface *surface; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
540 SDL_Rect real_srcrect; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
541 SDL_Rect real_dstrect; |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
542 int status; |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
543 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
544 if (!SW_ActivateRenderer(renderer)) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
545 return -1; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
546 } |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
547 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
548 if (data->renderer->LockTexture(data->renderer, data->texture, dstrect, |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
549 &data->surface.pixels, |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
550 &data->surface.pitch) < 0) { |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
551 return -1; |
1897
c2a27da60b18
Solved the performance problems by introducing the concept of a single-buffered
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
552 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
553 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
554 surface = (SDL_Surface *) texture->driverdata; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
555 real_srcrect = *srcrect; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
556 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
557 data->surface.w = dstrect->w; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
558 data->surface.h = dstrect->h; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
559 data->surface.clip_rect.w = dstrect->w; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
560 data->surface.clip_rect.h = dstrect->h; |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
561 real_dstrect = data->surface.clip_rect; |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1972
diff
changeset
|
562 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
563 status = SDL_LowerBlit(surface, &real_srcrect, &data->surface, &real_dstrect); |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
564 data->renderer->UnlockTexture(data->renderer, data->texture); |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
565 return status; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 |
3427
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
568 static int |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
569 SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
3435
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3427
diff
changeset
|
570 Uint32 format, void * pixels, int pitch) |
3427
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
571 { |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
572 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
573 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
574 if (!SW_ActivateRenderer(renderer)) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
575 return -1; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
576 } |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
577 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
578 if (data->renderer->LockTexture(data->renderer, data->texture, rect, |
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
579 &data->surface.pixels, |
3427
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
580 &data->surface.pitch) < 0) { |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
581 return -1; |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
582 } |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
583 |
3435
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3427
diff
changeset
|
584 SDL_ConvertPixels(rect->w, rect->h, |
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3427
diff
changeset
|
585 data->format, data->surface.pixels, data->surface.pitch, |
9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3427
diff
changeset
|
586 format, pixels, pitch); |
3427
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
587 |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
588 data->renderer->UnlockTexture(data->renderer, data->texture); |
3427
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
589 return 0; |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
590 } |
36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents:
3053
diff
changeset
|
591 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
592 static void |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
593 SW_RenderPresent(SDL_Renderer * renderer) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
594 { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
595 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
596 SDL_Texture *texture = SW_ActivateRenderer(renderer); |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
597 SDL_Rect rect; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
598 |
5150
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
599 if (!texture) { |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
600 return; |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
601 } |
ad50b3db78bd
The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents:
5145
diff
changeset
|
602 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 /* Send the data to the display */ |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
604 rect.x = 0; |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
605 rect.y = 0; |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
606 rect.w = texture->w; |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
607 rect.h = texture->h; |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
608 data->renderer->RenderCopy(data->renderer, texture, &rect, &rect); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
609 data->renderer->RenderPresent(data->renderer); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
610 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
611 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
612 static void |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
613 SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
614 { |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
615 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
616 |
5159
307ccc9c135e
Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
5157
diff
changeset
|
617 SDL_FreeSurface(surface); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
618 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
619 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
620 static void |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
621 SW_DestroyRenderer(SDL_Renderer * renderer) |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
622 { |
1918
092bd3a019c5
Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents:
1907
diff
changeset
|
623 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3599
diff
changeset
|
624 SDL_Window *window = renderer->window; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
626 if (data) { |
5145
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
627 if (data->texture) { |
c8e049de174c
Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents:
5144
diff
changeset
|
628 DestroyTexture(data->renderer, data->texture); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 } |
1907
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
630 if (data->surface.format) { |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
631 SDL_FreeFormat(data->surface.format); |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
632 } |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
633 if (data->renderer) { |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
634 data->renderer->DestroyRenderer(data->renderer); |
06c27a737b7a
Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
1897
diff
changeset
|
635 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
636 SDL_free(data); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
637 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
638 SDL_free(renderer); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
639 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
640 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
641 /* vi: set ts=4 sw=4 expandtab: */ |