Browse Source

Fixed the UI not rendering on OpenGL.

Lasse Öörni 14 years ago
parent
commit
483413e472

+ 1 - 1
Docs/Urho3D.dox

@@ -2,7 +2,7 @@
 
 \mainpage Urho3D rendering and game engine
 
-Urho3D is a lightweight, object-oriented rendering and game engine written in C++.
+Urho3D is a lightweight, object-oriented rendering and game engine written in C++, that utilizes either Direct3D9 or OpenGL for rendering.
 
 For getting started, see:
 

+ 23 - 0
Engine/Graphics/OGL/OGLGraphics.cpp

@@ -397,6 +397,13 @@ bool Graphics::BeginFrame()
     SetColorWrite(true);
     SetDepthWrite(true);
     
+    // Reset immediate mode vertex buffer positions
+    for (Map<unsigned, unsigned>::Iterator i = immediateVertexBufferPos_.Begin(); i != immediateVertexBufferPos_.End(); ++i)
+        i->second_ = 0;
+    
+    numPrimitives_ = 0;
+    numBatches_ = 0;
+    
     SendEvent(E_BEGINRENDER);
     
     return true;
@@ -502,6 +509,10 @@ void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount
     ++numBatches_;
 }
 
+void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount)
+{
+}
+
 void Graphics::SetVertexBuffer(VertexBuffer* buffer)
 {
     Vector<VertexBuffer*> vertexBuffers(1);
@@ -1590,6 +1601,14 @@ void Graphics::SetScissorTest(bool enable, const IntRect& rect)
     }
 }
 
+void Graphics::SetStreamFrequency(unsigned index, unsigned frequency)
+{
+}
+
+void Graphics::ResetStreamFrequencies()
+{
+}
+
 void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, StencilOp fail, StencilOp zFail, unsigned stencilRef, unsigned stencilMask)
 {
     if (enable != stencilTest_)
@@ -1762,6 +1781,10 @@ void Graphics::EndImmediate()
     }
 }
 
+void Graphics::SetForceSM2(bool enable)
+{
+}
+
 unsigned char* Graphics::GetImmediateDataPtr() const
 {
     if (!immediateBuffer_)

+ 4 - 4
Engine/Graphics/OGL/OGLGraphics.h

@@ -91,7 +91,7 @@ public:
     /// Draw indexed geometry
     void Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount);
     /// Draw indexed, instanced geometry. No-op on OpenGL
-    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount) {}
+    void DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount);
     /// Set vertex buffer
     void SetVertexBuffer(VertexBuffer* buffer);
     /// Set multiple vertex buffers
@@ -183,9 +183,9 @@ public:
     /// Set stencil test
     void SetStencilTest(bool enable, CompareMode mode = CMP_ALWAYS, StencilOp pass = OP_KEEP, StencilOp fail = OP_KEEP, StencilOp zFail = OP_KEEP, unsigned stencilRef = 0, unsigned stencilMask = M_MAX_UNSIGNED);
     /// Set vertex buffer stream frequency. No-op on OpenGL
-    void SetStreamFrequency(unsigned index, unsigned frequency) {}
+    void SetStreamFrequency(unsigned index, unsigned frequency);
     /// Reset stream frequencies. No-op on OpenGL
-    void ResetStreamFrequencies() {}
+    void ResetStreamFrequencies();
     /// Begin immediate rendering command
     bool BeginImmediate(PrimitiveType type, unsigned vertexCount, unsigned elementMask);
     /// Define immediate vertex
@@ -201,7 +201,7 @@ public:
     /// End immediate rendering command and render
     void EndImmediate();
     /// Set force Shader Model 2 flag. No effect on OpenGL
-    void SetForceSM2(bool enable) {}
+    void SetForceSM2(bool enable);
     
     /// Return whether rendering initialized
     bool IsInitialized() const;

+ 4 - 0
Engine/Graphics/OGL/OGLTexture.cpp

