Bläddra i källkod

Encapsulated PixelData::data

Marko Pintera 12 år sedan
förälder
incheckning
8c53fd844b

+ 0 - 6
CamelotCore/Include/CmRenderSystem.h

@@ -96,12 +96,6 @@ namespace CamelotFramework
 		 */
 		 */
 		virtual const String& getShadingLanguageName() const = 0;
 		virtual const String& getShadingLanguageName() const = 0;
 
 
-		/** Notifies the render system that a new window was created.  
-		* 
-		* @note Should only be called by internal methods.
-		*/
-		virtual void _notifyWindowCreated(RenderWindow& window);
-
 		/**
 		/**
 		 * @brief	Sets a sampler state for the specified texture unit.
 		 * @brief	Sets a sampler state for the specified texture unit.
 		 * @see		SamplerState
 		 * @see		SamplerState

+ 1 - 1
CamelotCore/Source/CmPixelBuffer.cpp

@@ -58,7 +58,7 @@ namespace CamelotFramework
         
         
         Box myBox(0, 0, 0, mWidth, mHeight, mDepth);
         Box myBox(0, 0, 0, mWidth, mHeight, mDepth);
         const PixelData &rv = lock(myBox, options);
         const PixelData &rv = lock(myBox, options);
-        return rv.data;
+        return rv.getData();
     }
     }
     
     
     //-----------------------------------------------------------------------------    
     //-----------------------------------------------------------------------------    

+ 0 - 6
CamelotCore/Source/CmRenderSystem.cpp

@@ -114,12 +114,6 @@ namespace CamelotFramework {
 		mActiveRenderTarget = nullptr;
 		mActiveRenderTarget = nullptr;
 	}
 	}
 
 
-    void RenderSystem::_notifyWindowCreated(RenderWindow& window)
-    {
-		THROW_IF_NOT_RENDER_THREAD;
-
-    }
-
 	const RenderSystemCapabilities* RenderSystem::getCapabilities(void) const 
 	const RenderSystemCapabilities* RenderSystem::getCapabilities(void) const 
 	{ 
 	{ 
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;

+ 3 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -522,7 +522,9 @@ namespace CamelotFramework
 		mDevice.getImmediateContext()->Map(pTempTexture2D, 0,D3D11_MAP_READ, 0, &mappedTex2D);
 		mDevice.getImmediateContext()->Map(pTempTexture2D, 0,D3D11_MAP_READ, 0, &mappedTex2D);
 
 
 		// copy the the texture to the dest
 		// copy the the texture to the dest
-		PixelUtil::bulkPixelConversion(PixelData(mWidth, mHeight, 1, PF_A8B8G8R8, mappedTex2D.pData), dst);
+		PixelData src(mWidth, mHeight, 1, PF_A8B8G8R8);
+		src.setExternalDataPtr((UINT8*)mappedTex2D.pData);
+		PixelUtil::bulkPixelConversion(src, dst);
 
 
 		// unmap the temp buffer
 		// unmap the temp buffer
 		mDevice.getImmediateContext()->Unmap(pTempTexture2D, 0);
 		mDevice.getImmediateContext()->Unmap(pTempTexture2D, 0);

+ 4 - 4
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -61,15 +61,15 @@ namespace CamelotFramework
 
 
 		if(flags == D3D11_MAP_READ || flags == D3D11_MAP_READ_WRITE)
 		if(flags == D3D11_MAP_READ || flags == D3D11_MAP_READ_WRITE)
 		{
 		{
-			lockedArea.data = _mapstagingbuffer(flags, face, mipLevel);
+			lockedArea.setExternalDataPtr((UINT8*)_mapstagingbuffer(flags, face, mipLevel));
 			mLockedForReading = true;
 			mLockedForReading = true;
 		}
 		}
 		else
 		else
 		{
 		{
 			if(mUsage == TU_DYNAMIC)
 			if(mUsage == TU_DYNAMIC)
-				lockedArea.data = _map(mTex, flags, face, mipLevel);
+				lockedArea.setExternalDataPtr((UINT8*)_map(mTex, flags, face, mipLevel));
 			else
 			else
-				lockedArea.data = _mapstaticbuffer(lockedArea, mipLevel, face);
+				lockedArea.setExternalDataPtr((UINT8*)_mapstaticbuffer(lockedArea, mipLevel, face));
 
 
 			mLockedForReading = false;
 			mLockedForReading = false;
 		}
 		}
@@ -530,7 +530,7 @@ namespace CamelotFramework
 
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
 		D3D11Device& device = rs->getPrimaryDevice();
-		device.getImmediateContext()->UpdateSubresource(mTex, mLockedSubresourceIdx, nullptr, mStaticBuffer->data, rowWidth, sliceWidth);
+		device.getImmediateContext()->UpdateSubresource(mTex, mLockedSubresourceIdx, nullptr, mStaticBuffer->getData(), rowWidth, sliceWidth);
 
 
 		if (device.hasError())
 		if (device.hasError())
 		{
 		{

+ 2 - 1
CamelotD3D9Renderer/Source/CmD3D9Device.cpp

@@ -1328,7 +1328,8 @@ namespace CamelotFramework
 			CM_EXCEPT(RenderingAPIException, "Unsupported format");
 			CM_EXCEPT(RenderingAPIException, "Unsupported format");
 		}
 		}
 
 
-		PixelData src(dst.getWidth(), dst.getHeight(), 1, format, lockedRect.pBits);
+		PixelData src(dst.getWidth(), dst.getHeight(), 1, format);
+		src.setExternalDataPtr((UINT8*)lockedRect.pBits);
 		src.rowPitch = lockedRect.Pitch / PixelUtil::getNumElemBytes(format);
 		src.rowPitch = lockedRect.Pitch / PixelUtil::getNumElemBytes(format);
 		src.slicePitch = desc.Height * src.rowPitch;
 		src.slicePitch = desc.Height * src.rowPitch;
 
 

+ 13 - 15
CamelotD3D9Renderer/Source/CmD3D9PixelBuffer.cpp

@@ -109,13 +109,13 @@ namespace CamelotFramework
 					dev->TestCooperativeLevel() == D3D_OK)
 					dev->TestCooperativeLevel() == D3D_OK)
 				{
 				{
 					Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth);
 					Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth);
-					PixelData dstBox(fullBufferBox, mFormat, (char*)CM_NEW_BYTES(getSizeInBytes(), ScratchAlloc));
+					PixelData dstBox(fullBufferBox, mFormat);
+					dstBox.allocData(getSizeInBytes());
 
 
 					blitToMemory(fullBufferBox, dstBox, it->second, it->first);
 					blitToMemory(fullBufferBox, dstBox, it->second, it->first);
 					blitFromMemory(dstBox, fullBufferBox, bufferResources);
 					blitFromMemory(dstBox, fullBufferBox, bufferResources);
 
 
-					if(dstBox.data != nullptr)
-						CM_DELETE_BYTES(dstBox.data, ScratchAlloc);
+					dstBox.freeData();
 
 
 					break;
 					break;
 				}
 				}
@@ -168,13 +168,13 @@ namespace CamelotFramework
 					dev->TestCooperativeLevel() == D3D_OK)
 					dev->TestCooperativeLevel() == D3D_OK)
 				{
 				{
 					Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth);
 					Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth);
-					PixelData dstBox(fullBufferBox, mFormat, (char*)CM_NEW_BYTES(getSizeInBytes(), ScratchAlloc));
+					PixelData dstBox(fullBufferBox, mFormat);
+					dstBox.allocData(getSizeInBytes());
 
 
 					blitToMemory(fullBufferBox, dstBox, it->second, it->first);
 					blitToMemory(fullBufferBox, dstBox, it->second, it->first);
 					blitFromMemory(dstBox, fullBufferBox, bufferResources);
 					blitFromMemory(dstBox, fullBufferBox, bufferResources);
 					
 					
-					if(dstBox.data != nullptr)
-						CM_DELETE_BYTES(dstBox.data, ScratchAlloc);
+					dstBox.freeData();
 
 
 					break;
 					break;
 				}
 				}
@@ -256,7 +256,7 @@ namespace CamelotFramework
 			CM_EXCEPT(InvalidParametersException, "Invalid pixel format");
 			CM_EXCEPT(InvalidParametersException, "Invalid pixel format");
 		}
 		}
 
 
-		rval.data = lrect.pBits;
+		rval.setExternalDataPtr((UINT8*)lrect.pBits);
 	}
 	}
 	void fromD3DLock(PixelData &rval, const D3DLOCKED_BOX &lbox)
 	void fromD3DLock(PixelData &rval, const D3DLOCKED_BOX &lbox)
 	{
 	{
@@ -277,7 +277,7 @@ namespace CamelotFramework
 		{
 		{
 			CM_EXCEPT(InvalidParametersException, "Invalid pixel format");
 			CM_EXCEPT(InvalidParametersException, "Invalid pixel format");
 		}
 		}
-		rval.data = lbox.pBits;
+		rval.setExternalDataPtr((UINT8*)lbox.pBits);
 	}
 	}
 	// Convert Ogre integer Box to D3D rectangle
 	// Convert Ogre integer Box to D3D rectangle
 	RECT toD3DRECT(const Box &lockBox)
 	RECT toD3DRECT(const Box &lockBox)
@@ -598,14 +598,13 @@ namespace CamelotFramework
 	void D3D9PixelBuffer::blitFromMemory(const PixelData &src, const Box &dstBox, BufferResources* dstBufferResources)
 	void D3D9PixelBuffer::blitFromMemory(const PixelData &src, const Box &dstBox, BufferResources* dstBufferResources)
 	{
 	{
 		// for scoped deletion of conversion buffer
 		// for scoped deletion of conversion buffer
-		void* data = NULL;
 		PixelData converted = src;
 		PixelData converted = src;
 
 
 		// convert to pixelbuffer's native format if necessary
 		// convert to pixelbuffer's native format if necessary
 		if (D3D9Mappings::_getPF(src.format) == D3DFMT_UNKNOWN)
 		if (D3D9Mappings::_getPF(src.format) == D3DFMT_UNKNOWN)
 		{
 		{
-			data = (void*)CM_NEW_BYTES(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat), ScratchAlloc);
-			converted = PixelData(src.getWidth(), src.getHeight(), src.getDepth(), mFormat, data);
+			converted = PixelData(src.getWidth(), src.getHeight(), src.getDepth(), mFormat);
+			converted.allocData(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat));
 			PixelUtil::bulkPixelConversion(src, converted);
 			PixelUtil::bulkPixelConversion(src, converted);
 		}
 		}
 
 
@@ -637,7 +636,7 @@ namespace CamelotFramework
 			destRect = toD3DRECT(dstBox);
 			destRect = toD3DRECT(dstBox);
 
 
 			if(D3DXLoadSurfaceFromMemory(dstBufferResources->surface, NULL, &destRect, 
 			if(D3DXLoadSurfaceFromMemory(dstBufferResources->surface, NULL, &destRect, 
-				converted.data, D3D9Mappings::_getPF(converted.format),
+				converted.getData(), D3D9Mappings::_getPF(converted.format),
 				static_cast<UINT>(rowWidth),
 				static_cast<UINT>(rowWidth),
 				NULL, &srcRect, D3DX_DEFAULT, 0) != D3D_OK)
 				NULL, &srcRect, D3DX_DEFAULT, 0) != D3D_OK)
 			{
 			{
@@ -671,7 +670,7 @@ namespace CamelotFramework
 			}
 			}
 
 
 			if(D3DXLoadVolumeFromMemory(dstBufferResources->volume, NULL, &destBox, 
 			if(D3DXLoadVolumeFromMemory(dstBufferResources->volume, NULL, &destBox, 
-				converted.data, D3D9Mappings::_getPF(converted.format),
+				converted.getData(), D3D9Mappings::_getPF(converted.format),
 				static_cast<UINT>(rowWidth), static_cast<UINT>(sliceWidth),
 				static_cast<UINT>(rowWidth), static_cast<UINT>(sliceWidth),
 				NULL, &srcBox, D3DX_DEFAULT, 0) != D3D_OK)
 				NULL, &srcBox, D3DX_DEFAULT, 0) != D3D_OK)
 			{
 			{
@@ -682,8 +681,7 @@ namespace CamelotFramework
 		if(mDoMipmapGen)
 		if(mDoMipmapGen)
 			_genMipmaps(dstBufferResources->mipTex);
 			_genMipmaps(dstBufferResources->mipTex);
 
 
-		if(data != nullptr)
-			CM_DELETE_BYTES(data, ScratchAlloc);
+		converted.freeData();
 	}
 	}
 
 
 	//-----------------------------------------------------------------------------  
 	//-----------------------------------------------------------------------------  

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -76,7 +76,7 @@ namespace CamelotFramework
 		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mFormat);
 		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mFormat);
 
 
 		mLockedBuffer = getBuffer(face, mipLevel);
 		mLockedBuffer = getBuffer(face, mipLevel);
-		lockedArea.data = mLockedBuffer->lock(options);
+		lockedArea.setExternalDataPtr((UINT8*)mLockedBuffer->lock(options));
 
 
 		return lockedArea;
 		return lockedArea;
 	}
 	}

+ 2 - 1
CamelotFreeImgImporter/Source/CmTextureData.cpp

@@ -52,7 +52,8 @@ namespace CamelotFramework
 		}
 		}
 
 
 		// Return subface as pixelbox
 		// Return subface as pixelbox
-		PixelData src(finalWidth, finalHeight, finalDepth, getFormat(), offset);
+		PixelData src(finalWidth, finalHeight, finalDepth, getFormat());
+		src.setExternalDataPtr(offset);
 		return src;
 		return src;
 	}
 	}
 }
 }

+ 18 - 22
CamelotGLRenderer/Source/CmGLPixelBuffer.cpp

@@ -50,15 +50,16 @@ namespace CamelotFramework
 	GLPixelBuffer::~GLPixelBuffer()
 	GLPixelBuffer::~GLPixelBuffer()
 	{
 	{
 		// Force free buffer
 		// Force free buffer
-		CM_DELETE_BYTES(mBuffer.data, ScratchAlloc);
+		mBuffer.freeData();
 	}
 	}
 	//-----------------------------------------------------------------------------  
 	//-----------------------------------------------------------------------------  
 	void GLPixelBuffer::allocateBuffer()
 	void GLPixelBuffer::allocateBuffer()
 	{
 	{
-		if(mBuffer.data)
+		if(mBuffer.getData())
 			// Already allocated
 			// Already allocated
 			return;
 			return;
-		mBuffer.data = CM_NEW_BYTES(mSizeInBytes, ScratchAlloc);
+
+		mBuffer.allocData(mSizeInBytes);
 		// TODO: use PBO if we're HBU_DYNAMIC
 		// TODO: use PBO if we're HBU_DYNAMIC
 	}
 	}
 	//-----------------------------------------------------------------------------  
 	//-----------------------------------------------------------------------------  
@@ -67,8 +68,7 @@ namespace CamelotFramework
 		// Free buffer if we're STATIC to save memory
 		// Free buffer if we're STATIC to save memory
 		if(mUsage & GBU_STATIC)
 		if(mUsage & GBU_STATIC)
 		{
 		{
-			CM_DELETE_BYTES(mBuffer.data, ScratchAlloc);
-			mBuffer.data = 0;
+			mBuffer.freeData();
 		}
 		}
 	}
 	}
 	//-----------------------------------------------------------------------------  
 	//-----------------------------------------------------------------------------  
@@ -267,7 +267,7 @@ namespace CamelotFramework
 							dest.getWidth(),
 							dest.getWidth(),
 							0,
 							0,
 							data.getConsecutiveSize(),
 							data.getConsecutiveSize(),
-							data.data);
+							data.getData());
 					}
 					}
 					else
 					else
 					{
 					{
@@ -275,7 +275,7 @@ namespace CamelotFramework
 							dest.left,
 							dest.left,
 							dest.getWidth(),
 							dest.getWidth(),
 							format, data.getConsecutiveSize(),
 							format, data.getConsecutiveSize(),
-							data.data);
+							data.getData());
 					}
 					}
 					break;
 					break;
 				case GL_TEXTURE_2D:
 				case GL_TEXTURE_2D:
@@ -290,7 +290,7 @@ namespace CamelotFramework
 							dest.getHeight(),
 							dest.getHeight(),
 							0,
 							0,
 							data.getConsecutiveSize(),
 							data.getConsecutiveSize(),
-							data.data);
+							data.getData());
 					}
 					}
 					else
 					else
 					{
 					{
@@ -298,7 +298,7 @@ namespace CamelotFramework
 							dest.left, dest.top, 
 							dest.left, dest.top, 
 							dest.getWidth(), dest.getHeight(),
 							dest.getWidth(), dest.getHeight(),
 							format, data.getConsecutiveSize(),
 							format, data.getConsecutiveSize(),
-							data.data);
+							data.getData());
 					}
 					}
 					break;
 					break;
 				case GL_TEXTURE_3D:
 				case GL_TEXTURE_3D:
@@ -313,7 +313,7 @@ namespace CamelotFramework
 							dest.getDepth(),
 							dest.getDepth(),
 							0,
 							0,
 							data.getConsecutiveSize(),
 							data.getConsecutiveSize(),
-							data.data);
+							data.getData());
 					}
 					}
 					else
 					else
 					{			
 					{			
@@ -321,7 +321,7 @@ namespace CamelotFramework
 							dest.left, dest.top, dest.front,
 							dest.left, dest.top, dest.front,
 							dest.getWidth(), dest.getHeight(), dest.getDepth(),
 							dest.getWidth(), dest.getHeight(), dest.getDepth(),
 							format, data.getConsecutiveSize(),
 							format, data.getConsecutiveSize(),
-							data.data);
+							data.getData());
 					}
 					}
 					break;
 					break;
 			}
 			}
@@ -345,7 +345,7 @@ namespace CamelotFramework
 						dest.left,
 						dest.left,
 						dest.getWidth(),
 						dest.getWidth(),
 						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
 						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
-						data.data);
+						data.getData());
 					break;
 					break;
 				case GL_TEXTURE_2D:
 				case GL_TEXTURE_2D:
 				case GL_TEXTURE_CUBE_MAP:
 				case GL_TEXTURE_CUBE_MAP:
@@ -353,7 +353,7 @@ namespace CamelotFramework
 						dest.left, dest.top, 
 						dest.left, dest.top, 
 						dest.getWidth(), dest.getHeight(),
 						dest.getWidth(), dest.getHeight(),
 						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
 						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
-						data.data);
+						data.getData());
 					break;
 					break;
 				case GL_TEXTURE_3D:
 				case GL_TEXTURE_3D:
 					glTexSubImage3D(
 					glTexSubImage3D(
@@ -361,7 +361,7 @@ namespace CamelotFramework
 						dest.left, dest.top, dest.front,
 						dest.left, dest.top, dest.front,
 						dest.getWidth(), dest.getHeight(), dest.getDepth(),
 						dest.getWidth(), dest.getHeight(), dest.getDepth(),
 						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
 						GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
-						data.data);
+						data.getData());
 					break;
 					break;
 			}	
 			}	
 		}
 		}
@@ -393,7 +393,7 @@ namespace CamelotFramework
 				"Compressed images must be consecutive, in the source format");
 				"Compressed images must be consecutive, in the source format");
 			// Data must be consecutive and at beginning of buffer as PixelStorei not allowed
 			// Data must be consecutive and at beginning of buffer as PixelStorei not allowed
 			// for compressed formate
 			// for compressed formate
-			glGetCompressedTexImage(mFaceTarget, mLevel, data.data);
+			glGetCompressedTexImage(mFaceTarget, mLevel, data.getData());
 		} 
 		} 
 		else
 		else
 		{
 		{
@@ -410,7 +410,7 @@ namespace CamelotFramework
 			// We can only get the entire texture
 			// We can only get the entire texture
 			glGetTexImage(mFaceTarget, mLevel, 
 			glGetTexImage(mFaceTarget, mLevel, 
 				GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
 				GLPixelUtil::getGLOriginFormat(data.format), GLPixelUtil::getGLOriginDataType(data.format),
-				data.data);
+				data.getData());
 			// Restore defaults
 			// Restore defaults
 			glPixelStorei(GL_PACK_ROW_LENGTH, 0);
 			glPixelStorei(GL_PACK_ROW_LENGTH, 0);
 			glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
 			glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
@@ -690,15 +690,14 @@ namespace CamelotFramework
 		if(!mBuffer.contains(dstBox))
 		if(!mBuffer.contains(dstBox))
 			CM_EXCEPT(InvalidParametersException, "destination box out of range");
 			CM_EXCEPT(InvalidParametersException, "destination box out of range");
 		/// For scoped deletion of conversion buffer
 		/// For scoped deletion of conversion buffer
-		void* data = NULL;
 		PixelData src;
 		PixelData src;
     
     
 		/// First, convert the srcbox to a OpenGL compatible pixel format
 		/// First, convert the srcbox to a OpenGL compatible pixel format
 		if(GLPixelUtil::getGLOriginFormat(src_orig.format) == 0)
 		if(GLPixelUtil::getGLOriginFormat(src_orig.format) == 0)
 		{
 		{
 			/// Convert to buffer internal format
 			/// Convert to buffer internal format
-			data = CM_NEW_BYTES(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat), ScratchAlloc);
-			src = PixelData(src_orig.getWidth(), src_orig.getHeight(), src_orig.getDepth(), mFormat, data);
+			src = PixelData(src_orig.getWidth(), src_orig.getHeight(), src_orig.getDepth(), mFormat);
+			src.allocData(PixelUtil::getMemorySize(src.getWidth(), src.getHeight(), src.getDepth(), mFormat));
 			PixelUtil::bulkPixelConversion(src_orig, src);
 			PixelUtil::bulkPixelConversion(src_orig, src);
 		}
 		}
 		else
 		else
@@ -743,9 +742,6 @@ namespace CamelotFramework
     
     
 		/// Delete temp texture
 		/// Delete temp texture
 		glDeleteTextures(1, &id);
 		glDeleteTextures(1, &id);
-
-		if(data != NULL)
-			CM_DELETE_BYTES(data, ScratchAlloc);
 	}
 	}
 	//********* GLRenderBuffer
 	//********* GLRenderBuffer
 	//----------------------------------------------------------------------------- 
 	//----------------------------------------------------------------------------- 

+ 1 - 1
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -251,7 +251,7 @@ namespace CamelotFramework {
 		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mFormat);
 		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mFormat);
 
 
 		mLockedBuffer = getBuffer(face, mipLevel);
 		mLockedBuffer = getBuffer(face, mipLevel);
-		lockedArea.data = mLockedBuffer->lock(options);
+		lockedArea.setExternalDataPtr((UINT8*)mLockedBuffer->lock(options));
 
 
 		return lockedArea;
 		return lockedArea;
 	}
 	}

+ 3 - 3
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -652,7 +652,7 @@ namespace CamelotFramework {
 		glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK);
 		glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK);
 		glReadPixels((GLint)dst.left, (GLint)dst.top,
 		glReadPixels((GLint)dst.left, (GLint)dst.top,
 					 (GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(),
 					 (GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(),
-					 format, type, dst.data);
+					 format, type, dst.getData());
 
 
 		// restore default alignment
 		// restore default alignment
 		glPixelStorei(GL_PACK_ALIGNMENT, 4);
 		glPixelStorei(GL_PACK_ALIGNMENT, 4);
@@ -662,7 +662,7 @@ namespace CamelotFramework {
 			size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format);
 			size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format);
 			size_t height = dst.getHeight();
 			size_t height = dst.getHeight();
 			UINT8 *tmpData = CM_NEW_BYTES((UINT32)(rowSpan * height), ScratchAlloc);
 			UINT8 *tmpData = CM_NEW_BYTES((UINT32)(rowSpan * height), ScratchAlloc);
-			UINT8 *srcRow = (UINT8 *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan;
+			UINT8 *srcRow = (UINT8 *)dst.getData(), *tmpRow = tmpData + (height - 1) * rowSpan;
 
 
 			while (tmpRow >= tmpData)
 			while (tmpRow >= tmpData)
 			{
 			{
@@ -670,7 +670,7 @@ namespace CamelotFramework {
 				srcRow += rowSpan;
 				srcRow += rowSpan;
 				tmpRow -= rowSpan;
 				tmpRow -= rowSpan;
 			}
 			}
-			memcpy(dst.data, tmpData, rowSpan * height);
+			memcpy(dst.getData(), tmpData, rowSpan * height);
 
 
 			CM_DELETE_BYTES(tmpData, ScratchAlloc);
 			CM_DELETE_BYTES(tmpData, ScratchAlloc);
 		}
 		}

+ 19 - 10
CamelotUtility/Include/CmPixelData.h

@@ -126,10 +126,7 @@ namespace CamelotFramework
     	PixelData() {}
     	PixelData() {}
 		~PixelData() 
 		~PixelData() 
 		{
 		{
-			if(ownsData && data != nullptr)
-				CM_DELETE_BYTES(data, ScratchAlloc);
-
-			data = nullptr;
+			freeData();
 		}
 		}
 		/** Constructor providing extents in the form of a Box object. This constructor
 		/** Constructor providing extents in the form of a Box object. This constructor
     		assumes the pixel data is laid out consecutively in memory. (this
     		assumes the pixel data is laid out consecutively in memory. (this
@@ -138,8 +135,8 @@ namespace CamelotFramework
     		@param pixelFormat	Format of this buffer
     		@param pixelFormat	Format of this buffer
     		@param pixelData	Pointer to the actual data
     		@param pixelData	Pointer to the actual data
     	*/
     	*/
