Skip to content

Commit

Permalink
fix: deleted doFlush, _createShared2DTex()
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurfernades committed Jan 16, 2025
1 parent 2d11b85 commit 3cc8d14
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 103 deletions.
2 changes: 1 addition & 1 deletion Components/Overlay/include/ImGui.i
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#ifdef SWIGPYTHON
// match the signature of the by value variants
%typemap(argout) float[4], float[3], float[2] {
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj($1, $descriptor(ImVec4*), 0));
$result = SWIG_AppendOutput($result, SWIG_NewPointerObj($1, $descriptor(ImVec4*), 0));
}

// for PlotHistogram, PlotLines
Expand Down
2 changes: 0 additions & 2 deletions OgreMain/include/OgreRenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ namespace Ogre {
*/
virtual void getCustomAttribute(const String& name, void* pData);

virtual void doFlush();

/** simplified API for bindings
*
* @overload
Expand Down
2 changes: 0 additions & 2 deletions OgreMain/include/OgreTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ namespace Ogre {
@param pData Pointer to memory matching the type of data you want to retrieve.
*/
virtual void getCustomAttribute(const String& name, void* pData);

virtual void doFlush();

/** simplified API for bindings
*
Expand Down
2 changes: 0 additions & 2 deletions OgreMain/src/OgreRenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ namespace Ogre {
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Attribute not found. " + name, " RenderTarget::getCustomAttribute");
}
//-----------------------------------------------------------------------
void RenderTarget::doFlush() { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Flush Error"); }
//-----------------------------------------------------------------------
void RenderTarget::addListener(RenderTargetListener* listener)
{
if (std::find(mListeners.begin(), mListeners.end(), listener) == mListeners.end())
Expand Down
4 changes: 0 additions & 4 deletions OgreMain/src/OgreTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ namespace Ogre {
{
}
//--------------------------------------------------------------------------
void Texture::doFlush()
{
}
//--------------------------------------------------------------------------
void Texture::readImage(LoadedImages& imgs, const String& name, const String& ext, bool haveNPOT)
{
DataStreamPtr dstream = ResourceGroupManager::getSingleton().openResource(name, mGroup, this);
Expand Down
3 changes: 2 additions & 1 deletion RenderSystems/Direct3D11/include/OgreD3D11Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ namespace Ogre {
void _create1DTex();
/// internal method, create a blank normal 2D texture
void _create2DTex();
/// internal method to create a normal 2D texture with an already existing surface
void _createShared2DTex();
/// internal method, create a blank cube texture
void _create3DTex();

Expand Down Expand Up @@ -156,7 +158,6 @@ namespace Ogre {
protected:
void notifyDeviceLost(D3D11Device* device);
void notifyDeviceRestored(D3D11Device* device);
void doFlush();
};

}
Expand Down
208 changes: 117 additions & 91 deletions RenderSystems/Direct3D11/src/OgreD3D11Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,105 +233,50 @@ namespace Ogre
//---------------------------------------------------------------------
void D3D11Texture::_create2DTex()
{
if (NULL != mSurface)
{
HRESULT hr = S_OK;

IUnknown* pUnk = (IUnknown*)mSurface;

IDXGIResource* pDXGIResource;
hr = pUnk->QueryInterface(__uuidof(IDXGIResource), (void**)&pDXGIResource);
if (FAILED(hr))
{
throw std::runtime_error("Failed to query IDXGIResource interface from the provided object.");
}

HANDLE sharedHandle;
hr = pDXGIResource->GetSharedHandle(&sharedHandle);
if (FAILED(hr))
{
throw std::runtime_error("Failed to retrieve the shared handle from IDXGIResource. Ensure the resource was "
"created with the D3D11_RESOURCE_MISC_SHARED flag.");
}

pDXGIResource->Release();

IUnknown* tempResource11;
hr = mDevice->OpenSharedResource(sharedHandle, __uuidof(ID3D11Resource), (void**)(&tempResource11));
if (FAILED(hr))
{
throw std::runtime_error("Failed to open shared resource using the shared handle. Ensure the handle is "
"valid and the device supports shared resources.");
}

ID3D11Texture2D* pOutputResource;
hr = tempResource11->QueryInterface(__uuidof(ID3D11Texture2D), (void**)(&pOutputResource));
if (FAILED(hr))
{
throw std::runtime_error("Failed to query ID3D11Texture2D interface from the shared resource. Ensure the "
"resource is of the correct type.");
}
tempResource11->Release();

mp2DTex = pOutputResource;

D3D11_TEXTURE2D_DESC desc;
mp2DTex->GetDesc(&desc);

D3D11_RENDER_TARGET_VIEW_DESC rtDesc;
rtDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtDesc.Texture2D.MipSlice = 0;

ComPtr<ID3D11RenderTargetView> renderTargetView;
hr = mDevice->CreateRenderTargetView(mp2DTex.Get(), nullptr, renderTargetView.GetAddressOf());
if (FAILED(hr))
throw std::runtime_error("Failed to create ID3D11RenderTargetView. Verify that the texture is valid, "
"properly initialized, and compatible with RenderTargetView creation.");
}
else
{
if (mSurface)
{
_createShared2DTex();
return;
}
// we must have those defined here
assert(mSrcWidth > 0 || mSrcHeight > 0);

// determine total number of mipmaps including main one (d3d11 convention)
UINT numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > std::max(mSrcWidth, mSrcHeight))
? 0
: mNumMipmaps + 1;
if (D3D11Mappings::_isBinaryCompressedFormat(mD3DFormat) && numMips > 1)
UINT numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > std::max(mSrcWidth, mSrcHeight)) ? 0 : mNumMipmaps + 1;
if(D3D11Mappings::_isBinaryCompressedFormat(mD3DFormat) && numMips > 1)
numMips = std::max(1U, numMips - 2);

D3D11_TEXTURE2D_DESC desc;
desc.Width = static_cast<UINT>(mSrcWidth);
desc.Height = static_cast<UINT>(mSrcHeight);
desc.MipLevels = numMips;
desc.ArraySize = mDepth == 0 ? 1 : mDepth;
desc.Format = mD3DFormat;
desc.SampleDesc = mFSAAType;
desc.Usage = D3D11Mappings::_getUsage(_getTextureUsage());
desc.BindFlags = D3D11Mappings::_getTextureBindFlags(mD3DFormat, _getTextureUsage());
desc.Width = static_cast<UINT>(mSrcWidth);
desc.Height = static_cast<UINT>(mSrcHeight);
desc.MipLevels = numMips;
desc.ArraySize = mDepth == 0 ? 1 : mDepth;
desc.Format = mD3DFormat;
desc.SampleDesc = mFSAAType;
desc.Usage = D3D11Mappings::_getUsage(_getTextureUsage());
desc.BindFlags = D3D11Mappings::_getTextureBindFlags(mD3DFormat, _getTextureUsage());
desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(_getTextureUsage());
desc.MiscFlags = D3D11Mappings::_getTextureMiscFlags(desc.BindFlags, getTextureType(), _getTextureUsage());
desc.MiscFlags = D3D11Mappings::_getTextureMiscFlags(desc.BindFlags, getTextureType(), _getTextureUsage());

if (PixelUtil::isDepth(mFormat))
{
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
}

if (this->getTextureType() == TEX_TYPE_CUBE_MAP)
{
desc.ArraySize = 6;
desc.ArraySize = 6;
}

D3D11RenderSystem* rs = (D3D11RenderSystem*)Root::getSingleton().getRenderSystem();
if (rs->_getFeatureLevel() < D3D_FEATURE_LEVEL_10_0)
if(rs->_getFeatureLevel() < D3D_FEATURE_LEVEL_10_0)
{
// http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150%28v=vs.85%29.aspx#ID3D11Device_CreateTexture2D
// ...If MipCount > 1, Dimensions must be integral power of two...
if (!IsPowerOfTwo(desc.Width) || !IsPowerOfTwo(desc.Height))
if(!IsPowerOfTwo(desc.Width) || !IsPowerOfTwo(desc.Height))
{
desc.MipLevels = 1;
}
Expand All @@ -344,26 +289,109 @@ namespace Ogre
}

// create the texture
HRESULT hr = mDevice->CreateTexture2D(&desc,
NULL, // data pointer
mp2DTex.ReleaseAndGetAddressOf());
HRESULT hr = mDevice->CreateTexture2D(
&desc,
NULL,// data pointer
mp2DTex.ReleaseAndGetAddressOf());
// check result and except if failed
if (FAILED(hr) || mDevice.isError())
{
this->unloadImpl();
String errorDescription = mDevice.getErrorDescription(hr);
OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr,
"Error creating texture\nError Description:" + errorDescription,
"D3D11Texture::_create2DTex");
OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr,
"Error creating texture\nError Description:" + errorDescription,
"D3D11Texture::_create2DTex" );
}
}

// set the base texture we'll use in the render system
_queryInterface<ID3D11Texture2D, ID3D11Resource>(mp2DTex, &mpTex);
//set the base texture we'll use in the render system
_queryInterface<ID3D11Texture2D, ID3D11Resource>(mp2DTex, &mpTex);

_create2DResourceView();
_create2DResourceView();
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void D3D11Texture::_createShared2DTex()
{
HRESULT hr = S_OK;

IUnknown* pUnk = (IUnknown*)mSurface;

IDXGIResource* pDXGIResource;
hr = pUnk->QueryInterface(__uuidof(IDXGIResource), (void**)&pDXGIResource);
if (FAILED(hr))
{
this->unloadImpl();
OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr,
"Error creating texture\nError Description: Failed to query IDXGIResource interface from "
"the provided object.",
"D3D11Texture::_create2DTex");
}

HANDLE sharedHandle;
hr = pDXGIResource->GetSharedHandle(&sharedHandle);
if (FAILED(hr))
{
this->unloadImpl();
OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr,
"Error creating texture\nError Description: Failed to retrieve the shared handle from "
"IDXGIResource. Ensure the resource was "
"created with the D3D11_RESOURCE_MISC_SHARED flag.",
"D3D11Texture::_create2DTex");
}

pDXGIResource->Release();

IUnknown* tempResource11;
hr = mDevice->OpenSharedResource(sharedHandle, __uuidof(ID3D11Resource), (void**)(&tempResource11));
if (FAILED(hr))
{
this->unloadImpl();
OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr,
"Error creating texture\nError Description: Failed to open shared resource using the shared "
"handle. Ensure the handle is "
"valid and the device supports shared resources.",
"D3D11Texture::_create2DTex");
}

ID3D11Texture2D* pOutputResource;
hr = tempResource11->QueryInterface(__uuidof(ID3D11Texture2D), (void**)(&pOutputResource));
if (FAILED(hr))
{
this->unloadImpl();
OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr,
"Error creating texture\nError Description: Failed to query ID3D11Texture2D interface from "
"the shared resource. Ensure the "
"resource is of the correct type.",
"D3D11Texture::_create2DTex");
}
tempResource11->Release();

mp2DTex = pOutputResource;

D3D11_TEXTURE2D_DESC desc;
mp2DTex->GetDesc(&desc);

D3D11_RENDER_TARGET_VIEW_DESC rtDesc;
rtDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtDesc.Texture2D.MipSlice = 0;

ComPtr<ID3D11RenderTargetView> renderTargetView;
hr = mDevice->CreateRenderTargetView(mp2DTex.Get(), nullptr, renderTargetView.GetAddressOf());
if (FAILED(hr))
{
this->unloadImpl();
OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr,
"Error creating texture\nError Description: Failed to create ID3D11RenderTargetView. Verify "
"that the texture is valid, "
"properly initialized, and compatible with RenderTargetView creation.",
"D3D11Texture::_create2DTex");
}

_queryInterface<ID3D11Texture2D, ID3D11Resource>(mp2DTex, &mpTex);

_create2DResourceView();
}
//----------------------------------------------------------------------------
void D3D11Texture::_create2DResourceView()
{
// set final tex. attributes from tex. description
Expand Down Expand Up @@ -565,8 +593,8 @@ namespace Ogre
}
}
}
//---------------------------------------------------------------------
void D3D11Texture :: _setSurface(void* surface) { mSurface = surface; }
//---------------------------------------------------------------------
void D3D11Texture ::_setSurface(void* surface) { mSurface = surface; }
//---------------------------------------------------------------------
// D3D11RenderTexture
//---------------------------------------------------------------------
Expand Down Expand Up @@ -687,6 +715,4 @@ namespace Ogre
{
rebind(static_cast<D3D11HardwarePixelBuffer*>(mBuffer));
}
//---------------------------------------------------------------------
void D3D11RenderTexture::doFlush() { mDevice.Flush(); }
}

0 comments on commit 3cc8d14

Please sign in to comment.