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

Added default internal buffer alloc for PixelData

Marko Pintera 12 лет назад
Родитель
Сommit
71002238ae

+ 10 - 0
CamelotCore/Include/CmGpuResourceData.h

@@ -20,6 +20,13 @@ namespace CamelotFramework
 
 		UINT8* getData() const;
 
+		/**
+		 * @brief	Allocates an internal buffer of a certain size. If there is another
+		 * 			buffer already allocated, it will be freed and new one will be allocated.
+		 * 			Buffer size is determine based on parameters used for initializing the class.
+		 */
+		void allocateInternalBuffer();
+
 		/**
 		 * @brief	Allocates an internal buffer of a certain size. If there is another
 		 * 			buffer already allocated, it will be freed and new one will be allocated.
@@ -53,6 +60,9 @@ namespace CamelotFramework
 		 */
 		void unlock() const;
 
+	protected:
+		virtual UINT32 getInternalBufferSize() = 0;
+
 	private:
 		UINT8* mData;
 		bool mOwnsData;

+ 2 - 0
CamelotCore/Include/CmPixelData.h

@@ -250,6 +250,8 @@ namespace CamelotFramework
             mSlicePitch = getWidth()*getHeight();
         }
 
+		UINT32 getInternalBufferSize();
+
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/

+ 5 - 0
CamelotCore/Source/CmGpuResourceData.cpp

@@ -36,6 +36,11 @@ namespace CamelotFramework
 		return mData;
 	}
 
+	void GpuResourceData::allocateInternalBuffer()
+	{
+		allocateInternalBuffer(getInternalBufferSize());
+	}
+
 	void GpuResourceData::allocateInternalBuffer(UINT32 size)
 	{
 #if !CM_FORCE_SINGLETHREADED_RENDERING

+ 5 - 0
CamelotCore/Source/CmPixelData.cpp

@@ -13,6 +13,11 @@ namespace CamelotFramework
 		mExtents = copy.mExtents;
 	}
 
+	UINT32 PixelData::getInternalBufferSize()
+	{
+		return PixelUtil::getMemorySize(getWidth(), getHeight(), getDepth(), getFormat());
+	}
+
 	/************************************************************************/
 	/* 								SERIALIZATION                      		*/
 	/************************************************************************/

+ 2 - 2
CamelotCore/Source/CmPixelUtil.cpp

@@ -1369,7 +1369,7 @@ namespace CamelotFramework {
 			{
 				// Allocate temporary buffer of destination size in source format 
 				temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.getFormat());
-				temp.allocateInternalBuffer(temp.getConsecutiveSize());
+				temp.allocateInternalBuffer();
 			}
 			// super-optimized: no conversion
 			switch (PixelUtil::getNumElemBytes(src.getFormat())) 
@@ -1413,7 +1413,7 @@ namespace CamelotFramework {
 				{
 					// Allocate temp buffer of destination size in source format 
 					temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.getFormat());
-					temp.allocateInternalBuffer(temp.getConsecutiveSize());
+					temp.allocateInternalBuffer();
 				}
 				// super-optimized: byte-oriented math, no conversion
 				switch (PixelUtil::getNumElemBytes(src.getFormat())) 

+ 1 - 1
CamelotCore/Source/CmTexture.cpp

@@ -158,7 +158,7 @@ namespace CamelotFramework {
 		PixelDataPtr dst(CM_NEW(PixelData, PoolAlloc) PixelData(width, height, depth, getFormat()),
 			&MemAllocDeleter<PixelData, PoolAlloc>::deleter);
 
-		dst->allocateInternalBuffer(totalSize);
+		dst->allocateInternalBuffer();
 
 		return dst;
 	}

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -519,7 +519,7 @@ namespace CamelotFramework
 		mLockedSubresourceIdx = D3D11CalcSubresource(mipLevel, face, getNumMipmaps()+1);
 
 		mStaticBuffer = CM_NEW(PixelData, PoolAlloc) PixelData(lock.getWidth(), lock.getHeight(), lock.getDepth(), lock.getFormat());
