2 * $Logfile: /Freespace2/code/Graphics/Shade.cpp $
7 * Routines to shade an area.
10 * Revision 1.1 2002/05/03 03:28:09 root
14 * 2 10/07/98 10:53a Dave
17 * 1 10/07/98 10:49a Dave
19 * 19 3/12/98 5:36p John
20 * Took out any unused shaders. Made shader code take rgbc instead of
21 * matrix and vector since noone used it like a matrix and it would have
22 * been impossible to do in hardware. Made Glide implement a basic
23 * shader for online help.
25 * 18 3/10/98 4:19p John
26 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
27 * & Glide have popups and print screen. Took out all >8bpp software
28 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
29 * support Fred. Made zbuffering key off of functions rather than one
32 * 17 11/30/97 12:18p John
33 * added more 24 & 32-bpp primitives
35 * 16 10/19/97 12:55p John
36 * new code to lock / unlock surfaces for smooth directx integration.
38 * 15 10/09/97 5:23p John
39 * Added support for more 16-bpp functions
41 * 14 10/03/97 12:16p John
42 * optimized the shader. About 50% faster.
44 * 13 10/03/97 9:10a John
45 * added better antialiased line drawer
47 * 12 9/09/97 10:41a Sandeep
48 * fixed warning level 4
50 * 11 6/18/97 12:07p John
51 * fixed some color bugs
53 * 10 6/17/97 7:04p John
54 * added d3d support for gradients.
55 * fixed some color bugs by adding screen signatures instead of watching
56 * flags and palette changes.
58 * 9 5/28/97 8:59a John
59 * Fixed bug with shader not working when switching to fullscreen.
61 * 8 5/12/97 12:27p John
62 * Restructured Graphics Library to add support for multiple renderers.
64 * 7 11/19/96 2:44p Allender
65 * fix up shader for 15 bpp
67 * 6 11/18/96 2:27p Allender
68 * made faster hacked version of shader for 16 bits
70 * 5 11/18/96 1:48p Allender
71 * added 16 bit version of (very slow) shader
73 * 4 11/15/96 3:34p Allender
74 * started on 16 bit support for the shader
76 * 3 10/26/96 1:40p John
77 * Added some now primitives to the 2d library and
78 * cleaned up some old ones.
84 #include "grinternal.h"
89 void grx_create_shader(shader * shade, float r, float g, float b, float c )
96 shade->screen_sig = gr_screen.signature;
102 for (i=0; i<256; i++ ) {
103 Sr = i2fl( gr_palette[i*3+0] );
104 Sg = i2fl( gr_palette[i*3+1] );
105 Sb = i2fl( gr_palette[i*3+2] );
106 Dr = Sr*r + Sg*r + Sb*r + c*256.0f;
107 Dg = Sr*g + Sg*g + Sb*g + c*256.0f;
108 Db = Sr*b + Sg*b + Sb*b + c*256.0f;
109 ri = fl2i(Dr); if ( ri < 0 ) ri = 0; else if (ri>255) ri = 255;
110 gi = fl2i(Dg); if ( gi < 0 ) gi = 0; else if (gi>255) gi = 255;
111 bi = fl2i(Db); if ( bi < 0 ) bi = 0; else if (bi>255) bi = 255;
112 shade->lookup[i] = (unsigned char)(palette_find(ri,gi,bi));
117 void grx_set_shader( shader * shade )
120 if (shade->screen_sig != gr_screen.signature) {
121 gr_create_shader( shade, shade->r, shade->g, shade->b, shade->c );
123 gr_screen.current_shader = *shade;
125 gr_create_shader( &gr_screen.current_shader, 0.0f, 0.0f, 0.0f, 0.0f );
130 void gr8_shade(int x,int y,int w,int h)
136 if (x1 < gr_screen.clip_left) x1 = gr_screen.clip_left;
137 if (x1 > gr_screen.clip_right) x1 = gr_screen.clip_right;
140 if (x2 < gr_screen.clip_left) x2 = gr_screen.clip_left;
141 if (x2 > gr_screen.clip_right) x2 = gr_screen.clip_right;
144 if (y1 < gr_screen.clip_top) y1 = gr_screen.clip_top;
145 if (y1 > gr_screen.clip_bottom) y1 = gr_screen.clip_bottom;
148 if (y2 < gr_screen.clip_top) y2 = gr_screen.clip_top;
149 if (y2 > gr_screen.clip_bottom) y2 = gr_screen.clip_bottom;
158 xlat_table = gr_screen.current_shader.lookup;
162 for (i=0; i<h; i++ ) {
163 ubyte * dp = GR_SCREEN_PTR(ubyte,x1,y1+i);
164 #ifdef USE_INLINE_ASM
169 while ( (uint)dp & 3 ) {
170 *dp = xlat_table[*dp];
176 if ( w1 < 1 ) continue;
179 int left_over = w1 % 4;
191 _asm mov esi, xlat_table
207 _asm mov al, [edx+esi]
208 _asm mov ah, [ebx+esi]
215 _asm mov al, [edx+esi]
216 _asm mov ah, [ebx+esi]
220 _asm mov [edi-4], eax
237 for (int j=0; j<left_over; j++ ) {
238 *dp = xlat_table[*dp];
244 for (int j=0; j<w; j++ ) {
245 *dp = xlat_table[*dp];