Browse Source

Converted DebugGeometry to use a vertex buffer instead of using immediate rendering.
Removed immediate rendering.

Lasse Öörni 14 years ago
parent
commit
2f74622427

+ 1 - 3
Docs/Reference.dox

@@ -291,7 +291,7 @@ ScriptObject@ object = node.CreateScriptObject("Scripts/MyClass.as", "MyClass");
 
 
 \section Script_ScriptAPI The script API
 \section Script_ScriptAPI The script API
 
 
-Much of the Urho3D classes are exposed to scripts, however things that require low-level access or high performance (like direct vertex buffer access or immediate rendering) are not. Also for scripting convenience some things have been changed from the C++ API:
+Much of the Urho3D classes are exposed to scripts, however things that require low-level access or high performance (like direct vertex buffer access) are not. Also for scripting convenience some things have been changed from the C++ API:
 
 
 - The template array and string classes are exposed as Array<type> and String.
 - The template array and string classes are exposed as Array<type> and String.
 
 
@@ -367,8 +367,6 @@ Graphics implements the low-level functionality:
 - Handling lost device
 - Handling lost device
 - Performing primitive rendering operations
 - Performing primitive rendering operations
 
 
-It also provides a low-performance, immediate-like interface for manually defining small amounts of geometry to be rendered. This interface is used for rendering the debug geometry.
-
 Screen resolution, fullscreen/windowed, vertical sync and hardware multisampling level are all set at once by calling Graphics's \ref Graphics::SetMode "SetMode()" function.
 Screen resolution, fullscreen/windowed, vertical sync and hardware multisampling level are all set at once by calling Graphics's \ref Graphics::SetMode "SetMode()" function.
 
 
 When setting the initial screen mode, Graphics does a few checks:
 When setting the initial screen mode, Graphics does a few checks:

+ 46 - 37
Engine/Graphics/DebugRenderer.cpp

@@ -35,6 +35,7 @@
 #include "Renderer.h"
 #include "Renderer.h"
 #include "ResourceCache.h"
 #include "ResourceCache.h"
 #include "ShaderVariation.h"
 #include "ShaderVariation.h"
+#include "VertexBuffer.h"
 
 
 #include "DebugNew.h"
 #include "DebugNew.h"
 
 
@@ -43,6 +44,8 @@ OBJECTTYPESTATIC(DebugRenderer);
 DebugRenderer::DebugRenderer(Context* context) :
 DebugRenderer::DebugRenderer(Context* context) :
     Component(context)
     Component(context)
 {
 {
+    vertexBuffer_ = new VertexBuffer(context_);
+    
     SubscribeToEvent(E_ENDFRAME, HANDLER(DebugRenderer, HandleEndFrame));
     SubscribeToEvent(E_ENDFRAME, HANDLER(DebugRenderer, HandleEndFrame));
 }
 }
 
 
@@ -248,17 +251,52 @@ void DebugRenderer::Render()
     if (lines_.Empty() && noDepthLines_.Empty())
     if (lines_.Empty() && noDepthLines_.Empty())
         return;
         return;
     
     
-    PROFILE(RenderDebugGeometry);
-    
     Graphics* graphics = GetSubsystem<Graphics>();
     Graphics* graphics = GetSubsystem<Graphics>();
     Renderer* renderer = GetSubsystem<Renderer>();
     Renderer* renderer = GetSubsystem<Renderer>();
     
     
+    if (!graphics || graphics->IsDeviceLost())
+        return;
+    
+    PROFILE(RenderDebugGeometry);
+    
+    unsigned numVertices = (lines_.Size() + noDepthLines_.Size()) * 2;
+    if (vertexBuffer_->GetVertexCount() < numVertices)
+        vertexBuffer_->SetSize(numVertices, MASK_POSITION | MASK_COLOR, true);
+    void* lockedData = vertexBuffer_->Lock(0, numVertices, LOCK_DISCARD);
+    if (!lockedData)
+        return;
+    
+    float* dest = (float*)lockedData;
+    
+    for (unsigned i = 0; i < lines_.Size(); ++i)
+    {
+        const DebugLine& line = lines_[i];
+            
+        *dest++ = line.start_.x_; *dest++ = line.start_.y_; *dest++ = line.start_.z_;
+        *((unsigned*)dest) = line.color_; dest++;
+            
+        *dest++ = line.end_.x_; *dest++ = line.end_.y_; *dest++ = line.end_.z_;
+        *((unsigned*)dest) = line.color_; dest++;
+    }
+    
+    for (unsigned i = 0; i < noDepthLines_.Size(); ++i)
+    {
+        const DebugLine& line = noDepthLines_[i];
+            
+        *dest++ = line.start_.x_; *dest++ = line.start_.y_; *dest++ = line.start_.z_;
+        *((unsigned*)dest) = line.color_; dest++;
+            
+        *dest++ = line.end_.x_; *dest++ = line.end_.y_; *dest++ = line.end_.z_;
+        *((unsigned*)dest) = line.color_; dest++;
+    }
+    
+    vertexBuffer_->Unlock();
+    
     graphics->SetAlphaTest(false);
     graphics->SetAlphaTest(false);
     graphics->SetBlendMode(BLEND_REPLACE);
     graphics->SetBlendMode(BLEND_REPLACE);
     graphics->SetColorWrite(true);
     graphics->SetColorWrite(true);
     graphics->SetCullMode(CULL_NONE);
     graphics->SetCullMode(CULL_NONE);
     graphics->SetDepthWrite(true);
     graphics->SetDepthWrite(true);
