1 /*
2 ===========================================================================
3 
4 Return to Castle Wolfenstein single player GPL Source Code
5 Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”).
8 
9 RTCW SP Source Code 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 3 of the License, or
12 (at your option) any later version.
13 
14 RTCW SP Source Code 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.
18 
19 You should have received a copy of the GNU General Public License
20 along with RTCW SP Source Code.  If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code.  If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __TR_PUBLIC_H
30 #define __TR_PUBLIC_H
31 
32 #include "tr_types.h"
33 
34 #define REF_API_VERSION     8
35 
36 //
37 // these are the functions exported by the refresh module
38 //
39 typedef struct {
40 	// called before the library is unloaded
41 	// if the system is just reconfiguring, pass destroyWindow = qfalse,
42 	// which will keep the screen from flashing to the desktop.
43 	void ( *Shutdown )( qboolean destroyWindow );
44 
45 	// All data that will be used in a level should be
46 	// registered before rendering any frames to prevent disk hits,
47 	// but they can still be registered at a later time
48 	// if necessary.
49 	//
50 	// BeginRegistration makes any existing media pointers invalid
51 	// and returns the current gl configuration, including screen width
52 	// and height, which can be used by the client to intelligently
53 	// size display elements
54 	void ( *BeginRegistration )( glconfig_t *config );
55 	qhandle_t ( *RegisterModel )( const char *name );
56 	qhandle_t ( *RegisterSkin )( const char *name );
57 	qhandle_t ( *RegisterShader )( const char *name );
58 	qhandle_t ( *RegisterShaderNoMip )( const char *name );
59 	void ( *LoadWorld )( const char *name );
60 	qboolean ( *GetSkinModel )( qhandle_t skinid, const char *type, char *name );    //----(SA)	added
61 	qhandle_t ( *GetShaderFromModel )( qhandle_t modelid, int surfnum, int withlightmap );                //----(SA)	added
62 
63 	// the vis data is a large enough block of data that we go to the trouble
64 	// of sharing it with the clipmodel subsystem
65 	void ( *SetWorldVisData )( const byte *vis );
66 
67 	// EndRegistration will draw a tiny polygon with each texture, forcing
68 	// them to be loaded into card memory
69 	void ( *EndRegistration )( void );
70 
71 	// a scene is built up by calls to R_ClearScene and the various R_Add functions.
72 	// Nothing is drawn until R_RenderScene is called.
73 	void ( *ClearScene )( void );
74 	void ( *AddRefEntityToScene )( const refEntity_t *re );
75 	int ( *LightForPoint )( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir );
76 	void ( *AddPolyToScene )( qhandle_t hShader, int numVerts, const polyVert_t *verts );
77 	// Ridah
78 	void ( *AddPolysToScene )( qhandle_t hShader, int numVerts, const polyVert_t *verts, int numPolys );
79 	// done.
80 	void ( *AddLightToScene )( const vec3_t org, float intensity, float r, float g, float b, int overdraw );
81 //----(SA)
82 	void ( *AddCoronaToScene )( const vec3_t org, float r, float g, float b, float scale, int id, int flags );
83 	void ( *SetFog )( int fogvar, int var1, int var2, float r, float g, float b, float density );
84 //----(SA)
85 	void ( *RenderScene )( const refdef_t *fd );
86 
87 	void ( *SetColor )( const float *rgba );    // NULL = 1,1,1,1
88 	void ( *DrawStretchPic )( float x, float y, float w, float h,
89 							  float s1, float t1, float s2, float t2, qhandle_t hShader ); // 0 = white
90 	void ( *DrawStretchPicGradient )( float x, float y, float w, float h,
91 									  float s1, float t1, float s2, float t2, qhandle_t hShader, const float *gradientColor, int gradientType );
92 
93 	// Draw images for cinematic rendering, pass as 32 bit rgba
94 	void ( *DrawStretchRaw )( int x, int y, int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty );
95 	void ( *UploadCinematic )( int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty );
96 
97 	void ( *BeginFrame )( stereoFrame_t stereoFrame );
98 
99 	// if the pointers are not NULL, timing info will be returned
100 	void ( *EndFrame )( int *frontEndMsec, int *backEndMsec );
101 
102 
103 	int ( *MarkFragments )( int numPoints, const vec3_t *points, const vec3_t projection,
104 							int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer );
105 
106 	int ( *LerpTag )( orientation_t *tag,  const refEntity_t *refent, const char *tagName, int startIndex );
107 	void ( *ModelBounds )( qhandle_t model, vec3_t mins, vec3_t maxs );
108 
109 	void ( *RegisterFont )( const char *fontName, int pointSize, fontInfo_t *font );
110 	void ( *RemapShader )( const char *oldShader, const char *newShader, const char *offsetTime );
111 
112 	// RF
113 	void ( *ZombieFXAddNewHit )( int entityNum, const vec3_t hitPos, const vec3_t hitDir );
114 
115 	qboolean ( *GetEntityToken )( char *buffer, int size );
116 
117 	void (*TakeVideoFrame)( int h, int w, byte* captureBuffer, byte *encodeBuffer, qboolean motionJpeg );
118 } refexport_t;
119 
120 //
121 // these are the functions imported by the refresh module
122 //
123 typedef struct {
124 	// print message on the local console
125 	void	(QDECL *Printf)( int printLevel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
126 
127 	// abort the game
128 	void	(QDECL *Error)( int errorLevel, const char *fmt, ...) __attribute__ ((noreturn, format (printf, 2, 3)));
129 
130 	// milliseconds should only be used for profiling, never
131 	// for anything game related.  Get time from the refdef
132 	int ( *Milliseconds )( void );
133 
134 	// stack based memory allocation for per-level things that
135 	// won't be freed
136 	void ( *Hunk_Clear )( void );
137 #ifdef HUNK_DEBUG
138 	void    *( *Hunk_AllocDebug )( int size, ha_pref pref, char *label, char *file, int line );
139 #else
140 	void    *( *Hunk_Alloc )( int size, ha_pref pref );
141 #endif
142 	void    *( *Hunk_AllocateTempMemory )( int size );
143 	void ( *Hunk_FreeTempMemory )( void *block );
144 
145 	void    *( *Z_Malloc )( int bytes );
146 	void ( *Free )( void *buf );
147 
148 	cvar_t  *( *Cvar_Get )( const char *name, const char *value, int flags );
149 	void ( *Cvar_Set )( const char *name, const char *value );
150 	void	(*Cvar_SetValue) (const char *name, float value);
151 	void	(*Cvar_CheckRange)( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
152 
153 	int		(*Cvar_VariableIntegerValue) (const char *var_name);
154 
155 	void ( *Cmd_AddCommand )( const char *name, void( *cmd ) ( void ) );
156 	void ( *Cmd_RemoveCommand )( const char *name );
157 
158 	int ( *Cmd_Argc )( void );
159 	char    *( *Cmd_Argv )( int i );
160 
161 	void ( *Cmd_ExecuteText )( int exec_when, const char *text );
162 
163 	byte	*(*CM_ClusterPVS)(int cluster);
164 
165 	// visualization for debugging collision detection
166 	void ( *CM_DrawDebugSurface )( void( *drawPoly ) ( int color, int numPoints, float *points ) );
167 
168 	// a -1 return means the file does not exist
169 	// NULL can be passed for buf to just determine existance
170 	int ( *FS_FileIsInPAK )( const char *name, int *pChecksum );
171 	long ( *FS_ReadFile )( const char *name, void **buf );
172 	void ( *FS_FreeFile )( void *buf );
173 	char ** ( *FS_ListFiles )( const char *name, const char *extension, int *numfilesfound );
174 	void ( *FS_FreeFileList )( char **filelist );
175 	void ( *FS_WriteFile )( const char *qpath, const void *buffer, int size );
176 	qboolean ( *FS_FileExists )( const char *file );
177 
178 	// cinematic stuff
179 	void ( *CIN_UploadCinematic )( int handle );
180 	int ( *CIN_PlayCinematic )( const char *arg0, int xpos, int ypos, int width, int height, int bits );
181 	e_status ( *CIN_RunCinematic )( int handle );
182 
183 	void	(*CL_WriteAVIVideoFrame)( const byte *buffer, int size );
184 
185 	// input event handling
186 	void	(*IN_Init)( void *windowData );
187 	void	(*IN_Shutdown)( void );
188 	void	(*IN_Restart)( void );
189 
190 	// math
191 	long    (*ftol)(float f);
192 
193 	// system stuff
194 	void	(*Sys_SetEnv)( const char *name, const char *value );
195 	void	(*Sys_GLimpSafeInit)( void );
196 	void	(*Sys_GLimpInit)( void );
197 	qboolean (*Sys_LowPhysicalMemory)( void );
198 } refimport_t;
199 
200 
201 // this is the only function actually exported at the linker level
202 // If the module can't init to a valid rendering state, NULL will be
203 // returned.
204 #ifdef USE_RENDERER_DLOPEN
205 typedef	refexport_t* (QDECL *GetRefAPI_t) (int apiVersion, refimport_t * rimp);
206 #else
207 refexport_t*GetRefAPI( int apiVersion, refimport_t *rimp );
208 #endif
209 
210 #endif  // __TR_PUBLIC_H
211