@@ -125,6 +125,10 @@ void Texture::SetParametersDirty()
     parametersDirty_ = true;
 }
 
+void Texture::ClearDataLost()
+{
+}    
+
 void Texture::UpdateParameters()
 {
     if ((!object_) || (!graphics_))

+ 1 - 1
Engine/Graphics/OGL/OGLTexture.h

@@ -57,7 +57,7 @@ public:
     /// Dirty the parameters
     void SetParametersDirty();
     /// Clear data lost flag. No-op on OpenGL
-    void ClearDataLost() {}
+    void ClearDataLost();
     /// Update changed parameters to OpenGL. Called by Graphics when binding the texture
     void UpdateParameters();
     

+ 1 - 1
Engine/UI/UI.cpp

@@ -280,7 +280,7 @@ void UI::Render()
         graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
         graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
         
-        batches_[i].Draw(graphics_, vs, ps);
+        batches_[i].Draw(graphics_);
     }
 }
 

+ 25 - 22
Engine/UI/UIBatch.cpp

@@ -165,7 +165,7 @@ bool UIBatch::Merge(const UIBatch& batch)
     return true;
 }
 
-void UIBatch::Draw(Graphics* graphics, ShaderVariation* vs, ShaderVariation* ps) const
+void UIBatch::Draw(Graphics* graphics) const
 {
     if ((!quads_) || (!quadCount_))
         return;
@@ -179,9 +179,12 @@ void UIBatch::Draw(Graphics* graphics, ShaderVariation* vs, ShaderVariation* ps)
     graphics->SetBlendMode(blendMode_);
     graphics->SetScissorTest(true, scissor_);
     graphics->SetTexture(0, texture_);
-    graphics->SetShaders(vs, ps);
     
+    #ifdef USE_OPENGL
+    Vector2 posAdjust(Vector2::ZERO);
+    #else
     Vector2 posAdjust(0.5f, 0.5f);
+    #endif
     Vector2 invScreenSize(1.0f / (float)graphics->GetWidth(), 1.0f / (float)graphics->GetHeight());
     
     const PODVector<UIQuad>& quads = *quads_;
@@ -196,36 +199,36 @@ void UIBatch::Draw(Graphics* graphics, ShaderVariation* vs, ShaderVariation* ps)
         for (unsigned i = quadStart_; i < quadStart_ + quadCount_; ++i)
         {
             const UIQuad& quad = quads[i];
-            Vector2 topLeft, bottoright_, topLeftUV, bottorightUV_;
+            Vector2 topLeft, bottomRight, topLeftUV, bottomRightUV;
             
             topLeft = (Vector2((float)quad.left_, (float)quad.top_) - posAdjust) * invScreenSize;
-            bottoright_ = (Vector2((float)quad.right_, (float)quad.bottom_) - posAdjust) * invScreenSize;
+            bottomRight = (Vector2((float)quad.right_, (float)quad.bottom_) - posAdjust) * invScreenSize;
             topLeftUV = Vector2((float)quad.leftUV_, (float)quad.topUV_) * invTextureSize;
-            bottorightUV_ = Vector2((float)quad.rightUV_, (float)quad.bottomUV_) * invTextureSize;
+            bottomRightUV = Vector2((float)quad.rightUV_, (float)quad.bottomUV_) * invTextureSize;
             
             *dest++ = topLeft.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].topLeftColor_; dest++;
             *dest++ = topLeftUV.x_; *dest++ = topLeftUV.y_;
             
-            *dest++ = bottoright_.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
+            *dest++ = bottomRight.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].topRightColor_; dest++;
-            *dest++ = bottorightUV_.x_; *dest++ = topLeftUV.y_;
+            *dest++ = bottomRightUV.x_; *dest++ = topLeftUV.y_;
             
-            *dest++ = topLeft.x_; *dest++ = bottoright_.y_; *dest++ = 0.0f;
+            *dest++ = topLeft.x_; *dest++ = bottomRight.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].bottomLeftColor_; dest++;
-            *dest++ = topLeftUV.x_; *dest++ = bottorightUV_.y_;
+            *dest++ = topLeftUV.x_; *dest++ = bottomRightUV.y_;
             