-    graphics->SetDepthTest(CMP_LESSEQUAL);
     graphics->SetFillMode(FILL_SOLID);
     graphics->SetFillMode(FILL_SOLID);
     graphics->SetScissorTest(false);
     graphics->SetScissorTest(false);
     graphics->SetStencilTest(false);
     graphics->SetStencilTest(false);
@@ -266,46 +304,17 @@ void DebugRenderer::Render()
     graphics->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
     graphics->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
     graphics->SetShaderParameter(VSP_VIEWPROJ, projection_ * view_);
     graphics->SetShaderParameter(VSP_VIEWPROJ, projection_ * view_);
     graphics->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
     graphics->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
+    graphics->SetVertexBuffer(vertexBuffer_);
     
     
-    // Draw all line geometry with depth testing
     if (lines_.Size())
     if (lines_.Size())
     {
     {
-        graphics->BeginImmediate(LINE_LIST, lines_.Size() * 2, MASK_POSITION | MASK_COLOR);
-        float* dest = (float*)graphics->GetImmediateDataPtr();
-        
-        for (unsigned i = 0; i < lines_.Size(); ++i)
-        {
-            const DebugLine& line = lines_[i];
-            
-            *dest++ = line.start_.x_; *dest++ = line.start_.y_; *dest++ = line.start_.z_;
-            *((unsigned*)dest) = line.color_; dest++;
-            
-            *dest++ = line.end_.x_; *dest++ = line.end_.y_; *dest++ = line.end_.z_;
-            *((unsigned*)dest) = line.color_; dest++;
-        }
-        
-        graphics->EndImmediate();
+        graphics->SetDepthTest(CMP_LESSEQUAL);
+        graphics->Draw(LINE_LIST, 0, lines_.Size() * 2);
     }
     }
-    
-    // Draw all line geometry without depth testing
-    graphics->SetDepthTest(CMP_ALWAYS);
     if (noDepthLines_.Size())
     if (noDepthLines_.Size())
     {
     {
-        graphics->BeginImmediate(LINE_LIST, noDepthLines_.Size() * 2, MASK_POSITION | MASK_COLOR);
-        float* dest = (float*)graphics->GetImmediateDataPtr();
-        
-        for (unsigned i = 0; i < noDepthLines_.Size(); ++i)
-        {
-            const DebugLine& line = noDepthLines_[i];
-            
-            *dest++ = line.start_.x_; *dest++ = line.start_.y_; *dest++ = line.start_.z_;
-            *((unsigned*)dest) = line.color_; dest++;
-            
-            *dest++ = line.end_.x_; *dest++ = line.end_.y_; *dest++ = line.end_.z_;
-            *((unsigned*)dest) = line.color_; dest++;
-        }
-        
-        graphics->EndImmediate();
+        graphics->SetDepthTest(CMP_ALWAYS);
+        graphics->Draw(LINE_LIST, lines_.Size() * 2, noDepthLines_.Size() * 2);
     }
     }
 }
 }
 
 

+ 4 - 3
Engine/Graphics/DebugRenderer.h

@@ -26,17 +26,16 @@
 #include "Color.h"
 #include "Color.h"
 #include "Component.h"
 #include "Component.h"
 #include "Frustum.h"
 #include "Frustum.h"
-#include "Ptr.h"
 
 
 class BoundingBox;
 class BoundingBox;
 class Camera;
 class Camera;
 class Polyhedron;
 class Polyhedron;
-class Frustum;
 class Drawable;
 class Drawable;
 class Light;
 class Light;
 class Matrix3x4;
 class Matrix3x4;
 class Renderer;
 class Renderer;
 class Skeleton;
 class Skeleton;
+class VertexBuffer;
 
 
 /// Debug rendering line.
 /// Debug rendering line.
 struct DebugLine
 struct DebugLine
@@ -93,7 +92,7 @@ public:
     void AddPolyhedron(const Polyhedron& poly, const Color& color, bool depthTest = true);
     void AddPolyhedron(const Polyhedron& poly, const Color& color, bool depthTest = true);
     /// Add a skeleton.
     /// Add a skeleton.
     void AddSkeleton(const Skeleton& skeleton, const Color& color, bool depthTest = true);
     void AddSkeleton(const Skeleton& skeleton, const Color& color, bool depthTest = true);