-		PixelData(const Box &extents, PixelFormat pixelFormat, void *pixelData = nullptr):
-			Box(extents), data(pixelData), format(pixelFormat), ownsData(false)
+		PixelData(const Box &extents, PixelFormat pixelFormat):
+			Box(extents), data(nullptr), format(pixelFormat), ownsData(false)
 		{
 		{
 			setConsecutive();
 			setConsecutive();
 		}
 		}
@@ -153,9 +150,9 @@ namespace CamelotFramework
     		@param pixelFormat	Format of this buffer
     		@param pixelFormat	Format of this buffer
     		@param pixelData    Pointer to the actual data
     		@param pixelData    Pointer to the actual data
     	*/
     	*/
-    	PixelData(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat, void *pixelData = nullptr):
+    	PixelData(UINT32 width, UINT32 height, UINT32 depth, PixelFormat pixelFormat):
     		Box(0, 0, 0, width, height, depth),
     		Box(0, 0, 0, width, height, depth),
-    		data(pixelData), format(pixelFormat), ownsData(false)
+    		data(nullptr), format(pixelFormat), ownsData(false)
     	{
     	{
     		setConsecutive();
     		setConsecutive();
     	}
     	}
@@ -167,8 +164,16 @@ namespace CamelotFramework
 		 */
 		 */
 		UINT8* allocData(UINT32 size);
 		UINT8* allocData(UINT32 size);
 
 
