Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fb3dfx.c @ 1557:61c237f69076
Fixed bug #90
The palette -> RGBA blit wasn't following the rule:
* RGB->RGBA:
* SDL_SRCALPHA not set:
* copy RGB, set destination alpha to source per-surface alpha value.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 20 Mar 2006 06:37:58 +0000 |
parents | d910939febfa |
children | 14717b52abc0 |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
19 Sam Lantinga |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
20 slouken@libsdl.org |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 #include "SDL_video.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
25 #include "../SDL_blit.h" |
0 | 26 #include "SDL_fb3dfx.h" |
27 #include "3dfx_mmio.h" | |
28 | |
29 | |
30 /* Wait for vertical retrace */ | |
31 static void WaitVBL(_THIS) | |
32 { | |
33 /* find start of retrace */ | |
34 tdfx_waitidle(); | |
35 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == STATUS_RETRACE ) | |
36 ; | |
37 /* wait until we're past the start */ | |
38 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0 ) | |
39 ; | |
40 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
41 static void WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
42 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
43 tdfx_waitidle(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
44 } |
0 | 45 |
46 /* Sets video mem colorkey and accelerated blit function */ | |
47 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) | |
48 { | |
49 return(0); | |
50 } | |
51 | |
52 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) | |
53 { | |
54 int bpp; | |
55 char *dst_base; | |
56 Uint32 format; | |
57 int dstX, dstY; | |
58 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
59 /* Don't blit to the display surface when switched away */ |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
60 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
61 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
62 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
63 |
0 | 64 /* Set the destination pixel format */ |
65 dst_base = (char *)((char *)dst->pixels - mapped_mem); | |
66 bpp = dst->format->BitsPerPixel; | |
67 format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
68 | |
69 /* Calculate source and destination base coordinates */ | |
70 dstX = rect->x; | |
71 dstY = rect->y; | |
72 | |
73 /* Execute the fill command */ | |
74 tdfx_wait(6); | |
75 tdfx_out32(DSTBASE, (Uint32)dst_base); | |
76 tdfx_out32(DSTFORMAT, format); | |
77 tdfx_out32(COLORFORE, color); | |
78 tdfx_out32(COMMAND_2D, COMMAND_2D_FILLRECT); | |
79 tdfx_out32(DSTSIZE, rect->w | (rect->h << 16)); | |
80 tdfx_out32(LAUNCH_2D, dstX | (dstY << 16)); | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
82 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
83 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
84 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
85 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
86 } |
0 | 87 return(0); |
88 } | |
89 | |
90 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
91 SDL_Surface *dst, SDL_Rect *dstrect) | |
92 { | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
93 SDL_VideoDevice *this = current_video; |
0 | 94 int bpp; |
95 Uint32 src_format; | |
96 Uint32 dst_format; | |
97 char *src_base; | |
98 char *dst_base; | |
99 int srcX, srcY; | |
100 int dstX, dstY; | |
101 Uint32 blitop; | |
102 Uint32 use_colorkey; | |
103 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
104 /* Don't blit to the display surface when switched away */ |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
105 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
106 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
107 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
108 |
0 | 109 /* Set the source and destination pixel format */ |
110 src_base = (char *)((char *)src->pixels - mapped_mem); | |
111 bpp = src->format->BitsPerPixel; | |
112 src_format = src->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
113 dst_base = (char *)((char *)dst->pixels - mapped_mem); | |
114 bpp = dst->format->BitsPerPixel; | |
115 dst_format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
116 | |
117 srcX = srcrect->x; | |
118 srcY = srcrect->y; | |
119 dstX = dstrect->x; | |
120 dstY = dstrect->y; | |
121 | |
122 /* Assemble the blit operation */ | |
123 blitop = COMMAND_2D_BITBLT | (0xCC << 24); | |
124 if ( srcX <= dstX ) { | |
125 blitop |= BIT(14); | |
126 srcX += (dstrect->w - 1); | |
127 dstX += (dstrect->w - 1); | |
128 } | |
129 if ( srcY <= dstY ) { | |
130 blitop |= BIT(15); | |
131 srcY += (dstrect->h - 1); | |
132 dstY += (dstrect->h - 1); | |
133 } | |
134 | |
135 /* Perform the blit! */ | |
136 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
137 tdfx_wait(3); | |
138 tdfx_out32(SRCCOLORKEYMIN, src->format->colorkey); | |
139 tdfx_out32(SRCCOLORKEYMAX, src->format->colorkey); | |
140 tdfx_out32(ROP_2D, 0xAA00); | |
141 use_colorkey = 1; | |
142 } else { | |
143 use_colorkey = 0; | |
144 } | |
145 tdfx_wait(9); | |
146 tdfx_out32(SRCBASE, (Uint32)src_base); | |
147 tdfx_out32(SRCFORMAT, src_format); | |
148 tdfx_out32(DSTBASE, (Uint32)dst_base); | |
149 tdfx_out32(DSTFORMAT, src_format); | |
150 tdfx_out32(COMMAND_2D, blitop); | |
151 tdfx_out32(COMMANDEXTRA_2D, use_colorkey); | |
152 tdfx_out32(DSTSIZE, dstrect->w | (dstrect->h << 16)); | |
153 tdfx_out32(DSTXY, dstX | (dstY << 16)); | |
154 tdfx_out32(LAUNCH_2D, srcX | (srcY << 16)); | |
155 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
156 FB_AddBusySurface(src); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
157 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
158 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
159 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
160 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
161 } |
0 | 162 return(0); |
163 } | |
164 | |
165 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) | |
166 { | |
167 int accelerated; | |
168 | |
169 /* Set initial acceleration on */ | |
170 src->flags |= SDL_HWACCEL; | |
171 | |
172 /* Set the surface attributes */ | |
173 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | |
174 if ( ! this->info.blit_hw_A ) { | |
175 src->flags &= ~SDL_HWACCEL; | |
176 } | |
177 } | |
178 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
179 if ( ! this->info.blit_hw_CC ) { | |
180 src->flags &= ~SDL_HWACCEL; | |
181 } | |
182 } | |
183 | |
184 /* Check to see if final surface blit is accelerated */ | |
185 accelerated = !!(src->flags & SDL_HWACCEL); | |
186 if ( accelerated ) { | |
187 src->map->hw_blit = HWAccelBlit; | |
188 } | |
189 return(accelerated); | |
190 } | |
191 | |
192 void FB_3DfxAccel(_THIS, __u32 card) | |
193 { | |
194 /* We have hardware accelerated surface functions */ | |
195 this->CheckHWBlit = CheckHWBlit; | |
196 wait_vbl = WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
197 wait_idle = WaitIdle; |
0 | 198 |
199 /* Reset the 3Dfx controller */ | |
200 tdfx_out32(BRESERROR0, 0); | |
201 tdfx_out32(BRESERROR1, 0); | |
202 | |
203 /* The 3Dfx has an accelerated color fill */ | |
204 this->info.blit_fill = 1; | |
205 this->FillHWRect = FillHWRect; | |
206 | |
207 /* The 3Dfx has accelerated normal and colorkey blits */ | |
208 this->info.blit_hw = 1; | |
209 this->info.blit_hw_CC = 1; | |
210 this->SetHWColorKey = SetHWColorKey; | |
211 } |