-    /// Render all debug lines. The viewport and rendertarget should be set before.
+    /// Update vertex buffer and render all debug lines. The viewport and rendertarget should be set before.
     void Render();
     void Render();
     
     
     /// Return the view transform.
     /// Return the view transform.
@@ -119,4 +118,6 @@ private:
     Matrix4 projection_;
     Matrix4 projection_;
     /// View frustum.
     /// View frustum.
     Frustum frustum_;
     Frustum frustum_;
+    /// Vertex buffer.
+    SharedPtr<VertexBuffer> vertexBuffer_;
 };
 };

+ 0 - 162
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -174,7 +174,6 @@ Graphics::Graphics(Context* context) :
     queryIndex_(0),
     queryIndex_(0),
     numPrimitives_(0),
     numPrimitives_(0),
     numBatches_(0),
     numBatches_(0),
-    immediateBuffer_(0),
     shaderParametersOverlap_(false),
     shaderParametersOverlap_(false),
     defaultTextureFilterMode_(FILTER_BILINEAR)
     defaultTextureFilterMode_(FILTER_BILINEAR)
 {
 {
@@ -410,8 +409,6 @@ void Graphics::Close()
 {
 {
     if (impl_->window_)
     if (impl_->window_)
     {
     {
-        immediateVertexBuffers_.Clear();
-        
         DestroyWindow(impl_->window_);
         DestroyWindow(impl_->window_);
         impl_->window_ = 0;
         impl_->window_ = 0;
     }
     }
@@ -545,10 +542,6 @@ bool Graphics::BeginFrame()
     // Cleanup stream frequencies from previous frame
     // Cleanup stream frequencies from previous frame
     ResetStreamFrequencies();
     ResetStreamFrequencies();
     
     
-    // Reset immediate mode vertex buffer positions
-    for (HashMap<unsigned, unsigned>::Iterator i = immediateVertexBufferPos_.Begin(); i != immediateVertexBufferPos_.End(); ++i)
-        i->second_ = 0;
-    
     numPrimitives_ = 0;
     numPrimitives_ = 0;
     numBatches_ = 0;
     numBatches_ = 0;
     
     
@@ -1689,148 +1682,6 @@ void Graphics::ResetStreamFrequencies()
     }
     }
 }
 }
 
 
