Просмотр исходного кода

Return the texture usage accurately for OpenGL textures.

Lasse Öörni 13 лет назад
Родитель
Сommit
cf36528fd4

+ 1 - 10
Engine/Graphics/OpenGL/OGLTexture.cpp

@@ -71,11 +71,11 @@ static const String filterModeNames[] =
 Texture::Texture(Context* context) :
     Resource(context),
     GPUObject(GetSubsystem<Graphics>()),
+    usage_(TEXTURE_STATIC),
     levels_(0),
     requestedLevels_(0),
     width_(0),
     height_(0),
-    dynamic_(false),
     shadowCompare_(false),
     parametersDirty_(true),
     filterMode_(FILTER_DEFAULT)
@@ -223,15 +223,6 @@ int Texture::GetLevelHeight(unsigned level) const
     return Max(height_ >> level, 1);
 }
 
-TextureUsage Texture::GetUsage() const
-{
-    /// \todo Check for rendertarget / depth-stencil mode
-    if (dynamic_)
-        return TEXTURE_DYNAMIC;
-    
-    return TEXTURE_STATIC;
-}
-
 unsigned Texture::GetDataSize(int width, int height) const
 {
     if (IsCompressed())

+ 3 - 3
Engine/Graphics/OpenGL/OGLTexture.h

@@ -91,7 +91,7 @@ public:
     /// Return mip level width, or 0 if level does not exist.
     int GetLevelHeight(unsigned level) const;
     /// Return texture usage type.
-    TextureUsage GetUsage() const;
+    TextureUsage GetUsage() const { return usage_; }
     /// Return data size in bytes for a rectangular region.
     unsigned GetDataSize(int width, int height) const;
     /// Return data size in bytes for a pixel or block row.
@@ -112,6 +112,8 @@ protected:
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     void CheckTextureBudget(ShortStringHash type);
     
+    /// Texture usage type.
+    TextureUsage usage_;
     /// OpenGL target.
     unsigned target_;
     /// Texture format.
@@ -124,8 +126,6 @@ protected:
     int width_;
     /// Texture height.
     int height_;
-    /// Dynamic flag.
-    bool dynamic_;
     /// Shadow compare mode, OpenGL only.
     bool shadowCompare_;
     /// Parameters dirty flag.

+ 6 - 7
Engine/Graphics/OpenGL/OGLTexture2D.cpp

@@ -146,26 +146,25 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
 {
     // Delete the old rendersurface if any
     renderSurface_.Reset();
-
+    
+    usage_ = usage;
+    
     if (usage >= TEXTURE_RENDERTARGET)
     {
         renderSurface_ = new RenderSurface(this, GL_TEXTURE_2D);
-        dynamic_ = true;
-
+        
         // Clamp mode addressing by default, nearest filtering, and mipmaps disabled
         addressMode_[COORD_U] = ADDRESS_CLAMP;
         addressMode_[COORD_V] = ADDRESS_CLAMP;
         filterMode_ = FILTER_NEAREST;
         requestedLevels_ = 1;
     }
-    else
-        dynamic_ = usage == TEXTURE_DYNAMIC;
-
+    
     if (usage == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(Texture2D, HandleRenderSurfaceUpdate));
     else
         UnsubscribeFromEvent(E_RENDERSURFACEUPDATE);
-
+    
     width_ = width;
     height_ = height;
     format_ = format;

+ 4 - 5
Engine/Graphics/OpenGL/OGLTextureCube.cpp

@@ -142,6 +142,8 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
         faceMemoryUse_[i] = 0;
     }
     
+    usage_ = usage;
+    
     if (usage == TEXTURE_RENDERTARGET)
     {
         for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
@@ -153,16 +155,13 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
         addressMode_[COORD_W] = ADDRESS_CLAMP;
         filterMode_ = FILTER_NEAREST;
         requestedLevels_ = 1;
-        dynamic_ = true;
     }
-    else
-         dynamic_ = usage == TEXTURE_DYNAMIC;
-
+    
     if (usage == TEXTURE_RENDERTARGET)
         SubscribeToEvent(E_RENDERSURFACEUPDATE, HANDLER(TextureCube, HandleRenderSurfaceUpdate));
     else
         UnsubscribeFromEvent(E_RENDERSURFACEUPDATE);
-
+    
     width_ = size;
     height_ = size;
     format_ = format;