1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4 
5 This file is part of Quake III Arena source code.
6 
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11 
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 ===========================================================================
21 */
22 #ifndef __TR_PUBLIC_H
23 #define __TR_PUBLIC_H
24 
25 #include "tr_types.h"
26 
27 #define	REF_API_VERSION		8
28 
29 //
30 // these are the functions exported by the refresh module
31 //
32 typedef struct {
33 	// called before the library is unloaded
34 	// if the system is just reconfiguring, pass destroyWindow = qfalse,
35 	// which will keep the screen from flashing to the desktop.
36 	void	(*Shutdown)( qboolean destroyWindow );
37 
38 	// All data that will be used in a level should be
39 	// registered before rendering any frames to prevent disk hits,
40 	// but they can still be registered at a later time
41 	// if necessary.
42 	//
43 	// BeginRegistration makes any existing media pointers invalid
44 	// and returns the current gl configuration, including screen width
45 	// and height, which can be used by the client to intelligently
46 	// size display elements
47 	void	(*BeginRegistration)( glconfig_t *config );
48 	qhandle_t (*RegisterModel)( const char *name );
49 	qhandle_t (*RegisterSkin)( const char *name );
50 	qhandle_t (*RegisterShader)( const char *name );
51 	qhandle_t (*RegisterShaderNoMip)( const char *name );
52 	void	(*LoadWorld)( const char *name );
53 
54 	// the vis data is a large enough block of data that we go to the trouble
55 	// of sharing it with the clipmodel subsystem
56 	void	(*SetWorldVisData)( const byte *vis );
57 
58 	// EndRegistration will draw a tiny polygon with each texture, forcing
59 	// them to be loaded into card memory
60 	void	(*EndRegistration)( void );
61 
62 	// a scene is built up by calls to R_ClearScene and the various R_Add functions.
63 	// Nothing is drawn until R_RenderScene is called.
64 	void	(*ClearScene)( void );
65 	void	(*AddRefEntityToScene)( const refEntity_t *re );
66 	void	(*AddPolyToScene)( qhandle_t hShader , int numVerts, const polyVert_t *verts, int num );
67 	int		(*LightForPoint)( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir );
68 	void	(*AddLightToScene)( const vec3_t org, float intensity, float r, float g, float b );
69 	void	(*AddAdditiveLightToScene)( const vec3_t org, float intensity, float r, float g, float b );
70 	void	(*RenderScene)( const refdef_t *fd );
71 
72 	void	(*SetColor)( const float *rgba );	// NULL = 1,1,1,1
73 	void	(*DrawStretchPic) ( float x, float y, float w, float h,
74 		float s1, float t1, float s2, float t2, qhandle_t hShader );	// 0 = white
75 
76 	// Draw images for cinematic rendering, pass as 32 bit rgba
77 	void	(*DrawStretchRaw) (int x, int y, int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
78 	void	(*UploadCinematic) (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
79 
80 	void	(*BeginFrame)( stereoFrame_t stereoFrame );
81 
82 	// if the pointers are not NULL, timing info will be returned
83 	void	(*EndFrame)( int *frontEndMsec, int *backEndMsec );
84 
85 
86 	int		(*MarkFragments)( int numPoints, const vec3_t *points, const vec3_t projection,
87 				   int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer );
88 
89 	int		(*LerpTag)( orientation_t *tag,  qhandle_t model, int startFrame, int endFrame,
90 					 float frac, const char *tagName );
91 	void	(*ModelBounds)( qhandle_t model, vec3_t mins, vec3_t maxs );
92 
93 #ifdef __USEA3D
94 	void    (*A3D_RenderGeometry) (void *pVoidA3D, void *pVoidGeom, void *pVoidMat, void *pVoidGeomStatus);
95 #endif
96 	void	(*RegisterFont)(const char *fontName, int pointSize, fontInfo_t *font);
97 	void	(*RemapShader)(const char *oldShader, const char *newShader, const char *offsetTime);
98 	qboolean (*GetEntityToken)( char *buffer, int size );
99 	qboolean (*inPVS)( const vec3_t p1, const vec3_t p2 );
100 
101 	void (*TakeVideoFrame)( int h, int w, byte* captureBuffer, byte *encodeBuffer, qboolean motionJpeg );
102 } refexport_t;
103 
104 //
105 // these are the functions imported by the refresh module
106 //
107 typedef struct {
108 	// print message on the local console
109 	void	(QDECL *Printf)( int printLevel, const char *fmt, ...);
110 
111 	// abort the game
112 	void	(QDECL *Error)( int errorLevel, const char *fmt, ...);
113 
114 	// milliseconds should only be used for profiling, never
115 	// for anything game related.  Get time from the refdef
116 	int		(*Milliseconds)( void );
117 
118 	// stack based memory allocation for per-level things that
119 	// won't be freed
120 #ifdef HUNK_DEBUG
121 	void	*(*Hunk_AllocDebug)( int size, ha_pref pref, char *label, char *file, int line );
122 #else
123 	void	*(*Hunk_Alloc)( int size, ha_pref pref );
124 #endif
125 	void	*(*Hunk_AllocateTempMemory)( int size );
126 	void	(*Hunk_FreeTempMemory)( void *block );
127 
128 	// dynamic memory allocator for things that need to be freed
129 	void	*(*Malloc)( int bytes );
130 	void	(*Free)( void *buf );
131 
132 	cvar_t	*(*Cvar_Get)( const char *name, const char *value, int flags );
133 	void	(*Cvar_Set)( const char *name, const char *value );
134 	void	(*Cvar_CheckRange)( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
135 
136 	void	(*Cmd_AddCommand)( const char *name, void(*cmd)(void) );
137 	void	(*Cmd_RemoveCommand)( const char *name );
138 
139 	int		(*Cmd_Argc) (void);
140 	char	*(*Cmd_Argv) (int i);
141 
142 	void	(*Cmd_ExecuteText) (int exec_when, const char *text);
143 
144 	// visualization for debugging collision detection
145 	void	(*CM_DrawDebugSurface)( void (*drawPoly)(int color, int numPoints, float *points) );
146 
147 	// a -1 return means the file does not exist
148 	// NULL can be passed for buf to just determine existance
149 	int		(*FS_FileIsInPAK)( const char *name, int *pCheckSum );
150 	int		(*FS_ReadFile)( const char *name, void **buf );
151 	void	(*FS_FreeFile)( void *buf );
152 	char **	(*FS_ListFiles)( const char *name, const char *extension, int *numfilesfound );
153 	void	(*FS_FreeFileList)( char **filelist );
154 	void	(*FS_WriteFile)( const char *qpath, const void *buffer, int size );
155 	qboolean (*FS_FileExists)( const char *file );
156 
157 	// cinematic stuff
158 	void	(*CIN_UploadCinematic)(int handle);
159 	int		(*CIN_PlayCinematic)( const char *arg0, int xpos, int ypos, int width, int height, int bits);
160 	e_status (*CIN_RunCinematic) (int handle);
161 
162 	void	(*CL_WriteAVIVideoFrame)( const byte *buffer, int size );
163 } refimport_t;
164 
165 
166 // this is the only function actually exported at the linker level
167 // If the module can't init to a valid rendering state, NULL will be
168 // returned.
169 refexport_t*GetRefAPI( int apiVersion, refimport_t *rimp );
170 
171 #endif	// __TR_PUBLIC_H
172