Przeglądaj źródła

Fixed a bug where texture would be marked as loaded before it really was
Added sync points when loading a texture to ensure we get a valid texture format

Marko Pintera 12 lat temu
rodzic
commit
bbc6f667e1

+ 2 - 0
BansheeEngine/Source/BsGUIManager.cpp

@@ -541,6 +541,7 @@ namespace BansheeEngine
 		if(mCaretTexture == nullptr)
 		{
 			HTexture newTex = Texture::create(TEX_TYPE_2D, 1, 1, 0, PF_R8G8B8A8);
+			newTex->synchonize(); // TODO - Required due to a bug in allocateSubresourceBuffer
 			mCaretTexture = cm_shared_ptr<SpriteTexture>(newTex);
 		}
 
@@ -558,6 +559,7 @@ namespace BansheeEngine
 		if(mTextSelectionTexture == nullptr)
 		{
 			HTexture newTex = Texture::create(TEX_TYPE_2D, 1, 1, 0, PF_R8G8B8A8);
+			newTex->synchonize(); // TODO - Required due to a bug in allocateSubresourceBuffer
 			mTextSelectionTexture = cm_shared_ptr<SpriteTexture>(newTex);
 		}
 

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -35,8 +35,8 @@
 #include "CmRTTIType.h"
 #include "CmPlatform.h"
 
-#define DX11
-//#define DX9
+//#define DX11
+#define DX9
 //#define GL
 
 using namespace CamelotFramework;

+ 3 - 3
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -154,9 +154,7 @@ namespace CamelotFramework
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		Texture::initialize_internal();
-
-			// load based on tex.type
+		// load based on tex.type
 		switch (getTextureType())
 		{
 			case TEX_TYPE_1D:
@@ -173,6 +171,8 @@ namespace CamelotFramework
 				destroy_internal();
 				CM_EXCEPT(RenderingAPIException, "Unknown texture type");
 		}
+
+		Texture::initialize_internal();
 	}
 
 	void D3D11Texture::destroy_internal()

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -230,14 +230,14 @@ namespace CamelotFramework
 	{ 
 		THROW_IF_NOT_CORE_THREAD;
 
-		Texture::initialize_internal();
-
 		for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
 		{
 			IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
 
 			createInternalResources(d3d9Device);
 		}
+
+		Texture::initialize_internal();
 	}
 	
 	void D3D9Texture::destroy_internal()

+ 14 - 2
CamelotFontImporter/Source/CmFontImporter.cpp

@@ -269,10 +269,22 @@ namespace CamelotFramework
 				}
 
 				HTexture newTex = Texture::create(TEX_TYPE_2D, pageIter->width, pageIter->height, 0, PF_R8G8);
-				newTex.synchronize();
+				newTex.synchronize(); // TODO - Required due to a bug in allocateSubresourceBuffer
 
 				UINT32 subresourceIdx = newTex->mapToSubresourceIdx(0, 0);
-				gMainSyncedCA().writeSubresource(newTex.getInternalPtr(), subresourceIdx, pixelData);
+
+				// It's possible the formats no longer match
+				if(newTex->getFormat() != pixelData->getFormat())
+				{
+					PixelDataPtr temp = newTex->allocateSubresourceBuffer(subresourceIdx);
+					PixelUtil::bulkPixelConversion(*pixelData, *temp);
+
+					gMainSyncedCA().writeSubresource(newTex.getInternalPtr(), subresourceIdx, temp);
+				}
+				else
+				{
+					gMainSyncedCA().writeSubresource(newTex.getInternalPtr(), subresourceIdx, pixelData);
+				}
 
 				fontData.texturePages.push_back(newTex);
 

+ 1 - 1
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -128,7 +128,7 @@ namespace CamelotFramework
 		HTexture newTexture = Texture::create(TEX_TYPE_2D, 
 			imgData->getWidth(), imgData->getHeight(), imgData->getNumMipmaps(), imgData->getFormat());
 
-		newTexture.synchronize();
+		newTexture->synchonize(); // TODO - Required due to a bug in allocateSubresourceBuffer
 
 		for(UINT32 mip = 0; mip <= imgData->getNumMipmaps(); ++mip)
 		{

+ 2 - 2
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -62,8 +62,6 @@ namespace CamelotFramework {
 
 	void GLTexture::initialize_internal()
 	{
-		Texture::initialize_internal();
-
 		// Convert to nearest power-of-two size if required
 		mWidth = GLPixelUtil::optionalPO2(mWidth);      
 		mHeight = GLPixelUtil::optionalPO2(mHeight);
@@ -190,6 +188,8 @@ namespace CamelotFramework {
 
 		if(buffer != nullptr)
 			mFormat = buffer->getFormat();
+
+		Texture::initialize_internal();
 	}
 
 	void GLTexture::destroy_internal()

+ 6 - 4
Opts.txt

@@ -42,7 +42,9 @@ from a transient mesh by drawing only parts of its buffer. But only do this afte
 Other possible improvements:
  - MeshData always completely overwrites destination mesh sub-meshes, plus it doesn't allow empty spaces or overlapping between the sub-meshes, they are always
    sequential.
- - Textures do lock/unlock when writing data to them. This causes an unnecessary copy in DX11 (and possibly other APIs)
-   - add writeData/readData methods that do those things as efficiently as possible
- - Textures always create dynamic buffers
- - When writing to mesh vertex buffer that requires a color flip I need to create a temporary copy of the entire buffer. It would be better to handle this differently. 
+ - When writing to mesh vertex buffer that requires a color flip I need to create a temporary copy of the entire buffer. It would be better to handle this differently. 
+
+ Problem with Texture::allocateSubresourceBuffer
+ - It relies on format being accurate, however it is only accurate after texture has been created on the core thread. Which means if I call that before texture is created I will get a buffer of incorrect size.
+   - I should probably ensure that parameters provided to Texture are accurate and don't change while on core thread. Probably deal with them inside TextureManager.
+   - After that is done remove the synchronize() point from FreeImgImporter::import, FontImporter and two texture updates in GUIManager