1 /*****************************************************************************
2 * vout_glide.c: 3dfx video output display method for 3dfx cards
3 *****************************************************************************
4 * Copyright (C) 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
28 #include <errno.h> /* ENOMEM */
29 #include <stdlib.h> /* free() */
30 #include <string.h> /* strerror() */
33 #include <conio.h> /* for glide ? */
44 #include "video_output.h"
51 #define BITS_PER_PLANE 16
52 #define BYTES_PER_PIXEL 2
54 /*****************************************************************************
55 * vout_sys_t: Glide video output method descriptor
56 *****************************************************************************
57 * This structure is part of the video output thread descriptor.
58 * It describes the Glide specific properties of an output thread.
59 *****************************************************************************/
60 typedef struct vout_sys_s
62 GrLfbInfo_t p_buffer_info; /* back buffer info */
64 /* Dummy video memory */
65 byte_t * p_video; /* base adress */
66 size_t i_page_size; /* page size */
70 /*****************************************************************************
72 *****************************************************************************/
73 static int GlideOpenDisplay ( vout_thread_t *p_vout );
74 static void GlideCloseDisplay ( vout_thread_t *p_vout );
76 /*****************************************************************************
77 * vout_SysCreate: allocates Glide video thread output method
78 *****************************************************************************
79 * This function allocates and initializes a Glide vout method.
80 *****************************************************************************/
81 int vout_SysCreate( vout_thread_t *p_vout, char *psz_display,
82 int i_root_window, void *p_data )
84 /* Allocate structure */
85 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
86 if( p_vout->p_sys == NULL )
88 intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
92 /* Open and initialize device */
93 if( GlideOpenDisplay( p_vout ) )
95 intf_ErrMsg("vout error: can't open display\n");
96 free( p_vout->p_sys );
103 /*****************************************************************************
104 * vout_SysInit: initialize Glide video thread output method
105 *****************************************************************************/
106 int vout_SysInit( vout_thread_t *p_vout )
111 /*****************************************************************************
112 * vout_SysEnd: terminate Glide video thread output method
113 *****************************************************************************/
114 void vout_SysEnd( vout_thread_t *p_vout )
119 /*****************************************************************************
120 * vout_SysDestroy: destroy Glide video thread output method
121 *****************************************************************************
122 * Terminate an output method created by vout_CreateOutputMethod
123 *****************************************************************************/
124 void vout_SysDestroy( vout_thread_t *p_vout )
126 GlideCloseDisplay( p_vout );
127 free( p_vout->p_sys );
130 /*****************************************************************************
131 * vout_SysManage: handle Glide events
132 *****************************************************************************
133 * This function should be called regularly by video output thread. It manages
134 * console events. It returns a non null value on error.
135 *****************************************************************************/
136 int vout_SysManage( vout_thread_t *p_vout )
141 /*****************************************************************************
142 * vout_SysDisplay: displays previously rendered output
143 *****************************************************************************
144 * This function send the currently rendered image to Glide image, waits until
145 * it is displayed and switch the two rendering buffers, preparing next frame.
146 *****************************************************************************/
147 void vout_SysDisplay( vout_thread_t *p_vout )
149 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
153 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
154 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
155 &p_vout->p_sys->p_buffer_info) == FXFALSE )
157 intf_ErrMsg( "vout error: can't take 3dfx back buffer lock\n" );
161 /* following functions are local */
163 /*****************************************************************************
164 * GlideOpenDisplay: open and initialize 3dfx device
165 *****************************************************************************/
167 static int GlideOpenDisplay( vout_thread_t *p_vout )
169 static char version[80];
170 GrHwConfiguration hwconfig;
171 GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
172 GrLfbInfo_t p_front_buffer_info; /* front buffer info */
174 p_vout->i_width = WIDTH;
175 p_vout->i_height = HEIGHT;
176 p_vout->i_screen_depth = BITS_PER_PLANE;
177 p_vout->i_bytes_per_pixel = BYTES_PER_PIXEL;
178 /* bytes per line value overriden later */
179 p_vout->i_bytes_per_line = 1024 * BYTES_PER_PIXEL;
181 p_vout->p_sys->i_page_size = WIDTH * HEIGHT * BYTES_PER_PIXEL;
183 p_vout->i_red_mask = 0xf800;
184 p_vout->i_green_mask = 0x07e0;
185 p_vout->i_blue_mask = 0x001f;
187 /* Map two framebuffers a the very beginning of the fb */
188 p_vout->p_sys->p_video = malloc( p_vout->p_sys->i_page_size * 2 );
189 if( (int)p_vout->p_sys->p_video == -1 )
191 intf_ErrMsg( "vout error: can't map video memory (%s)\n", strerror(errno) );
195 grGlideGetVersion( version );
198 if( !grSstQueryHardware(&hwconfig) )
200 intf_ErrMsg( "vout error: can't get 3dfx hardware config\n" );
205 if( !grSstWinOpen(0, resolution, GR_REFRESH_60Hz,
206 GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1) )
208 intf_ErrMsg( "vout error: can't open 3dfx screen\n" );
212 /* disable dithering */
213 //grDitherMode( GR_DITHER_DISABLE );
215 /* clear both buffers */
216 grRenderBuffer( GR_BUFFER_BACKBUFFER );
217 grBufferClear( 0, 0, 0 );
218 grRenderBuffer( GR_BUFFER_FRONTBUFFER );
219 grBufferClear( 0, 0, 0 );
220 grRenderBuffer( GR_BUFFER_BACKBUFFER );
222 p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
223 p_front_buffer_info.size = sizeof( GrLfbInfo_t );
225 /* lock the buffers to find their adresses */
226 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
227 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
228 &p_front_buffer_info) == FXFALSE )
230 intf_ErrMsg( "vout error: can't take 3dfx front buffer lock\n" );
234 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
236 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
237 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
238 &p_vout->p_sys->p_buffer_info) == FXFALSE )
240 intf_ErrMsg( "vout error: can't take 3dfx back buffer lock\n" );
244 grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
246 /* Get the number of bytes per line */
247 p_vout->i_bytes_per_line = p_vout->p_sys->p_buffer_info.strideInBytes;
249 grBufferClear( 0, 0, 0 );
251 /* Set and initialize buffers */
252 vout_SetBuffers( p_vout, p_vout->p_sys->p_buffer_info.lfbPtr,
253 p_front_buffer_info.lfbPtr );
258 /*****************************************************************************
259 * GlideCloseDisplay: close and reset 3dfx device
260 *****************************************************************************
261 * Returns all resources allocated by GlideOpenDisplay and restore the original
262 * state of the device.
263 *****************************************************************************/
264 static void GlideCloseDisplay( vout_thread_t *p_vout )
266 /* unlock the hidden buffer */
267 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
271 free( p_vout->p_sys->p_video );