Browse Source

Adding support for BGRA texture format in UI (for WebView)

JoshEngebretson 10 years ago
parent
commit
6ce6aeaf58

+ 5 - 1
Resources/CoreData/Shaders/HLSL/Basic.hlsl

@@ -73,7 +73,11 @@ void PS(
             if (diffInput.a < 0.5)
             if (diffInput.a < 0.5)
                 discard;
                 discard;
         #endif
         #endif
-        oColor = diffColor * diffInput;
+        #ifdef DIFFMAPBGRA
+          oColor = diffColor * float4(diffInput.b, diffInput.g, diffInput.r, diffInput.a);
+        #else
+          oColor = diffColor * diffInput;
+        #endif
     #endif
     #endif
     #ifdef ALPHAMAP
     #ifdef ALPHAMAP
         float alphaInput = Sample2D(DiffMap, iTexCoord).a;
         float alphaInput = Sample2D(DiffMap, iTexCoord).a;

+ 8 - 3
Source/Atomic/UI/UI.cpp

@@ -343,6 +343,8 @@ void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigne
     ShaderVariation* diffMaskTexturePS = graphics_->GetShader(PS, "Basic", "DIFFMAP ALPHAMASK VERTEXCOLOR");
     ShaderVariation* diffMaskTexturePS = graphics_->GetShader(PS, "Basic", "DIFFMAP ALPHAMASK VERTEXCOLOR");
     ShaderVariation* alphaTexturePS = graphics_->GetShader(PS, "Basic", "ALPHAMAP VERTEXCOLOR");
     ShaderVariation* alphaTexturePS = graphics_->GetShader(PS, "Basic", "ALPHAMAP VERTEXCOLOR");
 
 
+    ShaderVariation* diffmapBGRAPS = graphics_->GetShader(PS, "Basic", "DIFFMAP VERTEXCOLOR DIFFMAPBGRA");
+
     unsigned alphaFormat = Graphics::GetAlphaFormat();
     unsigned alphaFormat = Graphics::GetAlphaFormat();
 
 
     for (unsigned i = batchStart; i < batchEnd; ++i)
     for (unsigned i = batchStart; i < batchEnd; ++i)
@@ -364,7 +366,9 @@ void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigne
             // If texture contains only an alpha channel, use alpha shader (for fonts)
             // If texture contains only an alpha channel, use alpha shader (for fonts)
             vs = diffTextureVS;
             vs = diffTextureVS;
 
 
-            if (batch.texture_->GetFormat() == alphaFormat)
+            if (batch.useBGRA_)
+                ps = diffmapBGRAPS;
+            else if (batch.texture_->GetFormat() == alphaFormat)
                 ps = alphaTexturePS;
                 ps = alphaTexturePS;
             else if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA)
             else if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA)
                 ps = diffMaskTexturePS;
                 ps = diffMaskTexturePS;
@@ -444,9 +448,10 @@ void UI::GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, c
     tb::g_renderer->EndPaint();
     tb::g_renderer->EndPaint();
 }
 }
 
 