-            *dest++ = bottoright_.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
+            *dest++ = bottomRight.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].topRightColor_; dest++;
-            *dest++ = bottorightUV_.x_; *dest++ = topLeftUV.y_;
+            *dest++ = bottomRightUV.x_; *dest++ = topLeftUV.y_;
             
-            *dest++ = bottoright_.x_; *dest++ = bottoright_.y_; *dest++ = 0.0f;
+            *dest++ = bottomRight.x_; *dest++ = bottomRight.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].bottomRightColor_; dest++;
-            *dest++ = bottorightUV_.x_; *dest++ = bottorightUV_.y_;
+            *dest++ = bottomRightUV.x_; *dest++ = bottomRightUV.y_;
             
-            *dest++ = topLeft.x_; *dest++ = bottoright_.y_; *dest++ = 0.0f;
+            *dest++ = topLeft.x_; *dest++ = bottomRight.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].bottomLeftColor_; dest++;
-            *dest++ = topLeftUV.x_; *dest++ = bottorightUV_.y_;
+            *dest++ = topLeftUV.x_; *dest++ = bottomRightUV.y_;
         }
         
         graphics->EndImmediate();
@@ -238,27 +241,27 @@ void UIBatch::Draw(Graphics* graphics, ShaderVariation* vs, ShaderVariation* ps)
         for (unsigned i = quadStart_; i < quadStart_ + quadCount_; ++i)
         {
             const UIQuad& quad = quads[i];
-            Vector2 topLeft, bottoright_, topLeftUV, bottorightUV_;
+            Vector2 topLeft, bottomRight, topLeftUV, bottomRightUV;
             
             topLeft = (Vector2((float)quad.left_, (float)quad.top_) - posAdjust) * invScreenSize;
-            bottoright_ = (Vector2((float)quad.right_, (float)quad.bottom_) - posAdjust) * invScreenSize;
+            bottomRight = (Vector2((float)quad.right_, (float)quad.bottom_) - posAdjust) * invScreenSize;
             
             *dest++ = topLeft.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].topLeftColor_; dest++;
             
-            *dest++ = bottoright_.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
+            *dest++ = bottomRight.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].topRightColor_; dest++;
             
-            *dest++ = topLeft.x_; *dest++ = bottoright_.y_; *dest++ = 0.0f;
+            *dest++ = topLeft.x_; *dest++ = bottomRight.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].bottomLeftColor_; dest++;
             
-            *dest++ = bottoright_.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
+            *dest++ = bottomRight.x_; *dest++ = topLeft.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].topRightColor_; dest++;
             
-            *dest++ = bottoright_.x_; *dest++ = bottoright_.y_; *dest++ = 0.0f;
+            *dest++ = bottomRight.x_; *dest++ = bottomRight.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].bottomRightColor_; dest++;
             
-            *dest++ = topLeft.x_; *dest++ = bottoright_.y_; *dest++ = 0.0f;
+            *dest++ = topLeft.x_; *dest++ = bottomRight.y_; *dest++ = 0.0f;
             *((unsigned*)dest) = quads[i].bottomLeftColor_; dest++;
         }
         

+ 1 - 1
Engine/UI/UIBatch.h

@@ -86,7 +86,7 @@ public:
     /// Merge with another batch
     bool Merge(const UIBatch& batch);
     /// Draw
-    void Draw(Graphics* graphics, ShaderVariation* vs, ShaderVariation* ps) const;
+    void Draw(Graphics* graphics) const;
     
     /// Add or merge a batch
     static void AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches);

+ 2 - 2
Readme.txt

@@ -1,5 +1,5 @@
-Urho3D - a rendering and game engine
-------------------------------------
+Urho3D - Direct3D9 / OpenGL rendering and game engine
+-----------------------------------------------------
 
 http://urho3d.googlecode.com