1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-08 14:17:06 +03:00

0029346: Visualization, TKOpenGl - collect frame statistics

Graphic3d_RenderingParams::ToShowStats - new option displaying rendering statistics.

OpenGl_FrameStats - new class for accumulating frame statistics.
OpenGl_Context::FrameStats() provides an access to the frame stats
used for currently rendered context.
OpenGl_View::Redraw() and OpenGl_View::RedrawImmediate()
resets counters within OpenGl_Context::FrameStats().

OpenGl_Layer::UpdateCulling() - simplified resetting of culling state for cullable structures.
This commit is contained in:
kgv
2017-11-24 18:43:01 +03:00
committed by bugmaster
parent ab3ff92cc0
commit 15669413da
36 changed files with 1449 additions and 107 deletions

View File

@@ -60,6 +60,8 @@ OpenGl_Texture::OpenGl_Texture (const TCollection_AsciiString& theResourceId,
mySizeY (0),
mySizeZ (0),
myTextFormat (GL_RGBA),
mySizedFormat(GL_RGBA8),
myNbSamples (1),
myHasMipmaps (Standard_False),
myIsAlpha (false)
{
@@ -433,6 +435,8 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
myHasMipmaps = toCreateMipMaps;
myTextFormat = thePixelFormat;
mySizedFormat = theTextFormat;
myNbSamples = 1;
#if !defined(GL_ES_VERSION_2_0)
const GLint anIntFormat = theTextFormat;
#else
@@ -546,6 +550,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
theSizeX, 0,
thePixelFormat, theDataType, NULL);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
if (aTestWidth == 0)
{
// no memory or broken input parameters
@@ -597,6 +602,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
thePixelFormat, theDataType, NULL);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
if (aTestWidth == 0 || aTestHeight == 0)
{
// no memory or broken input parameters
@@ -660,6 +666,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
thePixelFormat, theDataType, NULL);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
if (aTestWidth == 0 || aTestHeight == 0)
{
// no memory or broken input parameters
@@ -768,8 +775,9 @@ bool OpenGl_Texture::Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
return false;
}
const GLsizei aNbSamples = OpenGl_Context::GetPowerOfTwo (theNbSamples, theCtx->MaxMsaaSamples());
myNbSamples = OpenGl_Context::GetPowerOfTwo (theNbSamples, theCtx->MaxMsaaSamples());
myTarget = GL_TEXTURE_2D_MULTISAMPLE;
myHasMipmaps = false;
if(theSizeX > theCtx->MaxTextureSize()
|| theSizeY > theCtx->MaxTextureSize())
{
@@ -778,17 +786,18 @@ bool OpenGl_Texture::Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
Bind (theCtx);
//myTextFormat = theTextFormat;
mySizedFormat = theTextFormat;
#if !defined(GL_ES_VERSION_2_0)
if (theCtx->Functions()->glTexStorage2DMultisample != NULL)
{
theCtx->Functions()->glTexStorage2DMultisample (myTarget, aNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
theCtx->Functions()->glTexStorage2DMultisample (myTarget, myNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
}
else
{
theCtx->Functions()->glTexImage2DMultisample (myTarget, aNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
theCtx->Functions()->glTexImage2DMultisample (myTarget, myNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
}
#else
theCtx->Functions() ->glTexStorage2DMultisample (myTarget, aNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
theCtx->Functions() ->glTexStorage2DMultisample (myTarget, myNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
#endif
if (theCtx->core11fwd->glGetError() != GL_NO_ERROR)
{
@@ -819,6 +828,8 @@ bool OpenGl_Texture::InitRectangle (const Handle(OpenGl_Context)& theCtx,
#if !defined(GL_ES_VERSION_2_0)
myTarget = GL_TEXTURE_RECTANGLE;
myNbSamples = 1;
myHasMipmaps = false;
const GLsizei aSizeX = Min (theCtx->MaxTextureSize(), theSizeX);
const GLsizei aSizeY = Min (theCtx->MaxTextureSize(), theSizeY);
@@ -826,26 +837,19 @@ bool OpenGl_Texture::InitRectangle (const Handle(OpenGl_Context)& theCtx,
Bind (theCtx);
applyDefaultSamplerParams (theCtx);
const GLint anIntFormat = theFormat.Internal();
myTextFormat = theFormat.Format();
myTextFormat = theFormat.Format();
mySizedFormat = theFormat.Internal();
glTexImage2D (GL_PROXY_TEXTURE_RECTANGLE,
0,
anIntFormat,
aSizeX,
aSizeY,
0,
theFormat.Format(),
GL_FLOAT,
NULL);
glTexImage2D (GL_PROXY_TEXTURE_RECTANGLE, 0, mySizedFormat,
aSizeX, aSizeY, 0,
myTextFormat, GL_FLOAT, NULL);
GLint aTestSizeX = 0;
GLint aTestSizeY = 0;
glGetTexLevelParameteriv (
GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_WIDTH, &aTestSizeX);
glGetTexLevelParameteriv (
GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_HEIGHT, &aTestSizeY);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_WIDTH, &aTestSizeX);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_HEIGHT, &aTestSizeY);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
if (aTestSizeX == 0 || aTestSizeY == 0)
{
@@ -853,15 +857,9 @@ bool OpenGl_Texture::InitRectangle (const Handle(OpenGl_Context)& theCtx,
return false;
}
glTexImage2D (myTarget,
0,
anIntFormat,
aSizeX,
aSizeY,
0,
theFormat.Format(),
GL_FLOAT,
NULL);
glTexImage2D (myTarget, 0, mySizedFormat,
aSizeX, aSizeY, 0,
myTextFormat, GL_FLOAT, NULL);
if (glGetError() != GL_NO_ERROR)
{
@@ -914,6 +912,8 @@ bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
}
myTarget = GL_TEXTURE_3D;
myNbSamples = 1;
myHasMipmaps = false;
const GLsizei aSizeX = Min (theCtx->MaxTextureSize(), theSizeX);
const GLsizei aSizeY = Min (theCtx->MaxTextureSize(), theSizeY);
@@ -936,19 +936,12 @@ bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
return false;
}
const GLint anIntFormat = theTextFormat;
mySizedFormat = theTextFormat;
#if !defined (GL_ES_VERSION_2_0)
theCtx->core15fwd->glTexImage3D (GL_PROXY_TEXTURE_3D,
0,
anIntFormat,
aSizeX,
aSizeY,
aSizeZ,
0,
thePixelFormat,
theDataType,
NULL);
theCtx->core15fwd->glTexImage3D (GL_PROXY_TEXTURE_3D, 0, mySizedFormat,
aSizeX, aSizeY, aSizeZ, 0,
thePixelFormat, theDataType, NULL);
GLint aTestSizeX = 0;
GLint aTestSizeY = 0;
@@ -957,6 +950,7 @@ bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &aTestSizeX);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_HEIGHT, &aTestSizeY);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_DEPTH, &aTestSizeZ);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
if (aTestSizeX == 0 || aTestSizeY == 0 || aTestSizeZ == 0)
{
@@ -967,16 +961,9 @@ bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
#endif
applyDefaultSamplerParams (theCtx);
theCtx->Functions()->glTexImage3D (myTarget,
0,
anIntFormat,
aSizeX,
aSizeY,
aSizeZ,
0,
thePixelFormat,
theDataType,
thePixels);
theCtx->Functions()->glTexImage3D (myTarget, 0, mySizedFormat,
aSizeX, aSizeY, aSizeZ, 0,
thePixelFormat, theDataType, thePixels);
if (glGetError() != GL_NO_ERROR)
{
@@ -992,3 +979,76 @@ bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
Unbind (theCtx);
return true;
}
// =======================================================================
// function : PixelSizeOfPixelFormat
// purpose :
// =======================================================================
Standard_Size OpenGl_Texture::PixelSizeOfPixelFormat (Standard_Integer theInternalFormat)
{
switch(theInternalFormat)
{
// RED variations (GL_RED, OpenGL 3.0+)
case GL_RED:
case GL_R8: return 1;
case GL_R16: return 2;
case GL_R16F: return 2;
case GL_R32F: return 4;
// RGB variations
case GL_RGB: return 3;
case GL_RGB8: return 3;
case GL_RGB16: return 6;
case GL_RGB16F: return 6;
case GL_RGB32F: return 12;
// RGBA variations
case GL_RGBA: return 4;
case GL_RGBA8: return 4;
case GL_RGB10_A2: return 4;
case GL_RGBA12: return 6;
case GL_RGBA16: return 8;
case GL_RGBA16F: return 8;
case GL_RGBA32F: return 16;
//
case GL_BGRA_EXT: return 4;
// ALPHA variations (deprecated)
case GL_ALPHA:
case GL_ALPHA8: return 1;
case GL_ALPHA16: return 2;
case GL_LUMINANCE: return 1;
case GL_LUMINANCE_ALPHA: return 2;
// depth-stencil
case GL_DEPTH24_STENCIL8: return 4;
case GL_DEPTH32F_STENCIL8: return 8;
case GL_DEPTH_COMPONENT16: return 2;
case GL_DEPTH_COMPONENT24: return 3;
case GL_DEPTH_COMPONENT32F: return 4;
}
return 0;
}
// =======================================================================
// function : EstimatedDataSize
// purpose :
// =======================================================================
Standard_Size OpenGl_Texture::EstimatedDataSize() const
{
if (!IsValid())
{
return 0;
}
Standard_Size aSize = PixelSizeOfPixelFormat (mySizedFormat) * mySizeX * myNbSamples;
if (mySizeY != 0)
{
aSize *= Standard_Size(mySizeY);
}
if (mySizeZ != 0)
{
aSize *= Standard_Size(mySizeZ);
}
if (myHasMipmaps)
{
aSize = aSize + aSize / 3;
}
return aSize;
}