-bool Graphics::BeginImmediate(PrimitiveType type, unsigned vertexCount, unsigned elementMask)
-{
-    if (immediateBuffer_)
-    {
-        LOGERROR("New immediate draw operation started before ending the last one");
-        return false;
-    }
-    if (!(elementMask & MASK_POSITION))
-    {
-        LOGERROR("Immediate draw operation must contain vertex positions");
-        return false;
-    }
-    if (!vertexCount)
-        return true;
-    
-    // Start from default size, ensure that buffer is big enough to hold the immediate draw operation
-    unsigned newSize = IMMEDIATE_BUFFER_DEFAULT_SIZE;
-    while (newSize < vertexCount)
-        newSize <<= 1;
-        
-    // See if buffer exists for this vertex format. If not, create new
-    if (!immediateVertexBuffers_.Contains(elementMask))
-    {
-        LOGDEBUG("Created immediate vertex buffer");
-        VertexBuffer* newBuffer = new VertexBuffer(context_);
-        newBuffer->SetSize(newSize, elementMask, true);
-        immediateVertexBuffers_[elementMask] = newBuffer;
-        immediateVertexBufferPos_[elementMask] = 0;
-    }
-    
-    // Resize buffer if it is too small
-    VertexBuffer* buffer = immediateVertexBuffers_[elementMask];
-    if (buffer->GetVertexCount() < newSize)
-    {
-        LOGDEBUG("Resized immediate vertex buffer to " + String(newSize));
-        buffer->SetSize(newSize, elementMask, true);
-        immediateVertexBufferPos_[elementMask] = 0;
-    }
-    
-    // Get the current lock position for the buffer
-    unsigned bufferPos = immediateVertexBufferPos_[elementMask];
-    if (bufferPos + vertexCount >= buffer->GetVertexCount())
-        bufferPos = 0;
-    
-    LockMode lockMode = LOCK_DISCARD;
-    if (bufferPos != 0)
-        lockMode = LOCK_NOOVERWRITE;
-    
-    // Note: the data pointer gets pre-decremented here, because the first call to DefineVertex() will increment it
-    immediateDataPtr_ = ((unsigned char*)buffer->Lock(bufferPos, vertexCount, lockMode)) - buffer->GetVertexSize();
-    immediateBuffer_ = buffer;
-    immediateType_= type;
-    immediateStartPos_ = bufferPos;
-    immediateVertexCount_ = vertexCount;
-    immediateCurrentVertex_ = 0;
-    
-    // Store new buffer position for next lock into the same buffer
-    bufferPos += vertexCount;
-    if (bufferPos >= buffer->GetVertexCount())
-        bufferPos = 0;
-    immediateVertexBufferPos_[elementMask] = bufferPos;
-    
-    return true;
-}
-
-bool Graphics::DefineVertex(const Vector3& vertex)
-{
-    if (!immediateBuffer_ || immediateCurrentVertex_ >= immediateVertexCount_)
-        return false;
-    
-    immediateDataPtr_ += immediateBuffer_->GetVertexSize();
-    ++immediateCurrentVertex_;
-    
-    float* dest = (float*)(immediateDataPtr_ + immediateBuffer_->GetElementOffset(ELEMENT_POSITION));
-    const float* src = vertex.GetData();
-    dest[0] = src[0];
-    dest[1] = src[1];
-    dest[2] = src[2];
-    
-    return true;
-}
-
-bool Graphics::DefineNormal(const Vector3& normal)
-{
-    if (!immediateBuffer_ || !(immediateBuffer_->GetElementMask() & MASK_NORMAL) || !immediateCurrentVertex_)
-        return false;
-    
-    float* dest = (float*)(immediateDataPtr_ + immediateBuffer_->GetElementOffset(ELEMENT_NORMAL));
-    const float* src = normal.GetData();
-    dest[0] = src[0];
-    dest[1] = src[1];
-    dest[2] = src[2];
-    
-    return true;
-}
-
-bool Graphics::DefineTexCoord(const Vector2& texCoord)
-{
-    if (!immediateBuffer_ || !(immediateBuffer_->GetElementMask() & MASK_TEXCOORD1) || !immediateCurrentVertex_)
-        return false;
-    
-    float* dest = (float*)(immediateDataPtr_ + immediateBuffer_->GetElementOffset(ELEMENT_TEXCOORD1));
-    const float* src = texCoord.GetData();
-    dest[0] = src[0];
-    dest[1] = src[1];
-    
-    return true;
-}
-
-bool Graphics::DefineColor(const Color& color)
-{
-    if (!immediateBuffer_ || !(immediateBuffer_->GetElementMask() & MASK_COLOR) || !immediateCurrentVertex_)
-        return false;
-    
-    unsigned* dest = (unsigned*)(immediateDataPtr_ + immediateBuffer_->GetElementOffset(ELEMENT_COLOR));
-    *dest = color.ToUInt();
-    
-    return true;
-}
-
-bool Graphics::DefineColor(unsigned color)
-{
-    if (!immediateBuffer_ || !(immediateBuffer_->GetElementMask() & MASK_COLOR) || !immediateCurrentVertex_)
-        return false;
-    
-    unsigned* dest = (unsigned*)(immediateDataPtr_ + immediateBuffer_->GetElementOffset(ELEMENT_COLOR));
-    *dest = color;
-    
-    return true;
-}
-
-void Graphics::EndImmediate()
-{
-    if (immediateBuffer_)
-    {
-        immediateBuffer_->Unlock();
-        SetVertexBuffer(immediateBuffer_);
-        Draw(immediateType_, immediateStartPos_, immediateVertexCount_);
-        immediateBuffer_ = 0;
-    }
-}
-
 void Graphics::SetForceSM2(bool enable)
 void Graphics::SetForceSM2(bool enable)
 {
 {
     // Note: this only has effect before calling SetMode() for the first time
     // Note: this only has effect before calling SetMode() for the first time
@@ -1848,17 +1699,6 @@ bool Graphics::IsInitialized() const
     return impl_->window_ != 0 && impl_->GetDevice() != 0;
     return impl_->window_ != 0 && impl_->GetDevice() != 0;
 }
 }
 
 
-unsigned char* Graphics::GetImmediateDataPtr() const
-{
-    if (!immediateBuffer_)
-    {
-        LOGERROR("Immediate draw operation not started");
-        return 0;
-    }
-    // Pointer was pre-decremented in BeginImmediate(). Undo that now
-    return immediateDataPtr_ + immediateBuffer_->GetVertexSize();
-}
-
 unsigned Graphics::GetWindowHandle() const
 unsigned Graphics::GetWindowHandle() const
 {
 {
     return (unsigned)impl_->window_;
     return (unsigned)impl_->window_;
@@ -2253,8 +2093,6 @@ void Graphics::OnDeviceReset()
     // Get default surfaces
     // Get default surfaces
     impl_->device_->GetRenderTarget(0, &impl_->defaultColorSurface_);
     impl_->device_->GetRenderTarget(0, &impl_->defaultColorSurface_);
     impl_->device_->GetDepthStencilSurface(&impl_->defaultDepthStencilSurface_);
     impl_->device_->GetDepthStencilSurface(&impl_->defaultDepthStencilSurface_);
-    
-    immediateBuffer_ = 0;
 }
 }
 
 
 void Graphics::ResetCachedState()
 void Graphics::ResetCachedState()

