1 /*****************************************************************************
2 * vout_glide.c: 3dfx video output display method for 3dfx cards
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: vout_glide.c,v 1.6 2001/03/21 13:42:34 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 #define MODULE_NAME glide
25 #include "modules_inner.h"
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <errno.h> /* ENOMEM */
33 #include <stdlib.h> /* free() */
34 #include <string.h> /* strerror() */
37 #include <conio.h> /* for glide ? */
40 #include <linutil.h> /* Glide kbhit() and getch() */
50 #include "video_output.h"
53 #include "interface.h"
57 #define GLIDE_WIDTH 800
58 #define GLIDE_HEIGHT 600
59 #define GLIDE_BITS_PER_PLANE 16
60 #define GLIDE_BYTES_PER_PIXEL 2
62 /*****************************************************************************
63 * vout_sys_t: Glide video output method descriptor
64 *****************************************************************************
65 * This structure is part of the video output thread descriptor.
66 * It describes the Glide specific properties of an output thread.
67 *****************************************************************************/
68 typedef struct vout_sys_s
70 GrLfbInfo_t p_buffer_info; /* back buffer info */
72 /* Dummy video memory */
73 byte_t * p_video; /* base adress */
74 size_t i_page_size; /* page size */
78 /*****************************************************************************
80 *****************************************************************************/
81 static int vout_Probe ( probedata_t *p_data );
82 static int vout_Create ( struct vout_thread_s * );
83 static int vout_Init ( struct vout_thread_s * );
84 static void vout_End ( struct vout_thread_s * );
85 static void vout_Destroy ( struct vout_thread_s * );
86 static int vout_Manage ( struct vout_thread_s * );
87 static void vout_Display ( struct vout_thread_s * );
89 static int GlideOpenDisplay ( vout_thread_t *p_vout );
90 static void GlideCloseDisplay ( vout_thread_t *p_vout );
92 /*****************************************************************************
93 * Functions exported as capabilities. They are declared as static so that
94 * we don't pollute the namespace too much.
95 *****************************************************************************/
96 void _M( vout_getfunctions )( function_list_t * p_function_list )
98 p_function_list->pf_probe = vout_Probe;
99 p_function_list->functions.vout.pf_create = vout_Create;
100 p_function_list->functions.vout.pf_init = vout_Init;
101 p_function_list->functions.vout.pf_end = vout_End;
102 p_function_list->functions.vout.pf_destroy = vout_Destroy;
103 p_function_list->functions.vout.pf_manage = vout_Manage;
104 p_function_list->functions.vout.pf_display = vout_Display;
105 p_function_list->functions.vout.pf_setpalette = NULL;
108 /*****************************************************************************
109 * vout_Probe: probe the video driver and return a score
110 *****************************************************************************
111 * This function tries to initialize SDL and returns a score to the
112 * plugin manager so that it can select the best plugin.
113 *****************************************************************************/
114 static int vout_Probe( probedata_t *p_data )
116 if( TestMethod( VOUT_METHOD_VAR, "glide" ) )
121 /* We could do a grSstQueryBoards( GrHwConfiguration *hwConfig ) at
122 * this point, but if the user didn't configure his 3dfx card, we
123 * have great chances to segfault here. So we'd better assume
124 * everything is fine and worry only if we really need to use Glide */
128 /*****************************************************************************
129 * vout_Create: allocates Glide video thread output method
130 *****************************************************************************
131 * This function allocates and initializes a Glide vout method.
132 *****************************************************************************/
133 int vout_Create( vout_thread_t *p_vout )
135 /* Allocate structure */
136 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
137 if( p_vout->p_sys == NULL )
139 intf_ErrMsg("error: %s", strerror(ENOMEM) );
143 /* Open and initialize device */
144 if( GlideOpenDisplay( p_vout ) )
146 intf_ErrMsg("vout error: can't open display");
147 free( p_vout->p_sys );
154 /*****************************************************************************
155 * vout_Init: initialize Glide video thread output method
156 *****************************************************************************/
157 int vout_Init( vout_thread_t *p_vout )
162 /*****************************************************************************
163 * vout_End: terminate Glide video thread output method
164 *****************************************************************************/
165 void vout_End( vout_thread_t *p_vout )
170 /*****************************************************************************
171 * vout_Destroy: destroy Glide video thread output method
172 *****************************************************************************
173 * Terminate an output method created by vout_CreateOutputMethod
174 *****************************************************************************/
175 void vout_Destroy( vout_thread_t *p_vout )
177 GlideCloseDisplay( p_vout );
178 free( p_vout->p_sys );
181 /*****************************************************************************
182 * vout_Manage: handle Glide events
183 *****************************************************************************
184 * This function should be called regularly by video output thread. It manages
185 * console events. It returns a non null value on error.
186 *****************************************************************************/
187 int vout_Manage( vout_thread_t *p_vout )
191 /* very Linux specific - see tlib.c in Glide for other versions */
199 p_main->p_intf->b_die = 1;
210 /*****************************************************************************
211 * vout_Display: displays previously rendered output
212 *****************************************************************************
213 * This function send the currently rendered image to Glide image, waits until
214 * it is displayed and switch the two rendering buffers, preparing next frame.
215 *****************************************************************************/
216 void vout_Display( vout_thread_t *p_vout )
218 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
222 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
223 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
224 &p_vout->p_sys->p_buffer_info) == FXFALSE )
226 intf_ErrMsg( "vout error: can't take 3dfx back buffer lock" );
230 /* following functions are local */
232 /*****************************************************************************
233 * GlideOpenDisplay: open and initialize 3dfx device
234 *****************************************************************************/
236 static int GlideOpenDisplay( vout_thread_t *p_vout )
238 static char version[80];
239 GrHwConfiguration hwconfig;
240 GrScreenResolution_t resolution = GR_RESOLUTION_800x600;
241 GrLfbInfo_t p_front_buffer_info; /* front buffer info */
243 p_vout->i_width = GLIDE_WIDTH;
244 p_vout->i_height = GLIDE_HEIGHT;
245 p_vout->i_screen_depth = GLIDE_BITS_PER_PLANE;
246 p_vout->i_bytes_per_pixel = GLIDE_BYTES_PER_PIXEL;
247 /* bytes per line value overriden later */
248 p_vout->i_bytes_per_line = 1024 * GLIDE_BYTES_PER_PIXEL;
250 p_vout->p_sys->i_page_size = GLIDE_WIDTH * GLIDE_HEIGHT
251 * GLIDE_BYTES_PER_PIXEL;
253 p_vout->i_red_mask = 0xf800;
254 p_vout->i_green_mask = 0x07e0;
255 p_vout->i_blue_mask = 0x001f;
257 /* Map two framebuffers a the very beginning of the fb */
258 p_vout->p_sys->p_video = malloc( p_vout->p_sys->i_page_size * 2 );
259 if( (int)p_vout->p_sys->p_video == -1 )
261 intf_ErrMsg( "vout error: can't map video memory (%s)",
266 grGlideGetVersion( version );
269 if( !grSstQueryHardware(&hwconfig) )
271 intf_ErrMsg( "vout error: can't get 3dfx hardware config" );
276 if( !grSstWinOpen(0, resolution, GR_REFRESH_60Hz,
277 GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1) )
279 intf_ErrMsg( "vout error: can't open 3dfx screen" );
283 /* disable dithering */
284 //grDitherMode( GR_DITHER_DISABLE );
286 /* clear both buffers */
287 grRenderBuffer( GR_BUFFER_BACKBUFFER );
288 grBufferClear( 0, 0, 0 );
289 grRenderBuffer( GR_BUFFER_FRONTBUFFER );
290 grBufferClear( 0, 0, 0 );
291 grRenderBuffer( GR_BUFFER_BACKBUFFER );
293 p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
294 p_front_buffer_info.size = sizeof( GrLfbInfo_t );
296 /* lock the buffers to find their adresses */
297 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
298 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
299 &p_front_buffer_info) == FXFALSE )
301 intf_ErrMsg( "vout error: can't take 3dfx front buffer lock" );
305 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
307 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
308 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
309 &p_vout->p_sys->p_buffer_info) == FXFALSE )
311 intf_ErrMsg( "vout error: can't take 3dfx back buffer lock" );
315 grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
317 /* Get the number of bytes per line */
318 p_vout->i_bytes_per_line = p_vout->p_sys->p_buffer_info.strideInBytes;
320 grBufferClear( 0, 0, 0 );
322 /* Set and initialize buffers */
323 vout_SetBuffers( p_vout, p_vout->p_sys->p_buffer_info.lfbPtr,
324 p_front_buffer_info.lfbPtr );
329 /*****************************************************************************
330 * GlideCloseDisplay: close and reset 3dfx device
331 *****************************************************************************
332 * Returns all resources allocated by GlideOpenDisplay and restore the original
333 * state of the device.
334 *****************************************************************************/
335 static void GlideCloseDisplay( vout_thread_t *p_vout )
337 /* unlock the hidden buffer */
338 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
342 free( p_vout->p_sys->p_video );