Browse Source

reduce unnessesary texture updates to increase performance

Kolja Strohm 1 year ago
parent
commit
b6fcea2590
3 changed files with 8 additions and 2 deletions
  1. 2 1
      DX12Textur.cpp
  2. 5 1
      Textur.cpp
  3. 1 0
      Textur.h

+ 2 - 1
DX12Textur.cpp

@@ -82,8 +82,9 @@ bool DX12Textur::updateTextur()
             (void**)&intermediate);
         shaderResource = 0;
     }
-    if (bild)
+    if (bild && (changed || bild->getRend()))
     {
+        changed = 0;
         if (shaderResource)
         {
             D3D12_RESOURCE_BARRIER barrier;

+ 5 - 1
Textur.cpp

@@ -18,6 +18,7 @@ Textur::Textur()
     bild = 0;
     lastGr = Punkt(0, 0);
     id = -1;
+    changed = 0;
 }
 
 // Destruktor
@@ -30,6 +31,7 @@ Textur::~Textur()
 //  b: Der Zeiger auf das Bild
 void Textur::setBildZ(Bild* b)
 {
+    if (bild != b) changed = 1;
     if (bild) bild->release();
     bild = b;
 }
@@ -39,6 +41,7 @@ void Textur::setBildZ(Bild* b)
 void Textur::setBild(Bild* b)
 {
     if (!b) return;
+    if (bild != b) changed = 1;
     if (!bild || bild->getBreite() != b->getBreite()
         || bild->getHeight() != b->getHeight())
     {
@@ -124,8 +127,9 @@ bool DX11Textur::updateTextur()
         HRESULT r = device->CreateTexture2D(&bufferDesc, 0, &txt);
         if (r != S_OK) return 0;
     }
-    if (!renderTarget)
+    if (!renderTarget && (bild->getRend() || changed))
     {
+        changed = 0;
         D3D11_MAPPED_SUBRESOURCE buffer;
         context->Map(txt, 0, D3D11_MAP::D3D11_MAP_WRITE_DISCARD, 0, &buffer);
         int* bgBuff = bild->getBuffer();

+ 1 - 0
Textur.h

@@ -22,6 +22,7 @@ namespace Framework
     {
     protected:
         Bild* bild;
+        bool changed;
         Punkt lastGr;
         int id;