+ 0 - 33
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -48,7 +48,6 @@ class VertexDeclaration;
 
 
 struct ShaderParameter;
 struct ShaderParameter;
 
 
-static const int IMMEDIATE_BUFFER_DEFAULT_SIZE = 1024;
 static const unsigned NUM_QUERIES = 2;
 static const unsigned NUM_QUERIES = 2;
 
 
 /// %Graphics subsystem. Manages the application window, rendering state and GPU resources.
 /// %Graphics subsystem. Manages the application window, rendering state and GPU resources.
@@ -173,20 +172,6 @@ public:
     void SetStreamFrequency(unsigned index, unsigned frequency);
     void SetStreamFrequency(unsigned index, unsigned frequency);
     /// Reset stream frequencies.
     /// Reset stream frequencies.
     void ResetStreamFrequencies();
     void ResetStreamFrequencies();
-    /// Begin immediate rendering command.
-    bool BeginImmediate(PrimitiveType type, unsigned vertexCount, unsigned elementMask);
-    /// Define immediate vertex.
-    bool DefineVertex(const Vector3& vertex);
-    /// Define immediate normal.
-    bool DefineNormal(const Vector3& normal);
-    /// Define immediate texture coordinate.
-    bool DefineTexCoord(const Vector2& texCoord);
-    /// Define immediate color.
-    bool DefineColor(const Color& color);
-    /// Define immediate color.
-    bool DefineColor(unsigned color);
-    /// End immediate rendering command and render.
-    void EndImmediate();
     /// %Set force Shader Model 2 flag. Needs to be set before setting initial screen mode to have effect.
     /// %Set force Shader Model 2 flag. Needs to be set before setting initial screen mode to have effect.
     void SetForceSM2(bool enable);
     void SetForceSM2(bool enable);
     /// %Set force fallback shaders flag. Needs to be set before setting initial screen mode to have effect.
     /// %Set force fallback shaders flag. Needs to be set before setting initial screen mode to have effect.
@@ -214,8 +199,6 @@ public:
     bool GetFlushGPU() const { return flushGPU_; }
     bool GetFlushGPU() const { return flushGPU_; }
     /// Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching.
     /// Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching.
     bool IsDeviceLost() const { return deviceLost_; }
     bool IsDeviceLost() const { return deviceLost_; }
-    /// Return immediate rendering data pointer.
-    unsigned char* GetImmediateDataPtr() const;
     /// Return window handle.
     /// Return window handle.
     unsigned GetWindowHandle() const;
     unsigned GetWindowHandle() const;
     /// Return number of primitives drawn this frame.
     /// Return number of primitives drawn this frame.
@@ -401,26 +384,10 @@ private:
     unsigned numPrimitives_;
     unsigned numPrimitives_;
     /// Number of batches this frame.
     /// Number of batches this frame.
     unsigned numBatches_;
     unsigned numBatches_;
-    /// Immediate rendering primitive type.
-    PrimitiveType immediateType_;
-    /// Immediate vertex buffer start position.
-    unsigned immediateStartPos_;
-    /// Immediate rendering total number of vertices.
-    unsigned immediateVertexCount_;
-    /// Immediate rendering current vertex number.
-    unsigned immediateCurrentVertex_;
-    /// Immediate rendering vertex buffer in use.
-    VertexBuffer* immediateBuffer_;
-    /// Immediate rendering data pointer.
-    unsigned char* immediateDataPtr_;
     /// GPU objects.
     /// GPU objects.
     Vector<GPUObject*> gpuObjects_;
     Vector<GPUObject*> gpuObjects_;
     /// Vertex declarations.
     /// Vertex declarations.
     HashMap<unsigned long long, SharedPtr<VertexDeclaration> > vertexDeclarations_;
     HashMap<unsigned long long, SharedPtr<VertexDeclaration> > vertexDeclarations_;
-    /// Immediate rendering vertex buffers by vertex declaration.
-    HashMap<unsigned, SharedPtr<VertexBuffer> > immediateVertexBuffers_;
-    /// Immediate rendering vertex buffer start positions.
-    HashMap<unsigned, unsigned> immediateVertexBufferPos_;
     /// Shadow map dummy color texture format.
     /// Shadow map dummy color texture format.
     unsigned dummyColorFormat_;
     unsigned dummyColorFormat_;
     /// Shadow map depth texture format.
     /// Shadow map depth texture format.

+ 0 - 1
Engine/Graphics/GraphicsDefs.h

