Browse Source

Reordered batch setup.
Removed unnecessary public Graphics functions.
Material & view-global shader parameters are stored into a HashMap.
Fixed HashMap bugs.

Lasse Öörni 14 years ago
parent
commit
2bee05deb9

+ 4 - 4
Engine/Container/HashMap.h

@@ -125,13 +125,13 @@ public:
         /// Assign from a non-const iterator
         ConstIterator& operator = (const Iterator& rhs) { ptr_ = rhs.ptr_; return *this; }
         /// Preincrement the pointer
-        Iterator& operator ++ () { GotoNext(); return *this; }
+        ConstIterator& operator ++ () { GotoNext(); return *this; }
         /// Postincrement the pointer
-        Iterator operator ++ (int) { Iterator it = *this; GotoNext(); return it; }
+        ConstIterator operator ++ (int) { Iterator it = *this; GotoNext(); return it; }
         /// Predecrement the pointer
-        Iterator& operator -- () { GotoPrev(); return *this; }
+        ConstIterator& operator -- () { GotoPrev(); return *this; }
         /// Postdecrement the pointer
-        Iterator operator -- (int) { Iterator it = *this; GotoPrev(); return it; }
+        ConstIterator operator -- (int) { Iterator it = *this; GotoPrev(); return it; }
         
         /// Point to the pair
         const KeyValue* operator -> () const { return &(static_cast<Node*>(ptr_))->pair_; }

+ 4 - 4
Engine/Container/HashSet.h

@@ -98,13 +98,13 @@ public:
         /// Assign from a non-const iterator
         ConstIterator& operator = (const Iterator& rhs) { ptr_ = rhs.ptr_; return *this; }
         /// Preincrement the pointer
-        Iterator& operator ++ () { GotoNext(); return *this; }
+        ConstIterator& operator ++ () { GotoNext(); return *this; }
         /// Postincrement the pointer
-        Iterator operator ++ (int) { Iterator it = *this; GotoNext(); return it; }
+        ConstIterator operator ++ (int) { Iterator it = *this; GotoNext(); return it; }
         /// Predecrement the pointer
-        Iterator& operator -- () { GotoPrev(); return *this; }
+        ConstIterator& operator -- () { GotoPrev(); return *this; }
         /// Postdecrement the pointer
-        Iterator operator -- (int) { Iterator it = *this; GotoPrev(); return it; }
+        ConstIterator operator -- (int) { Iterator it = *this; GotoPrev(); return it; }
         
         /// Point to the key
         const T* operator -> () const { return &(static_cast<Node*>(ptr_))->key_; }

+ 2 - 2
Engine/Engine/GraphicsAPI.cpp

@@ -241,8 +241,8 @@ static void RegisterTextures(asIScriptEngine* engine)
 
 static Vector4 MaterialGetShaderParameter(ShaderParameter parameter, Material* ptr)
 {
-    const Map<ShaderParameter, Vector4>& parameters = ptr->GetShaderParameters();
-    Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Find(parameter);
+    const HashMap<ShaderParameter, Vector4>& parameters = ptr->GetShaderParameters();
+    HashMap<ShaderParameter, Vector4>::ConstIterator i = parameters.Find(parameter);
     if (i == parameters.End())
         return Vector4::ZERO;
     else

+ 116 - 111
Engine/Graphics/Batch.cpp

@@ -71,21 +71,11 @@ void Batch::CalculateSortKey()
         (((unsigned long long)material) << 16) || geometry;
 }
 
