]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_dyntexture.c
Experimental r_shadow_shadowmapping_quality cvar which makes a lightradius-based...
[divverent/darkplaces.git] / cl_dyntexture.c
1 // Andreas Kirsch 07\r
2 \r
3 #include "quakedef.h"\r
4 #include "cl_dyntexture.h"\r
5 \r
6 typedef struct dyntexture_s {\r
7         // everything after DYNAMIC_TEXTURE_PATH_PREFIX\r
8         char name[ MAX_QPATH + 32 ];\r
9         // texture pointer (points to r_texture_white at first)\r
10         rtexture_t *texture;\r
11 } dyntexture_t;\r
12 \r
13 static dyntexture_t dyntextures[ MAX_DYNAMIC_TEXTURE_COUNT ];\r
14 static unsigned dyntexturecount;\r
15 \r
16 #define DEFAULT_DYNTEXTURE r_texture_grey128\r
17 \r
18 static dyntexture_t * cl_finddyntexture( const char *name, qboolean warnonfailure ) {\r
19         unsigned i;\r
20         dyntexture_t *dyntexture = NULL;\r
21 \r
22         // sanity checks - make sure its actually a dynamic texture path\r
23         if( !name || !*name || strncmp( name, CLDYNTEXTUREPREFIX, sizeof( CLDYNTEXTUREPREFIX ) - 1 ) != 0 ) {\r
24                 // TODO: print a warning or something\r
25                 if (warnonfailure)\r
26                         Con_Printf( "cl_finddyntexture: Bad dynamic texture name '%s'\n", name );\r
27                 return NULL;\r
28         }\r
29 \r
30         for( i = 0 ; i < dyntexturecount ; i++ ) {\r
31                 dyntexture = &dyntextures[ i ];\r
32                 if( dyntexture->name && strcmp( dyntexture->name, name ) == 0 ) {\r
33                         return dyntexture;\r
34                 }\r
35         }\r
36 \r
37         if( dyntexturecount == MAX_DYNAMIC_TEXTURE_COUNT ) {\r
38                 // TODO: warn or expand the array, etc.\r
39                 return NULL;\r
40         }\r
41         dyntexture = &dyntextures[ dyntexturecount++ ];\r
42         strlcpy( dyntexture->name, name, sizeof( dyntexture->name ) );\r
43         dyntexture->texture = DEFAULT_DYNTEXTURE;\r
44         return dyntexture;\r
45 }\r
46 \r
47 rtexture_t * CL_GetDynTexture( const char *name ) {\r
48         dyntexture_t *dyntexture = cl_finddyntexture( name, false );\r
49         if( dyntexture ) {\r
50                 return dyntexture->texture;\r
51         } else {\r
52                 return NULL;\r
53         }\r
54 }\r
55 \r
56 void CL_LinkDynTexture( const char *name, rtexture_t *texture ) {\r
57         dyntexture_t *dyntexture;\r
58         cachepic_t *cachepic;\r
59         skinframe_t *skinframe;\r
60 \r
61         dyntexture = cl_finddyntexture( name, true );\r
62         if( !dyntexture ) {\r
63                 Con_Printf( "CL_LinkDynTexture: internal error in cl_finddyntexture!\n" );\r
64                 return;\r
65         }\r
66         // TODO: assert dyntexture != NULL!\r
67         if( dyntexture->texture != texture ) {\r
68                 dyntexture->texture = texture;\r
69 \r
70                 cachepic = Draw_CachePic_Flags( name, CACHEPICFLAG_NOTPERSISTENT );\r
71                 // TODO: assert cachepic and skinframe should be valid pointers...\r
72                 // TODO: assert cachepic->tex = dyntexture->texture\r
73                 cachepic->tex = texture;\r
74                 // update cachepic's size, too\r
75                 cachepic->width = R_TextureWidth( texture );\r
76                 cachepic->height = R_TextureHeight( texture );\r
77 \r
78                 // update skinframes\r
79                 skinframe = NULL;\r
80                 while( (skinframe = R_SkinFrame_FindNextByName( skinframe, name )) != NULL ) {\r
81                         skinframe->base = texture;\r
82                         // simply reset the compare* attributes of skinframe\r
83                         skinframe->comparecrc = 0;\r
84                         skinframe->comparewidth = skinframe->compareheight = 0;\r
85                         // this is kind of hacky\r
86                 }\r
87         }\r
88 }\r
89 \r
90 void CL_UnlinkDynTexture( const char *name ) {\r
91         CL_LinkDynTexture( name, DEFAULT_DYNTEXTURE );\r
92 }\r
93 \r