@@ -276,5 +276,4 @@ static const float ANIMATION_LOD_BASESCALE = 2.5f;
 static const int MAX_RENDERTARGETS = 4;
 static const int MAX_RENDERTARGETS = 4;
 static const int MAX_VERTEX_STREAMS = 4;
 static const int MAX_VERTEX_STREAMS = 4;
 static const int MAX_SKIN_MATRICES = 64;
 static const int MAX_SKIN_MATRICES = 64;
-static const int MAX_IMMEDIATE_ELEMENTS = 4;
 static const int MAX_CONSTANT_REGISTERS = 256;
 static const int MAX_CONSTANT_REGISTERS = 256;

+ 0 - 162
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -130,7 +130,6 @@ Graphics::Graphics(Context* context_) :
     flushGPU_(true),
     flushGPU_(true),
     numPrimitives_(0),
     numPrimitives_(0),
     numBatches_(0),
     numBatches_(0),
-    immediateVertexCount_(0),
     defaultTextureFilterMode_(FILTER_BILINEAR),
     defaultTextureFilterMode_(FILTER_BILINEAR),
     shadowMapFormat_(GL_DEPTH_COMPONENT16),
     shadowMapFormat_(GL_DEPTH_COMPONENT16),
     hiresShadowMapFormat_(GL_DEPTH_COMPONENT24),
     hiresShadowMapFormat_(GL_DEPTH_COMPONENT24),
@@ -1587,156 +1586,6 @@ void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, Ste
     }
     }
 }
 }
 
 
-bool Graphics::BeginImmediate(PrimitiveType type, unsigned vertexCount, unsigned elementMask)
-{
-    if (immediateVertexCount_)
-    {
-        LOGERROR("New immediate draw operation started before ending the last one");
-        return false;
-    }
-    if (!(elementMask & MASK_POSITION))
-    {
-        LOGERROR("Immediate draw operation must contain vertex positions");
-        return false;
-    }
-    if (!vertexCount)
-        return true;
-    
-    // Resize the buffer if it is too small
-    unsigned vertexSize = VertexBuffer::GetVertexSize(elementMask);
-    if (immediateVertexData_.Size() < vertexCount * vertexSize)
-        immediateVertexData_.Resize(vertexCount * vertexSize);
-    
-    // Note: the data pointer gets pre-decremented here, because the first call to DefineVertex() will increment it
-    immediateDataPtr_ = &immediateVertexData_[0] - vertexSize;
-    immediateType_= type;
-    immediateVertexCount_ = vertexCount;
-    immediateVertexSize_ = vertexSize;
-    immediateElementMask_ = elementMask;
-    immediateCurrentVertex_ = 0;
-    
-    unsigned dataOffset = 0;
-    for (unsigned i = ELEMENT_POSITION; i <= ELEMENT_TEXCOORD1; ++i)
-    {
-        immediateElementOffsets_[i] = dataOffset;
-        if (elementMask & (1 << i))
-            dataOffset += VertexBuffer::elementSize[i];
-    }
-    
-    return true;
-}
-
-bool Graphics::DefineVertex(const Vector3& vertex)
-{
-    if (!immediateVertexCount_ || immediateCurrentVertex_ >= immediateVertexCount_)
-        return false;
-    
-    immediateDataPtr_ += immediateVertexSize_;
-    ++immediateCurrentVertex_;
-    
-    float* dest = (float*)(immediateDataPtr_ + immediateElementOffsets_[ELEMENT_POSITION]);
-    const float* src = vertex.GetData();
-    dest[0] = src[0];
-    dest[1] = src[1];
-    dest[2] = src[2];
-    
-    return true;
-}
-
-bool Graphics::DefineNormal(const Vector3& normal)
-{
-    if (!immediateVertexCount_ || !(immediateElementMask_ & MASK_NORMAL) || !immediateCurrentVertex_)
-        return false;
-    
-    float* dest = (float*)(immediateDataPtr_ + immediateElementOffsets_[ELEMENT_NORMAL]);
-    const float* src = normal.GetData();
-    dest[0] = src[0];
-    dest[1] = src[1];
-    dest[2] = src[2];
-    
-    return true;
-}
-
-bool Graphics::DefineTexCoord(const Vector2& texCoord)
-{
-    if (!immediateVertexCount_ || !(immediateElementMask_ & MASK_TEXCOORD1) || !immediateCurrentVertex_)
-        return false;
-    
-    float* dest = (float*)(immediateDataPtr_ + immediateElementOffsets_[ELEMENT_TEXCOORD1]);
-    const float* src = texCoord.GetData();
-    dest[0] = src[0];
-    dest[1] = src[1];
-    
-    return true;
-}
-
-bool Graphics::DefineColor(const Color& color)
-{
-    if (!immediateVertexCount_ || !(immediateElementMask_ & MASK_COLOR) || !immediateCurrentVertex_)
-        return false;
-    
-    unsigned* dest = (unsigned*)(immediateDataPtr_ + immediateElementOffsets_[ELEMENT_COLOR]);
-    *dest = color.ToUInt();
-    
-    return true;
-}
-
-bool Graphics::DefineColor(unsigned color)
-{
-    if (!immediateVertexCount_ || !(immediateElementMask_ & MASK_COLOR) || !immediateCurrentVertex_)
-        return false;
-    
-    unsigned* dest = (unsigned*)(immediateDataPtr_ + immediateElementOffsets_[ELEMENT_COLOR]);
-    *dest = color;
-    
-    return true;
-}
-
-void Graphics::EndImmediate()
-{
-    if (immediateVertexCount_)
-    {
-        SetVertexBuffer(0);
-        SetIndexBuffer(0);
-        
-        if (shaderProgram_)
-        {
-            const int* attributeLocations = shaderProgram_->GetAttributeLocations();
-            unsigned vertexSize = VertexBuffer::GetVertexSize(immediateElementMask_);
-            
-            glBindBuffer(GL_ARRAY_BUFFER, 0);
-            
-            for (unsigned i = ELEMENT_POSITION; i <= ELEMENT_TEXCOORD1; ++i)
-            {
-                unsigned attributeIndex = attributeLocations[i];
-                unsigned attributeBit = 1 << attributeIndex;
-                unsigned elementBit = 1 << i;
-                
-                if (immediateElementMask_ & elementBit)
-                {
-                    if ((impl_->enabledAttributes_ & attributeBit) == 0)
-                    {
-                        glEnableVertexAttribArray(attributeIndex);
-                        impl_->enabledAttributes_ |= attributeBit;
-                    }
-                    
-                    glVertexAttribPointer(attributeIndex, VertexBuffer::elementComponents[i], VertexBuffer::elementType[i],
-                        VertexBuffer::elementNormalize[i], vertexSize, (const GLvoid*)&immediateVertexData_[immediateElementOffsets_[i]]);
-                }
-                else if (impl_->enabledAttributes_ & attributeBit)
-                {
-                    glDisableVertexAttribArray(attributeIndex);
-                    impl_->enabledAttributes_ &= ~attributeBit;
-                }
-            }
-            
-            Draw(immediateType_, 0, immediateVertexCount_);
-        }
-        
-        immediateVertexCount_ = 0;
-    }
-}
-
 void Graphics::SetForceSM2(bool enable)
 void Graphics::SetForceSM2(bool enable)
 {
 {
 }
 }
