Mercurial > sdl-ios-xcode
annotate src/render/software/SDL_drawline.c @ 5231:710d00cb3a6a
Made it possible to disable the rendering subsystem with configure --disable-render
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 08 Feb 2011 10:04:09 -0800 |
parents | 4d39eeaad00b |
children | b530ef003506 |
rev | line source |
---|---|
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
5231
710d00cb3a6a
Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents:
5169
diff
changeset
|
24 #if !SDL_RENDER_DISABLED |
710d00cb3a6a
Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents:
5169
diff
changeset
|
25 |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
2896
diff
changeset
|
26 #include "SDL_draw.h" |
5166
d72793305335
Making the API simpler, moved the surface drawing functions to the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
27 #include "SDL_drawline.h" |
5169
4d39eeaad00b
Added a way to get a framebuffer interface for a window, and also a way to create a software renderer for an arbitrary surface.
Sam Lantinga <slouken@libsdl.org>
parents:
5166
diff
changeset
|
28 #include "SDL_drawpoint.h" |
5166
d72793305335
Making the API simpler, moved the surface drawing functions to the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
29 |
2890
1863c8b59658
Placeholder for line drawing algorithm (current code doesn't work)
Sam Lantinga <slouken@libsdl.org>
parents:
2888
diff
changeset
|
30 |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
31 static void |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
32 SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
33 SDL_bool draw_end) |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
34 { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
35 if (y1 == y2) { |
3671
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
36 //HLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
37 int length; |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
38 int pitch = (dst->pitch / dst->format->BytesPerPixel); |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
39 Uint8 *pixel; |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
40 if (x1 <= x2) { |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
41 pixel = (Uint8 *)dst->pixels + y1 * pitch + x1; |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
42 length = draw_end ? (x2-x1+1) : (x2-x1); |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
43 } else { |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
44 pixel = (Uint8 *)dst->pixels + y1 * pitch + x2; |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
45 if (!draw_end) { |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
46 ++pixel; |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
47 } |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
48 length = draw_end ? (x1-x2+1) : (x1-x2); |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
49 } |
0d6f520c0eb9
Fixed building under Visual Studio
Sam Lantinga <slouken@libsdl.org>
parents:
3596
diff
changeset
|
50 SDL_memset(pixel, color, length); |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
51 } else if (x1 == x2) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
52 VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
53 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
54 DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
55 } else { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
56 BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
57 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
58 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
59 |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
60 static void |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
61 SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
62 SDL_bool draw_end) |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
63 { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
64 if (y1 == y2) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
65 HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
66 } else if (x1 == x2) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
67 VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
68 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
69 DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
70 } else { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
71 Uint8 _r, _g, _b, _a; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
72 const SDL_PixelFormat * fmt = dst->format; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
73 SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
74 if (fmt->Rmask == 0x7C00) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
75 AALINE(x1, y1, x2, y2, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
76 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
77 draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
78 } else if (fmt->Rmask == 0xF800) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
79 AALINE(x1, y1, x2, y2, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
80 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
81 draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
82 } else { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
83 AALINE(x1, y1, x2, y2, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
84 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
85 draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
86 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
87 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
88 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
89 |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
90 static void |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
91 SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
92 SDL_bool draw_end) |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
93 { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
94 if (y1 == y2) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
95 HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
96 } else if (x1 == x2) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
97 VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
98 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
99 DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
100 } else { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
101 Uint8 _r, _g, _b, _a; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
102 const SDL_PixelFormat * fmt = dst->format; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
103 SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
104 if (fmt->Rmask == 0x00FF0000) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
105 if (!fmt->Amask) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
106 AALINE(x1, y1, x2, y2, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
107 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
108 draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
109 } else { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
110 AALINE(x1, y1, x2, y2, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
111 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
112 draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
113 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
114 } else { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
115 AALINE(x1, y1, x2, y2, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
116 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
117 draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
118 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
119 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
120 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
121 |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
122 typedef void (*DrawLineFunc) (SDL_Surface * dst, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
123 int x1, int y1, int x2, int y2, |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
124 Uint32 color, SDL_bool draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
125 |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
126 static DrawLineFunc |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
127 SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt) |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
128 { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
129 switch (fmt->BytesPerPixel) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
130 case 1: |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
131 if (fmt->BitsPerPixel < 8) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
132 break; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
133 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
134 return SDL_DrawLine1; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
135 case 2: |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
136 return SDL_DrawLine2; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
137 case 4: |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
138 return SDL_DrawLine4; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
139 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
140 return NULL; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
141 } |
2890
1863c8b59658
Placeholder for line drawing algorithm (current code doesn't work)
Sam Lantinga <slouken@libsdl.org>
parents:
2888
diff
changeset
|
142 |
2901 | 143 int |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 { |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
146 DrawLineFunc func; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
147 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
148 if (!dst) { |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
149 SDL_SetError("SDL_DrawLine(): Passed NULL destination surface"); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
150 return -1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
151 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
152 |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
153 func = SDL_CalculateDrawLineFunc(dst->format); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
154 if (!func) { |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 SDL_SetError("SDL_DrawLine(): Unsupported surface format"); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
156 return -1; |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 } |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 /* Perform clipping */ |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
160 /* FIXME: We don't actually want to clip, as it may change line slope */ |
2910
27d8b12e0e8e
Fixed argument order to the line clipping routine
Sam Lantinga <slouken@libsdl.org>
parents:
2909
diff
changeset
|
161 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
162 return 0; |
2909 | 163 } |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
165 func(dst, x1, y1, x2, y2, color, SDL_TRUE); |
2890
1863c8b59658
Placeholder for line drawing algorithm (current code doesn't work)
Sam Lantinga <slouken@libsdl.org>
parents:
2888
diff
changeset
|
166 return 0; |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 } |
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
169 int |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
170 SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
171 Uint32 color) |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
172 { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
173 int i; |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
174 int x1, y1; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
175 int x2, y2; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
176 SDL_bool draw_end; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
177 DrawLineFunc func; |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
178 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
179 if (!dst) { |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
180 SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
181 return -1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
182 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
183 |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
184 func = SDL_CalculateDrawLineFunc(dst->format); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
185 if (!func) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
186 SDL_SetError("SDL_DrawLines(): Unsupported surface format"); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
187 return -1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
188 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
189 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
190 for (i = 1; i < count; ++i) { |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
191 x1 = points[i-1].x; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
192 y1 = points[i-1].y; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
193 x2 = points[i].x; |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
194 y2 = points[i].y; |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
195 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
196 /* Perform clipping */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
197 /* FIXME: We don't actually want to clip, as it may change line slope */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
198 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
199 continue; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
200 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
201 |
3596
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
202 /* Draw the end if it was clipped */ |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
203 draw_end = (x2 != points[i].x || y2 != points[i].y); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
204 |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
205 func(dst, x1, y1, x2, y2, color, draw_end); |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
206 } |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
207 if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { |
f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents:
3594
diff
changeset
|
208 SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color); |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
209 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
210 return 0; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
211 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
2910
diff
changeset
|
212 |
5231
710d00cb3a6a
Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents:
5169
diff
changeset
|
213 #endif /* !SDL_RENDER_DISABLED */ |
710d00cb3a6a
Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents:
5169
diff
changeset
|
214 |
2888
32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 /* vi: set ts=4 sw=4 expandtab: */ |