-		mStaticBuffer->allocateInternalBuffer(sizeOfImage);
+		mStaticBuffer->allocateInternalBuffer();
 
 		return mStaticBuffer->getData();
 	}

+ 3 - 3
CamelotD3D9Renderer/Source/CmD3D9PixelBuffer.cpp

@@ -110,7 +110,7 @@ namespace CamelotFramework
 				{
 					Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth);
 					PixelData dstBox(fullBufferBox, mFormat);
-					dstBox.allocateInternalBuffer(getSizeInBytes());
+					dstBox.allocateInternalBuffer();
 
 					blitToMemory(fullBufferBox, dstBox, it->second, it->first);
 					blitFromMemory(dstBox, fullBufferBox, bufferResources);
@@ -169,7 +169,7 @@ namespace CamelotFramework
 				{
 					Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth);
 					PixelData dstBox(fullBufferBox, mFormat);
-					dstBox.allocateInternalBuffer(getSizeInBytes());
+					dstBox.allocateInternalBuffer();
 
 					blitToMemory(fullBufferBox, dstBox, it->second, it->first);
 					blitFromMemory(dstBox, fullBufferBox, bufferResources);
@@ -604,7 +604,7 @@ namespace CamelotFramework
 		if (D3D9Mappings::_getPF(src.getFormat()) == D3DFMT_UNKNOWN)
 		{
 			converted = PixelData(src.getWidth(), src.getHeight(), src.getDepth(), mFormat);
-			converted.allocateInternalBuffer(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat));
+			converted.allocateInternalBuffer();
 			PixelUtil::bulkPixelConversion(src, converted);
 		}
 

+ 1 - 1
CamelotFontImporter/Source/CmFontImporter.cpp

@@ -135,7 +135,7 @@ namespace CamelotFramework
 
 				PixelData pixelData(pageIter->width, pageIter->height, 1, PF_R8G8);
 
-				pixelData.allocateInternalBuffer(bufferSize);
+				pixelData.allocateInternalBuffer();
 				UINT8* pixelBuffer = pixelData.getData();
 				memset(pixelBuffer, 0, bufferSize);
 

+ 2 - 2
CamelotGLRenderer/Source/CmGLPixelBuffer.cpp

@@ -59,7 +59,7 @@ namespace CamelotFramework
 			// Already allocated
 			return;
 
-		mBuffer.allocateInternalBuffer(mSizeInBytes);
+		mBuffer.allocateInternalBuffer();
 		// TODO: use PBO if we're HBU_DYNAMIC
 	}
 	//-----------------------------------------------------------------------------  
@@ -697,7 +697,7 @@ namespace CamelotFramework
 		{
 			/// Convert to buffer internal format
 			src = PixelData(src_orig.getWidth(), src_orig.getHeight(), src_orig.getDepth(), mFormat);
-			src.allocateInternalBuffer(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat));
+			src.allocateInternalBuffer();
 			PixelUtil::bulkPixelConversion(src_orig, src);
 		}
 		else

+ 4 - 1
TODO.txt

@@ -10,7 +10,10 @@ When I'm canceling command queue commands I might be canceling important user co
 
 <<<<<<<Resource update/read>>>>>>>>
 RenderSystem does syncing external to CommandQueue
- - That probably won't be needed once I have syncable CommandQueue
+ - That probably won't be needed once I have syncable CommandQueue so it's done twice for no reason
+ - I can also probably replace render system command queue with a deferred render context? Since I already
+   need to create a deferred synced context anyway, no point in having a command queue that does exactly the same thing.
+   - (I forgot to submitToGpu() on the deferred context, but I guess it might not be needed if I handle it properly?)
 
 MeshData needs to be ported to GpuResourceData format
  - I don't want to give up the current MeshData interface as it's easy to use. Anything lower level and I might just be using vertex/index buffers directly