-        /// The data pointer 
-        void *data;
+		/**
+		 * @brief	Frees the buffer data. Normally you don't need to call this manually as the
+		 * 			data will be freed automatically when an instance of PixelData is freed.
+		 */
+		void freeData();
+
+		void setExternalDataPtr(UINT8* data);
+
+		void* getData() const { return data; }
+
         /// The pixel format 
         /// The pixel format 
         PixelFormat format;
         PixelFormat format;
         /** Number of elements between the leftmost pixel of one row and the left
         /** Number of elements between the leftmost pixel of one row and the left
@@ -244,6 +249,10 @@ namespace CamelotFramework
          */
          */
         void setColourAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z);
         void setColourAt(Color const &cv, UINT32 x, UINT32 y, UINT32 z);
 
 
+	private:
+		/// The data pointer 
+		void *data;
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 1 - 1
CamelotUtility/Include/CmPixelDataRTTI.h

@@ -38,7 +38,7 @@ namespace CamelotFramework
 
 
 		ManagedDataBlock getData(PixelData* obj) 
 		ManagedDataBlock getData(PixelData* obj) 
 		{ 
 		{ 
-			ManagedDataBlock dataBlock((UINT8*)obj->data, obj->getConsecutiveSize());
+			ManagedDataBlock dataBlock((UINT8*)obj->getData(), obj->getConsecutiveSize());
 			return dataBlock; 
 			return dataBlock; 
 		}
 		}
 
 

