2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Graphics/Shade.cpp $
15 * Routines to shade an area.
18 * Revision 1.2 2002/06/09 04:41:18 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:09 root
25 * 2 10/07/98 10:53a Dave
28 * 1 10/07/98 10:49a Dave
30 * 19 3/12/98 5:36p John
31 * Took out any unused shaders. Made shader code take rgbc instead of
32 * matrix and vector since noone used it like a matrix and it would have
33 * been impossible to do in hardware. Made Glide implement a basic
34 * shader for online help.
36 * 18 3/10/98 4:19p John
37 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
38 * & Glide have popups and print screen. Took out all >8bpp software
39 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
40 * support Fred. Made zbuffering key off of functions rather than one
43 * 17 11/30/97 12:18p John
44 * added more 24 & 32-bpp primitives
46 * 16 10/19/97 12:55p John
47 * new code to lock / unlock surfaces for smooth directx integration.
49 * 15 10/09/97 5:23p John
50 * Added support for more 16-bpp functions
52 * 14 10/03/97 12:16p John
53 * optimized the shader. About 50% faster.
55 * 13 10/03/97 9:10a John
56 * added better antialiased line drawer
58 * 12 9/09/97 10:41a Sandeep
59 * fixed warning level 4
61 * 11 6/18/97 12:07p John
62 * fixed some color bugs
64 * 10 6/17/97 7:04p John
65 * added d3d support for gradients.
66 * fixed some color bugs by adding screen signatures instead of watching
67 * flags and palette changes.
69 * 9 5/28/97 8:59a John
70 * Fixed bug with shader not working when switching to fullscreen.
72 * 8 5/12/97 12:27p John
73 * Restructured Graphics Library to add support for multiple renderers.
75 * 7 11/19/96 2:44p Allender
76 * fix up shader for 15 bpp
78 * 6 11/18/96 2:27p Allender
79 * made faster hacked version of shader for 16 bits
81 * 5 11/18/96 1:48p Allender
82 * added 16 bit version of (very slow) shader
84 * 4 11/15/96 3:34p Allender
85 * started on 16 bit support for the shader
87 * 3 10/26/96 1:40p John
88 * Added some now primitives to the 2d library and
89 * cleaned up some old ones.
95 #include "grinternal.h"
100 void grx_create_shader(shader * shade, float r, float g, float b, float c )
107 shade->screen_sig = gr_screen.signature;
113 for (i=0; i<256; i++ ) {
114 Sr = i2fl( gr_palette[i*3+0] );
115 Sg = i2fl( gr_palette[i*3+1] );
116 Sb = i2fl( gr_palette[i*3+2] );
117 Dr = Sr*r + Sg*r + Sb*r + c*256.0f;
118 Dg = Sr*g + Sg*g + Sb*g + c*256.0f;
119 Db = Sr*b + Sg*b + Sb*b + c*256.0f;
120 ri = fl2i(Dr); if ( ri < 0 ) ri = 0; else if (ri>255) ri = 255;
121 gi = fl2i(Dg); if ( gi < 0 ) gi = 0; else if (gi>255) gi = 255;
122 bi = fl2i(Db); if ( bi < 0 ) bi = 0; else if (bi>255) bi = 255;
123 shade->lookup[i] = (unsigned char)(palette_find(ri,gi,bi));
128 void grx_set_shader( shader * shade )
131 if (shade->screen_sig != gr_screen.signature) {
132 gr_create_shader( shade, shade->r, shade->g, shade->b, shade->c );
134 gr_screen.current_shader = *shade;
136 gr_create_shader( &gr_screen.current_shader, 0.0f, 0.0f, 0.0f, 0.0f );
141 void gr8_shade(int x,int y,int w,int h)
147 if (x1 < gr_screen.clip_left) x1 = gr_screen.clip_left;
148 if (x1 > gr_screen.clip_right) x1 = gr_screen.clip_right;
151 if (x2 < gr_screen.clip_left) x2 = gr_screen.clip_left;
152 if (x2 > gr_screen.clip_right) x2 = gr_screen.clip_right;
155 if (y1 < gr_screen.clip_top) y1 = gr_screen.clip_top;
156 if (y1 > gr_screen.clip_bottom) y1 = gr_screen.clip_bottom;
159 if (y2 < gr_screen.clip_top) y2 = gr_screen.clip_top;
160 if (y2 > gr_screen.clip_bottom) y2 = gr_screen.clip_bottom;
169 xlat_table = gr_screen.current_shader.lookup;
173 for (i=0; i<h; i++ ) {
174 ubyte * dp = GR_SCREEN_PTR(ubyte,x1,y1+i);
175 #ifdef USE_INLINE_ASM
180 while ( (uint)dp & 3 ) {
181 *dp = xlat_table[*dp];
187 if ( w1 < 1 ) continue;
190 int left_over = w1 % 4;
202 _asm mov esi, xlat_table
218 _asm mov al, [edx+esi]
219 _asm mov ah, [ebx+esi]
226 _asm mov al, [edx+esi]
227 _asm mov ah, [ebx+esi]
231 _asm mov [edi-4], eax
248 for (int j=0; j<left_over; j++ ) {
249 *dp = xlat_table[*dp];
255 for (int j=0; j<w; j++ ) {
256 *dp = xlat_table[*dp];