-void Batch::Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& shaderParameters, bool SetModelTransform) const
+void Batch::Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters, bool SetModelTransform) const
 {
     if ((!vertexShader_) || (!pixelShader_))
         return;
     
-    // Set shaders
-    graphics->SetShaders(vertexShader_, pixelShader_);
-    
-    // Set global shader parameters as needed
-    for (Map<ShaderParameter, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
-    {
-        if (graphics->NeedParameterUpdate(i->first_, &shaderParameters))
-            graphics->SetShaderParameter(i->first_, i->second_);
-    }
-    
     // Set pass / material-specific renderstates
     if ((pass_) && (material_))
     {
@@ -98,41 +88,30 @@ void Batch::Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& sha
         graphics->SetCullMode(pass_->GetType() != PASS_SHADOW ? material_->GetCullMode() : material_->GetShadowCullMode());
         graphics->SetDepthTest(pass_->GetDepthTestMode());
         graphics->SetDepthWrite(pass_->GetDepthWrite());
-        
-        const Vector<SharedPtr<Texture> >& textures = material_->GetTextures();
-        
-        if (graphics->NeedTextureUnit(TU_DIFFUSE))
-            graphics->SetTexture(TU_DIFFUSE, textures[TU_DIFFUSE]);
-        if (graphics->NeedTextureUnit(TU_NORMAL))
-            graphics->SetTexture(TU_NORMAL, textures[TU_NORMAL]);
-        if (graphics->NeedTextureUnit(TU_SPECULAR))
-            graphics->SetTexture(TU_SPECULAR, textures[TU_SPECULAR]);
-        if (graphics->NeedTextureUnit(TU_DETAIL))
-            graphics->SetTexture(TU_DETAIL, textures[TU_DETAIL]);
-        if (graphics->NeedTextureUnit(TU_ENVIRONMENT))
-            graphics->SetTexture(TU_ENVIRONMENT, textures[TU_ENVIRONMENT]);
-        if (!light_)
-        {
-            if (graphics->NeedTextureUnit(TU_EMISSIVE))
-                graphics->SetTexture(TU_EMISSIVE, textures[TU_EMISSIVE]);
-        }
     }
     
-    // Set light-related textures
-    Texture2D* shadowMap = 0;
-    if (light_)
+    // Set shaders
+    graphics->SetShaders(vertexShader_, pixelShader_);
+    
+    // Set global shader parameters
+    for (HashMap<ShaderParameter, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
     {
-        shadowMap = light_->GetShadowMap();
-        
-        if ((shadowMap) && (graphics->NeedTextureUnit(TU_SHADOWMAP)))
-            graphics->SetTexture(TU_SHADOWMAP, shadowMap);
-        if (graphics->NeedTextureUnit(TU_LIGHTRAMP))
-            graphics->SetTexture(TU_LIGHTRAMP, light_->GetRampTexture());
-        if (graphics->NeedTextureUnit(TU_LIGHTSPOT))
-            graphics->SetTexture(TU_LIGHTSPOT, light_->GetShapeTexture());
+        if (graphics->NeedParameterUpdate(i->first_, &shaderParameters))
+            graphics->SetShaderParameter(i->first_, i->second_);
     }
     
-    // Set viewport parameters
+    // Set material's shader parameters
+    if (material_)
+    {
+        const HashMap<ShaderParameter, Vector4>& parameters = material_->GetShaderParameters();
+        for (HashMap<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
+        {
+            if (graphics->NeedParameterUpdate(i->first_, material_))
+                graphics->SetShaderParameter(i->first_, i->second_);
+        }
+    }
+    
+    // Set viewport and camera shader parameters
     if (graphics->NeedParameterUpdate(VSP_CAMERAPOS, camera_))
         graphics->SetShaderParameter(VSP_CAMERAPOS, camera_->GetWorldPosition());
     
@@ -150,45 +129,6 @@ void Batch::Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& sha
         graphics->SetShaderParameter(VSP_DEPTHMODE, depthMode);
     }
     
-    // Set transforms
-    if ((SetModelTransform) && (graphics->NeedParameterUpdate(VSP_MODEL, worldTransform_)))
-        graphics->SetShaderParameter(VSP_MODEL, *worldTransform_);
-    
-    if ((shadowMap) && (graphics->NeedParameterUpdate(VSP_SHADOWPROJ, light_)))
-    {
-        Camera* shadowCamera = light_->GetShadowCamera();
-        Matrix3x4 shadowView(shadowCamera->GetInverseWorldTransform());
-        Matrix4 shadowProj(shadowCamera->GetProjection());
-        
-        Matrix4 texAdjust(Matrix4::IDENTITY);
-        float offset = 0.5f + 0.5f / (float)shadowMap->GetWidth();
-        texAdjust.SetTranslation(Vector3(offset, offset, 0.0f));
-        texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
-        
-        graphics->SetShaderParameter(VSP_SHADOWPROJ, texAdjust * shadowProj * shadowView);
-    }
-    
-    if ((light_) && (graphics->NeedParameterUpdate(VSP_SPOTPROJ, light_)))
-    {
-        const Matrix3x4& transform = light_->GetWorldTransform();
-        Matrix3x4 spotView(transform.Translation(), transform.Rotation(), 1.0f);
-        
-        Matrix4 spotProj(Matrix4::ZERO);
-        // Make the projected light slightly smaller than the shadow map to prevent light spill
-        float h = 1.005f / tanf(light_->GetFov() * M_DEGTORAD * 0.5f);
-        float w = h / light_->GetAspectRatio();
-        spotProj.m00_ = w;
-        spotProj.m11_ = h;
-        spotProj.m22_ = 1.0f / Max(light_->GetRange(), M_EPSILON);
-        spotProj.m32_ = 1.0f;
-        
-        Matrix4 texAdjust(Matrix4::IDENTITY);
-        texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
-        texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
-        
-        graphics->SetShaderParameter(VSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse());
-    }
-    
     if (overrideView_)
     {
         // If we override the view matrix, also disable any projection jittering
@@ -209,6 +149,10 @@ void Batch::Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& sha
     if (graphics->NeedParameterUpdate(VSP_VIEWUPVECTOR, camera_))
         graphics->SetShaderParameter(VSP_VIEWUPVECTOR, camera_->GetUpVector());
     
+    // Set model transform
+    if ((SetModelTransform) && (graphics->NeedParameterUpdate(VSP_MODEL, worldTransform_)))
+        graphics->SetShaderParameter(VSP_MODEL, *worldTransform_);
+    
     // Set skinning transforms
     if ((shaderData_) && (shaderDataSize_))
     {
@@ -216,9 +160,30 @@ void Batch::Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& sha
             graphics->SetShaderParameter(VSP_SKINMATRICES, (const float*)shaderData_, shaderDataSize_);
     }
     
-    // Set light-related parameters
+    // Set light-related shader parameters
     if (light_)
     {
+        if (graphics->NeedParameterUpdate(VSP_SPOTPROJ, light_))
+        {
+            const Matrix3x4& transform = light_->GetWorldTransform();
+            Matrix3x4 spotView(transform.Translation(), transform.Rotation(), 1.0f);
+            
+            Matrix4 spotProj(Matrix4::ZERO);
+            // Make the projected light slightly smaller than the shadow map to prevent light spill
+            float h = 1.005f / tanf(light_->GetFov() * M_DEGTORAD * 0.5f);
+            float w = h / light_->GetAspectRatio();
+            spotProj.m00_ = w;
+            spotProj.m11_ = h;
+            spotProj.m22_ = 1.0f / Max(light_->GetRange(), M_EPSILON);
+            spotProj.m32_ = 1.0f;
+            
+            Matrix4 texAdjust(Matrix4::IDENTITY);
+            texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
+            texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
+            
+            graphics->SetShaderParameter(VSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse());
+        }
+        
         if (graphics->NeedParameterUpdate(PSP_LIGHTATTEN, light_))
         {
             Vector4 light_Atten(1.0f / Max(light_->GetRange(), M_EPSILON), 0.0f, 0.0f, 0.0f);
@@ -269,11 +234,52 @@ void Batch::Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& sha
             
             graphics->SetShaderParameter(PSP_LIGHTVECROT, light_VecRot);
         }
+        
+        if (graphics->NeedParameterUpdate(PSP_SPOTPROJ, light_))
+        {
+            Matrix3x4 spotView(light_->GetWorldPosition(), light_->GetWorldRotation(), 1.0f);
+            Matrix4 spotProj(Matrix4::IDENTITY);
+            
+            // Make the projected light slightly smaller than the shadow map to prevent light spill
+            float h = 1.005f / tanf(light_->GetFov() * M_DEGTORAD * 0.5f);
+            float w = h / light_->GetAspectRatio();
+            spotProj.m00_ = w;
+            spotProj.m11_ = h;
+            spotProj.m22_ = 1.0f / Max(light_->GetRange(), M_EPSILON);
+            spotProj.m32_ = 1.0f;
+            
+            Matrix3x4 viewPos(Matrix3x4::IDENTITY);
+            viewPos.SetTranslation(camera_->GetWorldPosition());
+            
+            Matrix4 texAdjust(Matrix4::IDENTITY);
+            texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
+            texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
+            
+            graphics->SetShaderParameter(PSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse() * viewPos);
+        }
     }
     
-    // Set shadow & spotlight projection parameters
+    // Set shadow mapping shader parameters
+    Texture2D* shadowMap = 0;
+    if (light_)
+        shadowMap = light_->GetShadowMap();
+    
     if (shadowMap)
     {
+        if (graphics->NeedParameterUpdate(VSP_SHADOWPROJ, light_))
+        {
+            Camera* shadowCamera = light_->GetShadowCamera();
+            Matrix3x4 shadowView(shadowCamera->GetInverseWorldTransform());
+            Matrix4 shadowProj(shadowCamera->GetProjection());
+            
+            Matrix4 texAdjust(Matrix4::IDENTITY);
+            float offset = 0.5f + 0.5f / (float)shadowMap->GetWidth();
+            texAdjust.SetTranslation(Vector3(offset, offset, 0.0f));
+            texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
+            
+            graphics->SetShaderParameter(VSP_SHADOWPROJ, texAdjust * shadowProj * shadowView);
+        }
+        
         if (graphics->NeedParameterUpdate(PSP_SAMPLEOFFSETS, shadowMap))
         {
             float invWidth = 1.0f / (float)shadowMap->GetWidth();
@@ -309,42 +315,41 @@ void Batch::Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& sha
         }
     }
     
-    if ((light_) && (graphics->NeedParameterUpdate(PSP_SPOTPROJ, light_)))
+    // Set material-specific textures
+    if (material_)
     {
-        Matrix3x4 spotView(light_->GetWorldPosition(), light_->GetWorldRotation(), 1.0f);
-        Matrix4 spotProj(Matrix4::IDENTITY);
-        
-        // Make the projected light slightly smaller than the shadow map to prevent light spill
-        float h = 1.005f / tanf(light_->GetFov() * M_DEGTORAD * 0.5f);
-        float w = h / light_->GetAspectRatio();
-        spotProj.m00_ = w;
-        spotProj.m11_ = h;
-        spotProj.m22_ = 1.0f / Max(light_->GetRange(), M_EPSILON);
-        spotProj.m32_ = 1.0f;
-        
-        Matrix3x4 viewPos(Matrix3x4::IDENTITY);
-        viewPos.SetTranslation(camera_->GetWorldPosition());
-        
-        Matrix4 texAdjust(Matrix4::IDENTITY);
-        texAdjust.SetTranslation(Vector3(0.5f, 0.5f, 0.0f));
-        texAdjust.SetScale(Vector3(0.5f, -0.5f, 1.0f));
+        const Vector<SharedPtr<Texture> >& textures = material_->GetTextures();
         
-        graphics->SetShaderParameter(PSP_SPOTPROJ, texAdjust * spotProj * spotView.Inverse() * viewPos);
+        if (graphics->NeedTextureUnit(TU_DIFFUSE))
+            graphics->SetTexture(TU_DIFFUSE, textures[TU_DIFFUSE]);
+        if (graphics->NeedTextureUnit(TU_NORMAL))
+            graphics->SetTexture(TU_NORMAL, textures[TU_NORMAL]);
+        if (graphics->NeedTextureUnit(TU_SPECULAR))
+            graphics->SetTexture(TU_SPECULAR, textures[TU_SPECULAR]);
+        if (graphics->NeedTextureUnit(TU_DETAIL))
+            graphics->SetTexture(TU_DETAIL, textures[TU_DETAIL]);
+        if (graphics->NeedTextureUnit(TU_ENVIRONMENT))
+            graphics->SetTexture(TU_ENVIRONMENT, textures[TU_ENVIRONMENT]);
+        if (!light_)
+        {
+            if (graphics->NeedTextureUnit(TU_EMISSIVE))
+                graphics->SetTexture(TU_EMISSIVE, textures[TU_EMISSIVE]);
+        }
     }
     
-    // Set material's shader parameters
-    if (material_)
+    // Set light-related textures
+    if (light_)
     {
-        const Map<ShaderParameter, Vector4>& parameters = material_->GetShaderParameters();
-        for (Map<ShaderParameter, Vector4>::ConstIterator i = parameters.Begin(); i != parameters.End(); ++i)
-        {
-            if (graphics->NeedParameterUpdate(i->first_, material_))
-                graphics->SetShaderParameter(i->first_, i->second_);
-        }
+        if ((shadowMap) && (graphics->NeedTextureUnit(TU_SHADOWMAP)))
+            graphics->SetTexture(TU_SHADOWMAP, shadowMap);
+        if (graphics->NeedTextureUnit(TU_LIGHTRAMP))
+            graphics->SetTexture(TU_LIGHTRAMP, light_->GetRampTexture());
+        if (graphics->NeedTextureUnit(TU_LIGHTSPOT))
+            graphics->SetTexture(TU_LIGHTSPOT, light_->GetShapeTexture());
     }
 }
 
-void Batch::Draw(Graphics* graphics, const Map<ShaderParameter, Vector4>& shaderParameters) const
+void Batch::Draw(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters) const
 {
     Prepare(graphics, shaderParameters);
     geometry_->Draw(graphics);
@@ -366,7 +371,7 @@ void BatchGroup::SetTransforms(void* lockedData, unsigned& freeIndex)
     freeIndex += instances_.Size();
 }
 
-void BatchGroup::Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const Map<ShaderParameter, Vector4>& shaderParameters) const
+void BatchGroup::Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const HashMap<ShaderParameter, Vector4>& shaderParameters) const
 {
     if (!instances_.Size())
         return;

+ 4 - 3
Engine/Graphics/Batch.h

@@ -23,6 +23,7 @@
 
 #pragma once
 
+#include "HashMap.h"
 #include "MathDefs.h"
 #include "GraphicsDefs.h"
 #include "SharedPtr.h"
@@ -56,9 +57,9 @@ struct Batch
     /// Calculate sort key, which consists of priority flag, light, pass and geometry
     void CalculateSortKey();
     /// Prepare for rendering
-    void Prepare(Graphics* graphics, const Map<ShaderParameter, Vector4>& shaderParameters, bool SetModelTransform = true) const;
+    void Prepare(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters, bool SetModelTransform = true) const;
     /// Prepare and draw
-    void Draw(Graphics* graphics, const Map<ShaderParameter, Vector4>& shaderParameters) const;
+    void Draw(Graphics* graphics, const HashMap<ShaderParameter, Vector4>& shaderParameters) const;
     
     /// Geometry
     Geometry* geometry_;
@@ -132,7 +133,7 @@ struct BatchGroup
     /// Pre-set the instance transforms. Buffer must be big enough to hold all transforms
     void SetTransforms(void* lockedData, unsigned& freeIndex);
     /// Prepare and draw
-    void Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const Map<ShaderParameter, Vector4>& shaderParameters) const;
+    void Draw(Graphics* graphics, VertexBuffer* instanceBuffer, const HashMap<ShaderParameter, Vector4>& shaderParameters) const;
     
     /// Geometry
     Geometry* geometry_;

+ 6 - 6
Engine/Graphics/Graphics.cpp

@@ -1079,21 +1079,21 @@ void Graphics::SetShaderParameter(ShaderParameter param, const Matrix3x4& matrix
         impl_->device_->SetPixelShaderConstantF(index, matrix.GetData(), 3);
 }
 
-bool Graphics::NeedParameterUpdate(ShaderParameter parameter, const void* source)
+bool Graphics::NeedParameterUpdate(ShaderParameter param, const void* source)
 {
-    if (parameter < PSP_AMBIENTCOLOR)
+    if (param < PSP_AMBIENTCOLOR)
     {
-        if ((vertexShader_) && (vertexShader_->HasParameter(parameter)) && (lastShaderParameterSources_[parameter] != source))
+        if ((vertexShader_) && (vertexShader_->HasParameter(param)) && (lastShaderParameterSources_[param] != source))
         {
-            lastShaderParameterSources_[parameter] = source;
+            lastShaderParameterSources_[param] = source;
             return true;
         }
     }
     else
     {
-        if ((pixelShader_) && (pixelShader_->HasParameter(parameter)) && (lastShaderParameterSources_[parameter] != source))
+        if ((pixelShader_) && (pixelShader_->HasParameter(param)) && (lastShaderParameterSources_[param] != source))
         {
-            lastShaderParameterSources_[parameter] = source;
+            lastShaderParameterSources_[param] = source;
             return true;
         }
     }

+ 5 - 9
Engine/Graphics/Graphics.h

@@ -100,7 +100,7 @@ public:
     void SetIndexBuffer(IndexBuffer* buffer);
     /// Set shaders
     void SetShaders(ShaderVariation* vs, ShaderVariation* ps);
-    /// Set shader bool parameter
+    /// Set shader bool constants
     void SetShaderParameter(ShaderParameter param, const bool* data, unsigned count);
     /// Set shader float constants
     void SetShaderParameter(ShaderParameter param, const float* data, unsigned count);
@@ -123,7 +123,7 @@ public:
     /// Map shader parameter to a constant register. Called by Shader
     void SetShaderRegister(ShaderParameter param, unsigned index) { shaderRegisters_[param] = index; }
     /// Check whether a shader parameter in the currently set shaders needs update
-    bool NeedParameterUpdate(ShaderParameter parameter, const void* source);
+    bool NeedParameterUpdate(ShaderParameter param, const void* source);
     /// Check whether the current pixel shader uses a texture unit
     bool NeedTextureUnit(TextureUnit unit);
     /// Clear remembered shader parameter sources
@@ -134,6 +134,8 @@ public:
     void SetTexture(unsigned index, Texture* texture);
     /// Set default texture filtering mode
     void SetDefaultTextureFilterMode(TextureFilterMode mode);
+    /// Set texture anisotropy
+    void SetTextureAnisotropy(unsigned level);
     /// Reset all render targets and depth buffer (render to back buffer and back buffer depth stencil)
     void ResetRenderTargets();
     /// Reset specific render target
@@ -154,8 +156,6 @@ public:
     void SetViewTexture(Texture* texture);
     /// Set alpha test
     void SetAlphaTest(bool enable, CompareMode mode = CMP_ALWAYS, float alphaRef = 0.5f);
-    /// Set texture anisotropy
-    void SetTextureAnisotropy(unsigned level);
     /// Set blending mode
     void SetBlendMode(BlendMode mode);
     /// Set color write on/off
@@ -199,7 +199,7 @@ public:
     
     /// Return whether rendering initialized
     bool IsInitialized() const;
-    /// Return graphics implementation, which holds the actual Direct3D resources
+    /// Return graphics implementation, which holds the actual API-specific resources
     GraphicsImpl* GetImpl() const { return impl_; }
     /// Return window title
     const String& GetWindowTitle() const { return windowTitle_; }
@@ -267,10 +267,6 @@ public:
     const String& GetShaderParameterName(ShaderParameter parameter);
     /// Return texture unit name by index
     const String& GetTextureUnitName(TextureUnit unit);
-    /// Return vertex shader constant register by parameter index
-    unsigned GetVSRegister(ShaderParameter param) { return shaderRegisters_[param]; }
-    /// Return pixel shader constant register by parameter index
-    unsigned GetPSRegister(ShaderParameter param) { return shaderRegisters_[param]; }
     /// Return texture by texture unit index
     Texture* GetTexture(unsigned index) const;
     /// Return the "view texture"

+ 7 - 0
Engine/Graphics/GraphicsDefs.h

@@ -23,6 +23,8 @@
 
 #pragma once
 
+#include "HashBase.h"
+
 /// Rendering mode
 enum RenderMode
 {
@@ -243,6 +245,11 @@ enum ShaderParameter
     MAX_SHADER_PARAMETERS
 };
 
+template<> inline unsigned MakeHash(const ShaderParameter& param)
+{
+    return (unsigned)param;
+}
+
 /// Texture units
 enum TextureUnit
 {

+ 1 - 1
Engine/Graphics/Material.cpp

@@ -239,7 +239,7 @@ bool Material::Save(Serializer& dest)
     }
     
     // Write shader parameters
-    for (Map<ShaderParameter, Vector4>::ConstIterator j = shaderParameters_.Begin(); j != shaderParameters_.End(); ++j)
+    for (HashMap<ShaderParameter, Vector4>::ConstIterator j = shaderParameters_.Begin(); j != shaderParameters_.End(); ++j)
     {
         XMLElement parameterElem = materialElem.CreateChildElement("parameter");
         parameterElem.SetString("name", graphics->GetShaderParameterName(j->first_));

+ 3 - 2
Engine/Graphics/Material.h

@@ -24,6 +24,7 @@
 #pragma once
 
 #include "GraphicsDefs.h"
+#include "HashMap.h"
 #include "Resource.h"
 #include "Vector4.h"
 
@@ -107,7 +108,7 @@ public:
     /// Return texture by unit
     Texture* GetTexture(TextureUnit unit) const;
     /// Return all shader parameters
-    const Map<ShaderParameter, Vector4>& GetShaderParameters() const { return shaderParameters_; }
+    const HashMap<ShaderParameter, Vector4>& GetShaderParameters() const { return shaderParameters_; }
     /// Return normal culling mode
     CullMode GetCullMode() const { return cullMode_; }
     /// Return culling mode for shadows
@@ -129,7 +130,7 @@ private:
     /// Textures
     Vector<SharedPtr<Texture> > textures_;
     /// Shader parameters
-    Map<ShaderParameter, Vector4> shaderParameters_;
+    HashMap<ShaderParameter, Vector4> shaderParameters_;
     /// Normal culling mode
     CullMode cullMode_;
     /// Culling mode for shadow rendering

+ 2 - 2
Engine/Graphics/Renderer.cpp

@@ -1446,7 +1446,7 @@ void Renderer::SetupLightBatch(Batch& batch)
     }
 }
 
-void Renderer::DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const Map<ShaderParameter, Vector4>& shaderParameters)
+void Renderer::DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const HashMap<ShaderParameter, Vector4>& shaderParameters)
 {
     graphics_->ClearTransformSources();
     
@@ -1460,7 +1460,7 @@ void Renderer::DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVar
     graphics_->SetShaderParameter(VSP_VIEWPROJ, camera.GetProjection(false));
     
     // Set global shader parameters as needed
-    for (Map<ShaderParameter, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
+    for (HashMap<ShaderParameter, Vector4>::ConstIterator i = shaderParameters.Begin(); i != shaderParameters.End(); ++i)
     {
         if (graphics_->NeedParameterUpdate(i->first_, &shaderParameters))
             graphics_->SetShaderParameter(i->first_, i->second_);

+ 1 - 1
Engine/Graphics/Renderer.h

@@ -302,7 +302,7 @@ private:
     /// Set up a light volume rendering batch
     void SetupLightBatch(Batch& batch);
     /// Draw a full screen quad (either near or far)
-    void DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const Map<ShaderParameter, Vector4>& shaderParameters);
+    void DrawFullScreenQuad(Camera& camera, ShaderVariation* vs, ShaderVariation* ps, bool nearQuad, const HashMap<ShaderParameter, Vector4>& shaderParameters);
     /// Handle screen mode event
     void HandleScreenMode(StringHash eventType, VariantMap& eventData);
     /// Handle render update event

+ 0 - 1
Engine/Graphics/View.cpp

@@ -378,7 +378,6 @@ void View::GetDrawables()
     Sort(lights_.Begin(), lights_.End(), CompareDrawables);
 }
 
-
 void View::GetBatches()
 {
     HashSet<LitTransparencyCheck> litTransparencies;

+ 1 - 1
Engine/Graphics/View.h

@@ -226,7 +226,7 @@ private:
     /// G-buffer size error displayed
     Set<RenderSurface*> gBufferErrorDisplayed_;
     /// View-global shader parameters
-    Map<ShaderParameter, Vector4> shaderParameters_;
+    HashMap<ShaderParameter, Vector4> shaderParameters_;
     
     /// G-buffer batches
     BatchQueue gBufferQueue_;