-void UI::SubmitBatchVertexData(Texture* texture, const PODVector<float>& vertexData)
+void UI::SubmitBatchVertexData(Texture* texture, const PODVector<float>& vertexData, BlendMode blendMode, bool useBGRA)
 {
 {
-    UIBatch b(BLEND_ALPHA , renderer_->currentScissor_, texture, &vertexData_);
+    UIBatch b(blendMode , renderer_->currentScissor_, texture, &vertexData_);
+    b.useBGRA_ = useBGRA;
 
 
     unsigned begin = b.vertexData_->Size();
     unsigned begin = b.vertexData_->Size();
     b.vertexData_->Resize(begin + vertexData.Size());
     b.vertexData_->Resize(begin + vertexData.Size());

+ 1 - 1
Source/Atomic/UI/UI.h

@@ -59,7 +59,7 @@ public:
 
 
     void Render(bool resetRenderTargets = true);
     void Render(bool resetRenderTargets = true);
     void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
     void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
-    void SubmitBatchVertexData(Texture* texture, const PODVector<float>& vertexData);
+    void SubmitBatchVertexData(Texture* texture, const PODVector<float>& vertexData, BlendMode blendMode = BLEND_ALPHA, bool useBGRA = false);
 
 
     void Initialize(const String& languageFile);
     void Initialize(const String& languageFile);
 
 

+ 3 - 1
Source/Atomic/UI/UIBatch.cpp

@@ -74,6 +74,7 @@ void UIBatch::SetDefaultColor()
 {
 {
     color_ = 0xffffffff;
     color_ = 0xffffffff;
     useGradient_ = false;
     useGradient_ = false;
+    useBGRA_ = false;
 }
 }
 
 
 void UIBatch::AddQuad(int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight)
 void UIBatch::AddQuad(int x, int y, int width, int height, int texOffsetX, int texOffsetY, int texWidth, int texHeight)
@@ -208,7 +209,8 @@ bool UIBatch::Merge(const UIBatch& batch)
         batch.scissor_ != scissor_ ||
         batch.scissor_ != scissor_ ||
         batch.texture_ != texture_ ||
         batch.texture_ != texture_ ||
         batch.vertexData_ != vertexData_ ||
         batch.vertexData_ != vertexData_ ||
-        batch.vertexStart_ != vertexEnd_)
+        batch.vertexStart_ != vertexEnd_ ||
+        batch.useBGRA_ != useBGRA_    )
         return false;
         return false;
 
 
     vertexEnd_ = batch.vertexEnd_;
     vertexEnd_ = batch.vertexEnd_;

+ 5 - 0
Source/Atomic/UI/UIBatch.h

@@ -80,6 +80,11 @@ public:
     unsigned vertexEnd_;
     unsigned vertexEnd_;
     /// Gradient flag.
     /// Gradient flag.
     bool useGradient_;
     bool useGradient_;
+
+    // ATOMIC BEGIN
+    /// Whether texture is in BGRA format
+    bool useBGRA_;
+    // ATOMIC END
 };
 };
 
 
 }
 }

+ 5 - 1
Source/AtomicWebView/UIWebView.cpp

@@ -113,7 +113,11 @@ public:
         data[30] = rect.x;
         data[30] = rect.x;
         data[31] = rect.y + rect.h;
         data[31] = rect.y + rect.h;
 
 
-        ui->SubmitBatchVertexData(webView_->GetWebTexture2D()->GetTexture2D(), vertexData_);
+        bool useBGRA = false;
+#ifdef ATOMIC_PLATFORM_WINDOWS
+        useBGRA = true;
+#endif
+        ui->SubmitBatchVertexData(webView_->GetWebTexture2D()->GetTexture2D(), vertexData_, BLEND_ALPHA, useBGRA );
 
 
     }
     }
 
 

+ 0 - 5
Source/AtomicWebView/WebTexture2D.cpp

@@ -209,11 +209,6 @@ WebTexture2D::WebTexture2D(Context* context) : WebRenderHandler(context)
     texture_ = new Texture2D(context_);
     texture_ = new Texture2D(context_);
     texture_->SetNumLevels(1);
     texture_->SetNumLevels(1);
     texture_->SetFilterMode(FILTER_BILINEAR);
     texture_->SetFilterMode(FILTER_BILINEAR);
-
-    ResourceCache* cache = GetSubsystem<ResourceCache>();
-    material_ = new Material(context_);
-    material_->SetTechnique(0, cache->GetResource<Technique>("Techniques/DiffUnlit.xml"));
-    material_->SetTexture(TU_DIFFUSE, texture_);
 }
 }
 
 
 WebTexture2D::~WebTexture2D()
 WebTexture2D::~WebTexture2D()

+ 0 - 2
Source/AtomicWebView/WebTexture2D.h

@@ -32,12 +32,10 @@ public:
     CefRenderHandler* GetCEFRenderHandler();
     CefRenderHandler* GetCEFRenderHandler();
 
 
     Texture2D* GetTexture2D() const { return texture_; }
     Texture2D* GetTexture2D() const { return texture_; }
-    Material* GetMaterial() const { return material_; }
 
 
 private:
 private:
 
 
     SharedPtr<Texture2D> texture_;
     SharedPtr<Texture2D> texture_;
-    SharedPtr<Material> material_;
 
 
     WebTexture2DPrivate* d_;
     WebTexture2DPrivate* d_;