@@ -1750,17 +1599,6 @@ bool Graphics::IsInitialized() const
     return impl_->window_ != 0;
     return impl_->window_ != 0;
 }
 }
 
 
-unsigned char* Graphics::GetImmediateDataPtr() const
-{
-    if (!immediateVertexCount_)
-    {
-        LOGERROR("Immediate draw operation not started");
-        return 0;
-    }
-    
-    return const_cast<unsigned char*>(&immediateVertexData_[0]);
-}
-
 void* Graphics::GetWindowHandle() const
 void* Graphics::GetWindowHandle() const
 {
 {
     return impl_->window_;
     return impl_->window_;

+ 0 - 32
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -176,20 +176,6 @@ public:
     void SetStreamFrequency(unsigned index, unsigned frequency);
     void SetStreamFrequency(unsigned index, unsigned frequency);
     /// Reset stream frequencies. No-op on OpenGL.
     /// 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.
-    bool DefineVertex(const Vector3& vertex);
-    /// Define immediate normal.
-    bool DefineNormal(const Vector3& normal);
-    /// Define immediate texture coordinate.
-    bool DefineTexCoord(const Vector2& texCoord);
-    /// Define immediate color.
-    bool DefineColor(const Color& color);
-    /// Define immediate color.
-    bool DefineColor(unsigned color);
-    /// End immediate rendering command and render.
-    void EndImmediate();
     /// Set force Shader Model 2 flag. No effect on OpenGL.
     /// Set force Shader Model 2 flag. No effect on OpenGL.
     void SetForceSM2(bool enable);
     void SetForceSM2(bool enable);
     /// %Set force fallback shaders flag. No effect on OpenGL.
     /// %Set force fallback shaders flag. No effect on OpenGL.
@@ -217,8 +203,6 @@ public:
     bool GetFlushGPU() const { return flushGPU_; }
     bool GetFlushGPU() const { return flushGPU_; }
     /// Return whether device is lost, and can not yet render. Always false on OpenGL.
     /// Return whether device is lost, and can not yet render. Always false on OpenGL.
     bool IsDeviceLost() const { return false; }
     bool IsDeviceLost() const { return false; }
-    /// Return immediate rendering data pointer.
-    unsigned char* GetImmediateDataPtr() const;
     /// Return window handle.
     /// Return window handle.
     void* GetWindowHandle() const;
     void* GetWindowHandle() const;
     /// Return number of primitives drawn this frame.
     /// Return number of primitives drawn this frame.
@@ -368,22 +352,6 @@ private:
     unsigned numPrimitives_;
     unsigned numPrimitives_;
     /// Number of batches this frame.
     /// Number of batches this frame.
     unsigned numBatches_;
     unsigned numBatches_;
-    /// Immediate rendering primitive type.
-    PrimitiveType immediateType_;
-    /// Immediate rendering total number of vertices.
-    unsigned immediateVertexCount_;
-    /// Immediate rendering vertex size.
-    unsigned immediateVertexSize_;
-    /// Immediate rendering vertex element mask.
-    unsigned immediateElementMask_;
-    /// Immediate rendering current vertex number.
-    unsigned immediateCurrentVertex_;
-    /// Immediate rendering data pointer.
-    unsigned char* immediateDataPtr_;
-    /// Immediate rendering data buffer.
-    PODVector<unsigned char> immediateVertexData_;
-    /// Immediate rendering element offsets.
-    unsigned immediateElementOffsets_[MAX_IMMEDIATE_ELEMENTS];
     /// GPU objects.
     /// GPU objects.
     Vector<GPUObject*> gpuObjects_;
     Vector<GPUObject*> gpuObjects_;
     /// Shadow map depth texture format.
     /// Shadow map depth texture format.

+ 23 - 32
Engine/UI/UI.cpp

@@ -218,40 +218,16 @@ void UI::Update(float timeStep)
 
 
 void UI::RenderUpdate()
 void UI::RenderUpdate()
 {
 {
-    if (!rootElement_ || !graphics_ || graphics_->IsDeviceLost())
+    if (!rootElement_ || !graphics_)
         return;
         return;
     
     
-    {
-        PROFILE(GetUIBatches);
-        
-        // Get batches & quads from the UI elements
-        batches_.Clear();
-        quads_.Clear();
-        const IntVector2& rootSize = rootElement_->GetSize();
-        GetBatches(rootElement_, IntRect(0, 0, rootSize.x_, rootSize.y_));
-    }
+    PROFILE(GetUIBatches);
     
     
-    {
-        PROFILE(UpdateUIGeometry);
-        
-        // Update quad geometry into the vertex buffer
-        unsigned numVertices = quads_.Size() * 6;
-        if (numVertices)
-        {
-            if (vertexBuffer_->GetVertexCount() < numVertices)
-                vertexBuffer_->SetSize(numVertices, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1, true);
-        
-            unsigned vertexSize = vertexBuffer_->GetVertexSize();
-            unsigned char* lockedData = (unsigned char*)vertexBuffer_->Lock(0, numVertices, LOCK_DISCARD);
-        
-            if (lockedData)
-            {
-                for (unsigned i = 0; i < batches_.Size(); ++i)
-                    batches_[i].UpdateGeometry(graphics_, lockedData + 6 * batches_[i].quadStart_ * vertexSize);
-                vertexBuffer_->Unlock();
-            }
-        }
-    }
+    // Get batches & quads from the UI elements
+    batches_.Clear();
+    quads_.Clear();
+    const IntVector2& rootSize = rootElement_->GetSize();
+    GetBatches(rootElement_, IntRect(0, 0, rootSize.x_, rootSize.y_));
     
     
     // If no drag, reset cursor shape for next frame
     // If no drag, reset cursor shape for next frame
     if (cursor_ && !dragElement_)
     if (cursor_ && !dragElement_)
@@ -262,9 +238,24 @@ void UI::Render()
 {
 {
     PROFILE(RenderUI);
     PROFILE(RenderUI);
     
     
-    if (!graphics_)
+    if (!graphics_ || graphics_->IsDeviceLost() || !quads_.Size())
         return;
         return;
     
     
+    // Update quad geometry into the vertex buffer
+    unsigned numVertices = quads_.Size() * 6;
+    if (vertexBuffer_->GetVertexCount() < numVertices)
+        vertexBuffer_->SetSize(numVertices, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1, true);
+    
+    unsigned vertexSize = vertexBuffer_->GetVertexSize();
+    void* lockedData = vertexBuffer_->Lock(0, numVertices, LOCK_DISCARD);
+    if (!lockedData)
+        return;
+    
+    for (unsigned i = 0; i < batches_.Size(); ++i)
+        batches_[i].UpdateGeometry(graphics_, ((unsigned char*)lockedData) + batches_[i].quadStart_ * vertexSize * 6);
+    
+    vertexBuffer_->Unlock();
+    
     Vector2 scale(2.0f, -2.0f);
     Vector2 scale(2.0f, -2.0f);
     Vector2 offset(-1.0f, 1.0f);
     Vector2 offset(-1.0f, 1.0f);