Sign in to follow this  

Is This normal behavior for a ID3D10ShaderResourceView bound to a rendertarget

This topic is 1117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi.

I have 2 image boxes I created for a UI system they both have there mesh material and a over ride material.

this over ride material gets set when setmaterial 1 button and set material 2 buttons are pressed.

I have a render target set for rendering meshes and that targts ID3D10ShaderResourceView gets copyed to the image boxes material.

Now picture this there is 2 image boxes on the screen 1 on the left and one on the right with a button under each.

The only time the render target is invoked is when one of the 2 button are pressed(its not a real time render)

after rendering depending if it was button 1 or 2 I set there materials ID3D10ShaderResourceView to the render targets ID3D10ShaderResourceView

thats ok the mesh is there and it works. but if I press button 2 and have a different mesh both the image boxes display the same view.

It's like when I set the ID3D10ShaderResourceView its a pointer to the current render target.

heres the code that I use to copy and create the view I also delete the view.

 

 

This code in a function when it ends it no longer has focus

///////////////////////////////////////////////////////////////////////////////////////
//we need to create a resource and copy the rt to it 
				// Create the shader-resource view
				D3D10_SHADER_RESOURCE_VIEW_DESC srDesc;
				srDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
				srDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
				srDesc.Texture2D.MostDetailedMip = 0;
				srDesc.Texture2D.MipLevels = 1;
				

				ID3D10ShaderResourceView *pShaderResView = NULL;
				ID3D10Resource *pResource = NULL;

				RenderTargetMesh.colorMap()->GetResource(&pResource);
				HRESULT hr = c3DDevice::m_pd3dDevice->CreateShaderResourceView( pResource, &srDesc, &pShaderResView );
				if(FAILED(hr))
				{
					OutPutDebugText("RenderLibraryToMapDefinedObjects(Failed T Create ResourceView",//TCHAR *errormsg,//the message to display
					"cRTSAssetUIManager::RenderLibraryToMapDefinedObjects()",//TCHAR *locmsg,//the location the message was called Eg. what function
					true);// bool Usewindowmsgbox = false);
				}


				SAFE_RELEASE(pResource);
				//now copy it over
				//c3DDevice::m_pd3dDevice->CopyResource(RenderTargetMesh.colorMap(), &imagebox->mat[0].m_pTextureRV)

				//now set the new one DialogBox_Objects->ImageBox[0].
				imagebox->mat[0].m_pTextureRV = pShaderResView;
				//imagebox->mat[0].m_pTextureRV->AddRef();
				//SAFE_RELEASE(pShaderResView);

////////////////////////////////////////////////////////

But if I do it like this it works It involes creating a texture but



	ID3D10Texture2D* colMap = 0;
	ID3D10ShaderResourceView *newresource = NULL;

	D3D10_TEXTURE2D_DESC texDesc;
	
	texDesc.Width     = mWidth;
	texDesc.Height    = mHeight;
	texDesc.MipLevels = 1;//0 will set them to autao generate mip maps
	texDesc.ArraySize = 1;
	texDesc.Format    = mColorMapFormat;
	texDesc.SampleDesc.Count   = 1;  
	texDesc.SampleDesc.Quality = 0;  
	texDesc.Usage          = D3D10_USAGE_DEFAULT;
	texDesc.BindFlags      = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0; 
	texDesc.MiscFlags      = D3D10_RESOURCE_MISC_GENERATE_MIPS;

	if(FAILED(md3dDevice->CreateTexture2D(&texDesc, 0, &colMap)))
	{
		OutPutDebugText("CreateTexture2D FAILED TO CREATE",//the message to display
						"DrawableTex2D->CopyRenderTarget()",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox
		return NULL;//error
	}//end error


	//now we want to copy the rendertarget to this new colourmap 
	ID3D10Resource *pResource = NULL;

	colorMap()->GetResource(&pResource);

	md3dDevice->CopyResource(colMap, pResource);

	if(FAILED(md3dDevice->CreateShaderResourceView(colMap, 0, &newresource)))
	{
		OutPutDebugText("CreateShaderResourceView FAILED TO CREATE",//the message to display
						"DrawableTex2D->CopyRenderTarget()",//the location the message was called Eg. what function
						 true);//bool Usewindowmsgbox = false);//true if you also want to display it in a messagebox
		return NULL;//error
	}//end error

	// View saves a reference to the texture so we can release our reference.
	SAFE_RELEASE(colMap);
	SAFE_RELEASE(pResource);




Share this post


Link to post
Share on other sites

This topic is 1117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this