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_GlideCreate: allocates Glide video thread output method
78 *****************************************************************************
79 * This function allocates and initializes a Glide vout method.
80 *****************************************************************************/
81 int vout_GlideCreate( 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", strerror(ENOMEM) );
92 /* Open and initialize device */
93 if( GlideOpenDisplay( p_vout ) )
95 intf_ErrMsg("vout error: can't open display");
96 free( p_vout->p_sys );
103 /*****************************************************************************
104 * vout_GlideInit: initialize Glide video thread output method
105 *****************************************************************************/
106 int vout_GlideInit( vout_thread_t *p_vout )
111 /*****************************************************************************
112 * vout_GlideEnd: terminate Glide video thread output method
113 *****************************************************************************/
114 void vout_GlideEnd( vout_thread_t *p_vout )
119 /*****************************************************************************
120 * vout_GlideDestroy: destroy Glide video thread output method
121 *****************************************************************************
122 * Terminate an output method created by vout_CreateOutputMethod
123 *****************************************************************************/
124 void vout_GlideDestroy( vout_thread_t *p_vout )
126 GlideCloseDisplay( p_vout );
127 free( p_vout->p_sys );
130 /*****************************************************************************
131 * vout_GlideManage: 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_GlideManage( vout_thread_t *p_vout )
141 /*****************************************************************************
142 * vout_GlideDisplay: 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_GlideDisplay( 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" );
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_800x600;
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)",
196 grGlideGetVersion( version );
199 if( !grSstQueryHardware(&hwconfig) )
201 intf_ErrMsg( "vout error: can't get 3dfx hardware config" );
206 if( !grSstWinOpen(0, resolution, GR_REFRESH_60Hz,
207 GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1) )
209 intf_ErrMsg( "vout error: can't open 3dfx screen" );
213 /* disable dithering */
214 //grDitherMode( GR_DITHER_DISABLE );
216 /* clear both buffers */
217 grRenderBuffer( GR_BUFFER_BACKBUFFER );
218 grBufferClear( 0, 0, 0 );
219 grRenderBuffer( GR_BUFFER_FRONTBUFFER );
220 grBufferClear( 0, 0, 0 );
221 grRenderBuffer( GR_BUFFER_BACKBUFFER );
223 p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
224 p_front_buffer_info.size = sizeof( GrLfbInfo_t );
226 /* lock the buffers to find their adresses */
227 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
228 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
229 &p_front_buffer_info) == FXFALSE )
231 intf_ErrMsg( "vout error: can't take 3dfx front buffer lock" );
235 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
237 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
238 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
239 &p_vout->p_sys->p_buffer_info) == FXFALSE )
241 intf_ErrMsg( "vout error: can't take 3dfx back buffer lock" );
245 grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
247 /* Get the number of bytes per line */
248 p_vout->i_bytes_per_line = p_vout->p_sys->p_buffer_info.strideInBytes;
250 grBufferClear( 0, 0, 0 );
252 /* Set and initialize buffers */
253 vout_SetBuffers( p_vout, p_vout->p_sys->p_buffer_info.lfbPtr,
254 p_front_buffer_info.lfbPtr );
259 /*****************************************************************************
260 * GlideCloseDisplay: close and reset 3dfx device
261 *****************************************************************************
262 * Returns all resources allocated by GlideOpenDisplay and restore the original
263 * state of the device.
264 *****************************************************************************/
265 static void GlideCloseDisplay( vout_thread_t *p_vout )
267 /* unlock the hidden buffer */
268 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
272 free( p_vout->p_sys->p_video );