D3DHost_FrameBuffer::BindBuffer() now implicitly detaches Depth+Stencil texture in case of driver failure.
D3DHost_View::d3dCreateRenderTarget() now does not request Depth+Stencil texture by default.
const Standard_Integer theSizeX,
const Standard_Integer theSizeY)
{
- if (InitD3dInterop (theCtx, theD3DDevice, theIsD3dEx, theSizeX, theSizeY))
+ if (InitD3dInterop (theCtx, theD3DDevice, theIsD3dEx, theSizeX, theSizeY, GL_DEPTH24_STENCIL8))
{
return Standard_True;
}
- return InitD3dFallback (theCtx, theD3DDevice, theIsD3dEx, theSizeX, theSizeY);
+ return InitD3dFallback (theCtx, theD3DDevice, theIsD3dEx, theSizeX, theSizeY, GL_DEPTH24_STENCIL8);
}
// =======================================================================
IDirect3DDevice9* theD3DDevice,
const Standard_Boolean theIsD3dEx,
const Standard_Integer theSizeX,
- const Standard_Integer theSizeY)
+ const Standard_Integer theSizeY,
+ const GLint theDepthFormat)
{
- const Standard_Boolean isGlInit = Init (theCtx, theSizeX, theSizeY, GL_RGBA8, GL_DEPTH24_STENCIL8, 0);
+ const Standard_Boolean isGlInit = OpenGl_FrameBuffer::Init (theCtx, theSizeX, theSizeY, GL_RGBA8, theDepthFormat, 0);
myD3dFallback = Standard_True;
const Standard_Integer aSizeX = theSizeX > 0 ? theSizeX : 2;
{
Release (theCtx.operator->());
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
- TCollection_AsciiString ("D3DHost_FrameBuffer, could not D3DFMT_X8R8G8B8 render target ") + aSizeX + "x" + aSizeY);
+ TCollection_AsciiString ("D3DHost_FrameBuffer, could not create D3DFMT_X8R8G8B8 render target ") + aSizeX + "x" + aSizeY);
return Standard_False;
}
return isGlInit;
IDirect3DDevice9* theD3DDevice,
const Standard_Boolean theIsD3dEx,
const Standard_Integer theSizeX,
- const Standard_Integer theSizeY)
+ const Standard_Integer theSizeY,
+ const GLint theDepthFormat)
{
Release (theCtx.operator->());
#if !defined(GL_ES_VERSION_2_0)
+ myDepthFormat = theDepthFormat;
myVPSizeX = theSizeX;
myVPSizeY = theSizeY;
myInitVPSizeX = theSizeX;
{
Release (theCtx.operator->());
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
- TCollection_AsciiString ("D3DHost_FrameBuffer, could not D3DFMT_X8R8G8B8 render target ") + aSizeX + "x" + aSizeY);
+ TCollection_AsciiString ("D3DHost_FrameBuffer, could not create D3DFMT_X8R8G8B8 render target ") + aSizeX + "x" + aSizeY);
return Standard_False;
}
myIsOwnBuffer = true;
myIsOwnDepth = true;
theCtx->arbFBO->glGenFramebuffers (1, &myGlFBufferId);
- if (!myDepthStencilTexture->Init (theCtx, GL_DEPTH24_STENCIL8,
- GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8,
- aSizeX, aSizeY, Graphic3d_TOT_2D))
+
+ GLenum aPixelFormat = 0, aDataType = 0;
+ if (myDepthFormat != 0
+ && getDepthDataFormat (myDepthFormat, aPixelFormat, aDataType)
+ && !myDepthStencilTexture->Init (theCtx, myDepthFormat,
+ aPixelFormat, aDataType,
+ aSizeX, aSizeY, Graphic3d_TOT_2D))
{
Release (theCtx.operator->());
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
(void )theIsD3dEx;
(void )theSizeX;
(void )theSizeY;
+ (void )theDepthFormat;
return Standard_False;
#endif
}
myColorTextures (0)->TextureId(),
GL_TEXTURE_2D,
WGL_ACCESS_WRITE_DISCARD_NV);
+ theCtx->ResetErrors (true);
if (myGlD3dSurf == NULL)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
myColorTextures (0)->GetTarget(), myColorTextures (0)->TextureId(), 0);
-#ifdef GL_DEPTH_STENCIL_ATTACHMENT
- theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
- myDepthStencilTexture->GetTarget(), myDepthStencilTexture->TextureId(), 0);
-#else
- theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- myDepthStencilTexture->GetTarget(), myDepthStencilTexture->TextureId(), 0);
- theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
- myDepthStencilTexture->GetTarget(), myDepthStencilTexture->TextureId(), 0);
-#endif
+
+ GLenum aDepthPixelFormat = 0, aDepthDataType = 0;
+ getDepthDataFormat (myDepthFormat, aDepthPixelFormat, aDepthDataType);
+ if (myDepthStencilTexture->IsValid())
+ {
+ #ifdef GL_DEPTH_STENCIL_ATTACHMENT
+ theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, aDepthPixelFormat == GL_DEPTH_STENCIL ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT,
+ myDepthStencilTexture->GetTarget(), myDepthStencilTexture->TextureId(), 0);
+ #else
+ theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+ myDepthStencilTexture->GetTarget(), myDepthStencilTexture->TextureId(), 0);
+ if (aDepthPixelFormat == GL_DEPTH_STENCIL)
+ {
+ theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
+ myDepthStencilTexture->GetTarget(), myDepthStencilTexture->TextureId(), 0);
+ }
+ #endif
+ }
if (theCtx->arbFBO->glCheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
- theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
- "D3DHost_FrameBuffer, OpenGL FBO is incomplete!");
- Release (theCtx.operator->());
+ if (myDepthStencilTexture->IsValid())
+ {
+ #ifdef GL_DEPTH_STENCIL_ATTACHMENT
+ theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, aDepthPixelFormat == GL_DEPTH_STENCIL ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT,
+ myDepthStencilTexture->GetTarget(), 0, 0);
+ #else
+ theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+ myDepthStencilTexture->GetTarget(), 0, 0);
+ if (aDepthPixelFormat == GL_DEPTH_STENCIL)
+ {
+ theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
+ myDepthStencilTexture->GetTarget(), 0, 0);
+ }
+ #endif
+ }
+ if (theCtx->arbFBO->glCheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+ {
+ theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
+ "D3DHost_FrameBuffer, OpenGL FBO is incomplete!");
+ Release (theCtx.operator->());
+ }
+ else
+ {
+ myDepthFormat = 0;
+ myDepthStencilTexture->Release (theCtx.get());
+ theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
+ "D3DHost_FrameBuffer, OpenGL FBO is created without Depth+Stencil attachements!");
+ }
}
}
Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
//! Initializes OpenGL FBO for Direct3D interoperability or in fallback mode.
+ //! Color pixel format is always GL_RGBA8/D3DFMT_X8R8G8B8, no MSAA; depth-stencil pixel format is GL_DEPTH24_STENCIL8.
+ //! @param theGlCtx currently bound OpenGL context
+ //! @param theD3DDevice d3d9 device
+ //! @param theIsD3dEx d3d9 extended flag (for creating shared texture resource)
+ //! @param theSizeX texture width
+ //! @param theSizeY texture height
+ //! @return true on success
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theCtx,
IDirect3DDevice9* theD3DDevice,
const Standard_Boolean theIsD3dEx,
const Standard_Integer theSizeY);
//! Initializes OpenGL FBO for Direct3D interoperability.
+ //! Color pixel format is always GL_RGBA8/D3DFMT_X8R8G8B8, no MSAA.
+ //! @param theGlCtx currently bound OpenGL context
+ //! @param theD3DDevice d3d9 device
+ //! @param theIsD3dEx d3d9 extended flag (for creating shared texture resource)
+ //! @param theSizeX texture width
+ //! @param theSizeY texture height
+ //! @param theDepthFormat depth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
+ //! @return true on success
Standard_EXPORT Standard_Boolean InitD3dInterop (const Handle(OpenGl_Context)& theCtx,
IDirect3DDevice9* theD3DDevice,
const Standard_Boolean theIsD3dEx,
const Standard_Integer theSizeX,
- const Standard_Integer theSizeY);
+ const Standard_Integer theSizeY,
+ const GLint theDepthFormat);
//! Initializes OpenGL FBO + Direct3D surface for copying memory using fallback.
+ //! Color pixel format is always GL_RGBA8/D3DFMT_X8R8G8B8, no MSAA.
+ //! @param theGlCtx currently bound OpenGL context
+ //! @param theD3DDevice d3d9 device
+ //! @param theIsD3dEx d3d9 extended flag (for creating shared texture resource)
+ //! @param theSizeX texture width
+ //! @param theSizeY texture height
+ //! @param theDepthFormat depth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
+ //! @return true on success
Standard_EXPORT Standard_Boolean InitD3dFallback (const Handle(OpenGl_Context)& theCtx,
IDirect3DDevice9* theD3DDevice,
const Standard_Boolean theIsD3dEx,
const Standard_Integer theSizeX,
- const Standard_Integer theSizeY);
+ const Standard_Integer theSizeY,
+ const GLint theDepthFormat);
//! Binds Direct3D color buffer to OpenGL texture.
Standard_EXPORT Standard_Boolean registerD3dBuffer (const Handle(OpenGl_Context)& theCtx);
myD3dDevice,
myIsD3dEx,
myWindow->Width(),
- myWindow->Height());
+ myWindow->Height(),
+ 0); // do not request depth-stencil attachment since buffer will be flipped using addition FBO (myToFlipOutput)
}
if (toD3dFallback)
{
myD3dDevice,
myIsD3dEx,
myWindow->Width(),
- myWindow->Height()))
+ myWindow->Height(),
+ GL_DEPTH24_STENCIL8))
{
return false;
}
namespace
{
+ //! Checks whether two format arrays are equal or not.
+ static bool operator== (const OpenGl_ColorFormats& theFmt1,
+ const OpenGl_ColorFormats& theFmt2)
+ {
+ if (theFmt1.Length() != theFmt2.Length())
+ return false;
+ OpenGl_ColorFormats::Iterator anIt1 (theFmt1);
+ OpenGl_ColorFormats::Iterator anIt2 (theFmt1);
+ for (; anIt1.More(); anIt1.Next(), anIt2.Next())
+ {
+ if (anIt1.Value() != anIt2.Value())
+ return false;
+ }
+ return true;
+ }
+}
- //! Determine data type from texture sized format.
- static bool getDepthDataFormat (GLint theTextFormat,
- GLenum& thePixelFormat,
- GLenum& theDataType)
+// =======================================================================
+// function : getDepthDataFormat
+// purpose :
+// =======================================================================
+bool OpenGl_FrameBuffer::getDepthDataFormat (GLint theTextFormat,
+ GLenum& thePixelFormat,
+ GLenum& theDataType)
+{
+ switch (theTextFormat)
{
- switch (theTextFormat)
+ case GL_DEPTH24_STENCIL8:
{
- case GL_DEPTH24_STENCIL8:
- {
- thePixelFormat = GL_DEPTH_STENCIL;
- theDataType = GL_UNSIGNED_INT_24_8;
- return true;
- }
- case GL_DEPTH32F_STENCIL8:
- {
- thePixelFormat = GL_DEPTH_STENCIL;
- theDataType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
- return true;
- }
- case GL_DEPTH_COMPONENT16:
- {
- thePixelFormat = GL_DEPTH_COMPONENT;
- theDataType = GL_UNSIGNED_SHORT;
- return true;
- }
- case GL_DEPTH_COMPONENT24:
- {
- thePixelFormat = GL_DEPTH_COMPONENT;
- theDataType = GL_UNSIGNED_INT;
- return true;
- }
- case GL_DEPTH_COMPONENT32F:
- {
- thePixelFormat = GL_DEPTH_COMPONENT;
- theDataType = GL_FLOAT;
- return true;
- }
+ thePixelFormat = GL_DEPTH_STENCIL;
+ theDataType = GL_UNSIGNED_INT_24_8;
+ return true;
+ }
+ case GL_DEPTH32F_STENCIL8:
+ {
+ thePixelFormat = GL_DEPTH_STENCIL;
+ theDataType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
+ return true;
+ }
+ case GL_DEPTH_COMPONENT16:
+ {
+ thePixelFormat = GL_DEPTH_COMPONENT;
+ theDataType = GL_UNSIGNED_SHORT;
+ return true;
+ }
+ case GL_DEPTH_COMPONENT24:
+ {
+ thePixelFormat = GL_DEPTH_COMPONENT;
+ theDataType = GL_UNSIGNED_INT;
+ return true;
+ }
+ case GL_DEPTH_COMPONENT32F:
+ {
+ thePixelFormat = GL_DEPTH_COMPONENT;
+ theDataType = GL_FLOAT;
+ return true;
}
- return false;
}
+ return false;
+}
- //! Determine data type from texture sized format.
- static bool getColorDataFormat (const Handle(OpenGl_Context)& theGlContext,
- GLint theTextFormat,
- GLenum& thePixelFormat,
- GLenum& theDataType)
+// =======================================================================
+// function : getColorDataFormat
+// purpose :
+// =======================================================================
+bool OpenGl_FrameBuffer::getColorDataFormat (const Handle(OpenGl_Context)& theGlContext,
+ GLint theTextFormat,
+ GLenum& thePixelFormat,
+ GLenum& theDataType)
+{
+ switch (theTextFormat)
{
- switch (theTextFormat)
+ case GL_RGBA32F:
{
- case GL_RGBA32F:
- {
- thePixelFormat = GL_RGBA;
- theDataType = GL_FLOAT;
- return true;
- }
- case GL_R32F:
- {
- thePixelFormat = GL_RED;
- theDataType = GL_FLOAT;
- return true;
- }
- case GL_RGBA16F:
- {
- thePixelFormat = GL_RGBA;
- theDataType = GL_HALF_FLOAT;
- if (theGlContext->hasHalfFloatBuffer == OpenGl_FeatureInExtensions)
- {
- #if defined(GL_ES_VERSION_2_0)
- theDataType = GL_HALF_FLOAT_OES;
- #else
- theDataType = GL_FLOAT;
- #endif
- }
- return true;
- }
- case GL_R16F:
- {
- thePixelFormat = GL_RED;
- theDataType = GL_HALF_FLOAT;
- if (theGlContext->hasHalfFloatBuffer == OpenGl_FeatureInExtensions)
- {
- #if defined(GL_ES_VERSION_2_0)
- theDataType = GL_HALF_FLOAT_OES;
- #else
- theDataType = GL_FLOAT;
- #endif
- }
- return true;
- }
- case GL_RGBA8:
- case GL_RGBA:
+ thePixelFormat = GL_RGBA;
+ theDataType = GL_FLOAT;
+ return true;
+ }
+ case GL_R32F:
+ {
+ thePixelFormat = GL_RED;
+ theDataType = GL_FLOAT;
+ return true;
+ }
+ case GL_RGBA16F:
+ {
+ thePixelFormat = GL_RGBA;
+ theDataType = GL_HALF_FLOAT;
+ if (theGlContext->hasHalfFloatBuffer == OpenGl_FeatureInExtensions)
{
- thePixelFormat = GL_RGBA;
- theDataType = GL_UNSIGNED_BYTE;
- return true;
+ #if defined(GL_ES_VERSION_2_0)
+ theDataType = GL_HALF_FLOAT_OES;
+ #else
+ theDataType = GL_FLOAT;
+ #endif
}
- case GL_RGB8:
- case GL_RGB:
+ return true;
+ }
+ case GL_R16F:
+ {
+ thePixelFormat = GL_RED;
+ theDataType = GL_HALF_FLOAT;
+ if (theGlContext->hasHalfFloatBuffer == OpenGl_FeatureInExtensions)
{
- thePixelFormat = GL_RGB;
- theDataType = GL_UNSIGNED_BYTE;
- return true;
+ #if defined(GL_ES_VERSION_2_0)
+ theDataType = GL_HALF_FLOAT_OES;
+ #else
+ theDataType = GL_FLOAT;
+ #endif
}
+ return true;
}
- return false;
- }
-
- //! Checks whether two format arrays are equal or not.
- static bool operator== (const OpenGl_ColorFormats& theFmt1,
- const OpenGl_ColorFormats& theFmt2)
- {
- if (theFmt1.Length() != theFmt2.Length())
- return false;
- OpenGl_ColorFormats::Iterator anIt1 (theFmt1);
- OpenGl_ColorFormats::Iterator anIt2 (theFmt1);
- for (; anIt1.More(); anIt1.Next(), anIt2.Next())
+ case GL_RGBA8:
+ case GL_RGBA:
{
- if (anIt1.Value() != anIt2.Value())
- return false;
+ thePixelFormat = GL_RGBA;
+ theDataType = GL_UNSIGNED_BYTE;
+ return true;
+ }
+ case GL_RGB8:
+ case GL_RGB:
+ {
+ thePixelFormat = GL_RGB;
+ theDataType = GL_UNSIGNED_BYTE;
+ return true;
}
- return true;
}
+ return false;
}
// =======================================================================
return myGlFBufferId != NO_FRAMEBUFFER;
}
+protected:
+
+ //! Determine data type from texture sized format.
+ Standard_EXPORT static bool getDepthDataFormat (GLint theTextFormat,
+ GLenum& thePixelFormat,
+ GLenum& theDataType);
+
+ //! Determine data type from texture sized format.
+ Standard_EXPORT static bool getColorDataFormat (const Handle(OpenGl_Context)& theCtx,
+ GLint theTextFormat,
+ GLenum& thePixelFormat,
+ GLenum& theDataType);
+
protected:
typedef NCollection_Vector<Handle(OpenGl_Texture)> OpenGl_TextureArray;