2 Copyright (c) 2001, Loki software, inc.
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright notice, this list
9 of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this
12 list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
15 Neither the name of Loki software nor the names of its contributors may be used
16 to endorse or promote products derived from this software without specific prior
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 //-----------------------------------------------------------------------------
34 // internal implementation of IShaders related stuff
40 //++timo TODO: track all the calls to IncRef and look for not-called DecRef bugs
41 //++timo TODO: move all needed stuff into the IShader interface
43 // Radiant's internal implementation of the IShader object
44 class CShader : public IShader
47 qtexture_t *m_pTexture;
48 // name is shader / texture name (if not a real shader) reletive to "textures/" directory
49 char m_Name[QER_MAX_NAMELEN];
50 char m_ShaderFileName[QER_MAX_NAMELEN];
53 // the name of the texture file to be used to represent the shader
55 // must fit the qtexture_t convention or not? I think so ..
56 // ((old .. NOTE: may be a straight copy of the .shader file, doesn't fit the qtexture_t naming requirements))
57 CString m_strTextureName;
69 // will hook itself in g_ActiveShaders and increment ref count
70 // will also update the underlying qtexture_t with some information about the shader name etc.
71 void RegisterActivate();
74 CShader() { refCount = 0; m_pTexture = NULL; m_Name[0]='\0'; m_ShaderFileName[0]='\0'; m_nFlags = 0; m_bInUse = false; m_bDisplayed = false; m_bColor = false; m_fTrans = 1.0f; m_nAlphaFunc = 0; m_fAlphaRef = 0.f; m_nCull = 0; }
75 virtual ~CShader() { }
77 // IShaders implementation -----------------
78 // Increment the number of references to this object
79 void IncRef () { refCount++; }
80 // Decrement the reference count
82 { if ( --refCount <= 0 )
85 // get/set the qtexture_t* Radiant uses to represent this shader object
86 qtexture_t* getTexture() const { return m_pTexture; }
87 void setTexture(qtexture_t *pTex) { m_pTexture = pTex; }
89 const char* getName() const { return m_Name; }
90 bool IsDisplayed() const { return m_bDisplayed; }
91 void SetDisplayed(bool b) { m_bDisplayed = b; }
92 // setting in use also sets the display flag on
93 bool IsInUse() const { return m_bInUse; }
94 void SetInUse(bool b) { m_bInUse = b; if (m_pTexture) m_pTexture->inuse = true; if (b) m_bDisplayed = true; }
95 // get the shader flags
96 int getFlags() { return m_nFlags; }
97 // get the transparency value
98 float getTrans() { return m_fTrans; }
99 // test if it's a true shader, or a default shader created to wrap around a texture
100 bool IsDefault() { return m_ShaderFileName[0] == '\0'; }
101 // test if it's a plain color shader, i.e. a shader we use on plain color stuff (like info_playerstart)
102 bool IsColor() { return m_bColor; }
103 // get the related color then!
104 void getColor( vec3_t v) { VectorCopy( m_vColor, v); }
106 void getAlphaFunc(int *func, float *ref) { *func = m_nAlphaFunc; *ref = m_fAlphaRef; };
108 int getCull() { return m_nCull; };
109 // get/set shader file name (ie the file where this one is defined)
110 const char* getShaderFileName() const { return m_ShaderFileName; }
111 // -----------------------------------------
116 // search / load the texture to be used when displaying the shader
117 // after a successfull call to one of these the shader will get displayed in the tex wnd
118 // if m_strTextureName could not be loaded will set m_pTexture to NULL
120 // if m_strTextureName could not be loaded will use a default qtexture
121 // FIXME TTimo: Activate forces activation, always true
125 void setName(const char* name) { strcpy(m_Name, name); }
126 void setShaderFileName(const char* name) { strcpy(m_ShaderFileName, name); }
127 // create a default shader for a given texture name
128 // will not activate!
129 // NOTE: CreateDefault expects a texture name reletive to the base path. Adding a "textures/" may be needed
130 void CreateDefault(const char* name);
131 const char* getTextureName() { return m_strTextureName; }
135 // void setColor( vec3_t c ) { VectorCopy( c, m_vColor ); m_bColor = true; }
136 // create a color shader
137 void CreateColor(const char* name);
140 // the classical CPtrArray with some enhancements
141 class CShaderArray : public CPtrArray
145 virtual ~CShaderArray() { }
146 // look for a shader with a given name (may return NULL)
147 CShader* Shader_ForName( const char * ) const;
148 // look for a shader with a given texture name (may return NULL)
149 // NOTE: the texture name is supposed to fit qtexture_t naming conventions .. _DEBUG builds will check
150 CShader* Shader_ForTextureName( const char * ) const;
151 // will Add the given object if not already in
152 void AddSingle(void*);
153 // will copy / add another CShaderArray, and IncRef
154 void operator = (const class CShaderArray &);
155 // will empty the array, decreasing the refcount by 1
157 // will empty all shaders that match a given filename, decreasing the refcount by 1
158 void ReleaseForShaderFile( const char * );
159 // sort the array by shader name
161 // set the IsDisplayed flag for all shaders stored
162 void SetDisplayed(bool b);
163 // set the InUse flag for all shaders stored
164 void SetInUse(bool b);