+ 0 - 10
CamelotUtility/Include/CmPixelUtil.h

@@ -206,16 +206,6 @@ namespace CamelotFramework {
         */
         */
         static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src); 
         static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf,  const void* src); 
         
         
-        /** Convert consecutive pixels from one format to another. No dithering or filtering is being done. 
-         	Converting from RGB to luminance takes the R channel.  In case the source and destination format match,
-         	just a copy is done.
-         	@param	src			Pointer to source region
-         	@param	srcFormat	Pixel format of source region
-         	@param   dst			Pointer to destination region
-         	@param	dstFormat	Pixel format of destination region
-         */
-        static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count);
-
       	/** Convert pixels from one format to another. No dithering or filtering is being done. Converting
       	/** Convert pixels from one format to another. No dithering or filtering is being done. Converting
           	from RGB to luminance takes the R channel. 
           	from RGB to luminance takes the R channel. 
 		 	@param	src			PixelBox containing the source pixels, pitches and format
 		 	@param	src			PixelBox containing the source pixels, pitches and format

+ 1 - 1
CamelotUtility/Source/CmDebug.cpp

@@ -51,7 +51,7 @@ namespace CamelotFramework
 		UINT32 bmpDataSize = BitmapWriter::getBMPSize(pixelData.getWidth(), pixelData.getHeight(), bytesPerPixel);
 		UINT32 bmpDataSize = BitmapWriter::getBMPSize(pixelData.getWidth(), pixelData.getHeight(), bytesPerPixel);
 		UINT8* bmpBuffer = CM_NEW_ARRAY(UINT8, bmpDataSize, ScratchAlloc);
 		UINT8* bmpBuffer = CM_NEW_ARRAY(UINT8, bmpDataSize, ScratchAlloc);
 
 
-		BitmapWriter::rawPixelsToBMP((UINT8*)pixelData.data, bmpBuffer, pixelData.getWidth(), pixelData.getHeight(), bytesPerPixel);
+		BitmapWriter::rawPixelsToBMP((UINT8*)pixelData.getData(), bmpBuffer, pixelData.getWidth(), pixelData.getHeight(), bytesPerPixel);
 
 
 		ds->write(bmpBuffer, bmpDataSize);
 		ds->write(bmpBuffer, bmpDataSize);
 		ds->close();
 		ds->close();

+ 18 - 0
CamelotUtility/Source/CmPixelData.cpp

@@ -22,6 +22,24 @@ namespace CamelotFramework
 		return (UINT8*)data;
 		return (UINT8*)data;
 	}
 	}
 
 
+	void PixelData::freeData()
+	{
+		if(ownsData && getData() != nullptr)
+		{
+			CM_DELETE_BYTES(getData(), ScratchAlloc);
+
+			data = nullptr;
+		}
+	}
+
+	void PixelData::setExternalDataPtr(UINT8* data)
+	{
+		freeData();
+
+		this->data = data;
+		ownsData = false;
+	}
+
 	/************************************************************************/
 	/************************************************************************/
 	/* 								SERIALIZATION                      		*/
 	/* 								SERIALIZATION                      		*/
 	/************************************************************************/
 	/************************************************************************/

+ 26 - 36
CamelotUtility/Source/CmPixelUtil.cpp

@@ -55,8 +55,8 @@ namespace CamelotFramework {
 			// assert(src.format == dst.format);
 			// assert(src.format == dst.format);
 
 
 			// srcdata stays at beginning, pdst is a moving pointer
 			// srcdata stays at beginning, pdst is a moving pointer
-			UINT8* srcdata = (UINT8*)src.data;
-			UINT8* pdst = (UINT8*)dst.data;
+			UINT8* srcdata = (UINT8*)src.getData();
+			UINT8* pdst = (UINT8*)dst.getData();
 
 
 			// sx_48,sy_48,sz_48 represent current position in source
 			// sx_48,sy_48,sz_48 represent current position in source
 			// using 16/48-bit fixed precision, incremented by steps
 			// using 16/48-bit fixed precision, incremented by steps
@@ -96,8 +96,8 @@ namespace CamelotFramework {
 			size_t dstelemsize = PixelUtil::getNumElemBytes(dst.format);
 			size_t dstelemsize = PixelUtil::getNumElemBytes(dst.format);
 
 
 			// srcdata stays at beginning, pdst is a moving pointer
 			// srcdata stays at beginning, pdst is a moving pointer
-			UINT8* srcdata = (UINT8*)src.data;
-			UINT8* pdst = (UINT8*)dst.data;
+			UINT8* srcdata = (UINT8*)src.getData();
+			UINT8* pdst = (UINT8*)dst.getData();
 
 
 			// sx_48,sy_48,sz_48 represent current position in source
 			// sx_48,sy_48,sz_48 represent current position in source
 			// using 16/48-bit fixed precision, incremented by steps
 			// using 16/48-bit fixed precision, incremented by steps
@@ -181,8 +181,8 @@ namespace CamelotFramework {
 			// assert(dstchannels == 3 || dstchannels == 4);
 			// assert(dstchannels == 3 || dstchannels == 4);
 
 
 			// srcdata stays at beginning, pdst is a moving pointer
 			// srcdata stays at beginning, pdst is a moving pointer
-			float* srcdata = (float*)src.data;
-			float* pdst = (float*)dst.data;
+			float* srcdata = (float*)src.getData();
+			float* pdst = (float*)dst.getData();
 
 
 			// sx_48,sy_48,sz_48 represent current position in source
 			// sx_48,sy_48,sz_48 represent current position in source
 			// using 16/48-bit fixed precision, incremented by steps
 			// using 16/48-bit fixed precision, incremented by steps
@@ -292,8 +292,8 @@ namespace CamelotFramework {
 			}
 			}
 
 
 			// srcdata stays at beginning of slice, pdst is a moving pointer
 			// srcdata stays at beginning of slice, pdst is a moving pointer
-			UINT8* srcdata = (UINT8*)src.data;
-			UINT8* pdst = (UINT8*)dst.data;
+			UINT8* srcdata = (UINT8*)src.getData();
+			UINT8* pdst = (UINT8*)dst.getData();
 
 
 			// sx_48,sy_48 represent current position in source
 			// sx_48,sy_48 represent current position in source
 			// using 16/48-bit fixed precision, incremented by steps
 			// using 16/48-bit fixed precision, incremented by steps
@@ -800,11 +800,11 @@ namespace CamelotFramework {
 		// Calculate new data origin
 		// Calculate new data origin
 		// Notice how we do not propagate left/top/front from the incoming box, since
 		// Notice how we do not propagate left/top/front from the incoming box, since
 		// the returned pointer is already offset
 		// the returned pointer is already offset
-		PixelData rval(def.getWidth(), def.getHeight(), def.getDepth(), format, 
-			((UINT8*)data) + ((def.left-left)*elemSize)
+		PixelData rval(def.getWidth(), def.getHeight(), def.getDepth(), format);
+
+		rval.setExternalDataPtr(((UINT8*)getData()) + ((def.left-left)*elemSize)
 			+ ((def.top-top)*rowPitch*elemSize)
 			+ ((def.top-top)*rowPitch*elemSize)
-			+ ((def.front-front)*slicePitch*elemSize)
-		);
+			+ ((def.front-front)*slicePitch*elemSize));
 
 
 		rval.rowPitch = rowPitch;
 		rval.rowPitch = rowPitch;
 		rval.slicePitch = slicePitch;
 		rval.slicePitch = slicePitch;
@@ -1229,16 +1229,6 @@ namespace CamelotFramework {
         }
         }
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    /* Convert pixels from one format to another */
-    void PixelUtil::bulkPixelConversion(void *srcp, PixelFormat srcFormat,
-        void *destp, PixelFormat dstFormat, unsigned int count)
-    {
-        PixelData src(count, 1, 1, srcFormat, srcp),
-				 dst(count, 1, 1, dstFormat, destp);
-
-        bulkPixelConversion(src, dst);
-    }
-    //-----------------------------------------------------------------------
     void PixelUtil::bulkPixelConversion(const PixelData &src, const PixelData &dst)
     void PixelUtil::bulkPixelConversion(const PixelData &src, const PixelData &dst)
     {
     {
         assert(src.getWidth() == dst.getWidth() &&
         assert(src.getWidth() == dst.getWidth() &&
@@ -1250,7 +1240,7 @@ namespace CamelotFramework {
 		{
 		{
 			if(src.format == dst.format)
 			if(src.format == dst.format)
 			{
 			{
-				memcpy(dst.data, src.data, src.getConsecutiveSize());
+				memcpy(dst.getData(), src.getData(), src.getConsecutiveSize());
 				return;
 				return;
 			}
 			}
 			else
 			else
@@ -1264,15 +1254,15 @@ namespace CamelotFramework {
             // Everything consecutive?
             // Everything consecutive?
             if(src.isConsecutive() && dst.isConsecutive())
             if(src.isConsecutive() && dst.isConsecutive())
             {
             {
-				memcpy(dst.data, src.data, src.getConsecutiveSize());
+				memcpy(dst.getData(), src.getData(), src.getConsecutiveSize());
                 return;
                 return;
             }
             }
 
 
             const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.format);
             const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.format);
             const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.format);
             const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.format);
-            UINT8 *srcptr = static_cast<UINT8*>(src.data)
+            UINT8 *srcptr = static_cast<UINT8*>(src.getData())
                 + (src.left + src.top * src.rowPitch + src.front * src.slicePitch) * srcPixelSize;
                 + (src.left + src.top * src.rowPitch + src.front * src.slicePitch) * srcPixelSize;
-            UINT8 *dstptr = static_cast<UINT8*>(dst.data)
+            UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
 				+ (dst.left + dst.top * dst.rowPitch + dst.front * dst.slicePitch) * dstPixelSize;
 				+ (dst.left + dst.top * dst.rowPitch + dst.front * dst.slicePitch) * dstPixelSize;
 
 
             // Calculate pitches+skips in bytes
             // Calculate pitches+skips in bytes
@@ -1324,9 +1314,9 @@ namespace CamelotFramework {
 
 
         const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.format);
         const size_t srcPixelSize = PixelUtil::getNumElemBytes(src.format);
         const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.format);
         const size_t dstPixelSize = PixelUtil::getNumElemBytes(dst.format);
-        UINT8 *srcptr = static_cast<UINT8*>(src.data)
+        UINT8 *srcptr = static_cast<UINT8*>(src.getData())
             + (src.left + src.top * src.rowPitch + src.front * src.slicePitch) * srcPixelSize;
             + (src.left + src.top * src.rowPitch + src.front * src.slicePitch) * srcPixelSize;
-        UINT8 *dstptr = static_cast<UINT8*>(dst.data)
+        UINT8 *dstptr = static_cast<UINT8*>(dst.getData())
             + (dst.left + dst.top * dst.rowPitch + dst.front * dst.slicePitch) * dstPixelSize;
             + (dst.left + dst.top * dst.rowPitch + dst.front * dst.slicePitch) * dstPixelSize;
 		
 		
 		// Old way, not taking into account box dimensions
 		// Old way, not taking into account box dimensions
@@ -1378,7 +1368,7 @@ namespace CamelotFramework {
 			{
 			{
 				// Allocate temporary buffer of destination size in source format 
 				// Allocate temporary buffer of destination size in source format 
 				temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
 				temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
-				temp.data = malloc(temp.getConsecutiveSize());
+				temp.allocData(temp.getConsecutiveSize());
 			}
 			}
 			// super-optimized: no conversion
 			// super-optimized: no conversion
 			switch (PixelUtil::getNumElemBytes(src.format)) 
 			switch (PixelUtil::getNumElemBytes(src.format)) 
@@ -1395,12 +1385,12 @@ namespace CamelotFramework {
 				// never reached
 				// never reached
 				assert(false);
 				assert(false);
 			}
 			}
-			if(temp.data != scaled.data)
+			if(temp.getData() != scaled.getData())
 			{
 			{
 				// Blit temp buffer
 				// Blit temp buffer
 				PixelUtil::bulkPixelConversion(temp, scaled);
 				PixelUtil::bulkPixelConversion(temp, scaled);
 
 
-				free(temp.data);
+				temp.freeData();
 			}
 			}
 			break;
 			break;
 
 
@@ -1422,7 +1412,7 @@ namespace CamelotFramework {
 				{
 				{
 					// Allocate temp buffer of destination size in source format 
 					// Allocate temp buffer of destination size in source format 
 					temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
 					temp = PixelData(scaled.getWidth(), scaled.getHeight(), scaled.getDepth(), src.format);
-					temp.data = malloc(temp.getConsecutiveSize());
+					temp.allocData(temp.getConsecutiveSize());
 				}
 				}
 				// super-optimized: byte-oriented math, no conversion
 				// super-optimized: byte-oriented math, no conversion
 				switch (PixelUtil::getNumElemBytes(src.format)) 
 				switch (PixelUtil::getNumElemBytes(src.format)) 
@@ -1435,11 +1425,11 @@ namespace CamelotFramework {
 					// never reached
 					// never reached
 					assert(false);
 					assert(false);
 				}
 				}
-				if(temp.data != scaled.data)
+				if(temp.getData() != scaled.getData())
 				{
 				{
 					// Blit temp buffer
 					// Blit temp buffer
 					PixelUtil::bulkPixelConversion(temp, scaled);
 					PixelUtil::bulkPixelConversion(temp, scaled);
-					free(temp.data);
+					temp.freeData();
 				}
 				}
 				break;
 				break;
 			case PF_FLOAT32_RGB:
 			case PF_FLOAT32_RGB:
@@ -1505,7 +1495,7 @@ namespace CamelotFramework {
 
 
         UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
         UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
         UINT32 pixelOffset = pixelSize * (z * slicePitch + y * rowPitch + x);
         UINT32 pixelOffset = pixelSize * (z * slicePitch + y * rowPitch + x);
-        PixelUtil::unpackColour(&cv, format, (unsigned char *)data + pixelOffset);
+        PixelUtil::unpackColour(&cv, format, (unsigned char *)getData() + pixelOffset);
 
 
         return cv;
         return cv;
     }
     }
@@ -1514,6 +1504,6 @@ namespace CamelotFramework {
     {
     {
         UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
         UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
         UINT32 pixelOffset = pixelSize * (z * slicePitch + y * rowPitch + x);
         UINT32 pixelOffset = pixelSize * (z * slicePitch + y * rowPitch + x);
-        PixelUtil::packColour(cv, format, (unsigned char *)data + pixelOffset);
+        PixelUtil::packColour(cv, format, (unsigned char *)getData() + pixelOffset);
     }
     }
 }
 }

+ 9 - 5
TODO.txt

@@ -1,11 +1,6 @@
 ----------------------- CAMELOT 2D / GUI -----------------------------------------------------------
 ----------------------- CAMELOT 2D / GUI -----------------------------------------------------------
 
 
 ----------------------------------------------------------------------------------------------
 ----------------------------------------------------------------------------------------------
-Finish up DX9 window init
-Attempt to remove _notifyWindowCreated method
- - instead make sure of RenderWindowManager?
-
--------------
 
 
 When I'm canceling command queue commands I might be canceling important user commands.
 When I'm canceling command queue commands I might be canceling important user commands.
  - (e.g. user schedules a resource update and I cancel the command)
  - (e.g. user schedules a resource update and I cancel the command)
@@ -14,6 +9,15 @@ When I'm canceling command queue commands I might be canceling important user co
    - input lag?
    - input lag?
 
 
 <<<<<<<Resource update/read>>>>>>>>
 <<<<<<<Resource update/read>>>>>>>>
+In order to get write/readSubresource usable I probably need to add AsyncOp.waitUntilComplete
+ - (Also remove "blockUntilFinished" parameters when queuing commands, as waitUntilComplete can be used instead)
+   - Or can it? Some operations don't return AsyncOp
+DeferredContext
+ - updateSubresource
+ - readSubresource - how to avoid casting returned value to either MeshData or PixelData?
+   - Have it as a parameter, that is created on main thread, using the source resource. (e.g. Texture::createCPUBuffer)
+
+
 All data classes (MeshData, PixelData, etc) derive from GpuBufferData class. 
 All data classes (MeshData, PixelData, etc) derive from GpuBufferData class. 
  - It contains basically just raw bytes.
  - It contains basically just raw bytes.
  - It has lock/unlock methods (used mostly internally)
  - It has lock/unlock methods (used mostly internally)