mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-21 10:13:43 +03:00
0032349: Visualization, TKOpenGl - move base buffer interface out from OpenGl_VertexBuffer class to OpenGl_Buffer
OpenGl_Buffer - added new class as a base for OpenGl_VertexBuffer, OpenGl_IndexBuffer, OpenGl_TextureBuffer. OpenGl_TextureBufferArb has been renamed to OpenGl_TextureBuffer. OpenGl_FrameBuffer - added initializers taking vec2i instead of (int,int) for dimensions.
This commit is contained in:
parent
11bbf75932
commit
1220d98e7a
@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
#include <OpenGl_GlCore20.hxx>
|
#include <OpenGl_GlCore20.hxx>
|
||||||
#include <OpenGl_ArbFBO.hxx>
|
#include <OpenGl_ArbFBO.hxx>
|
||||||
|
#include <OpenGl_Context.hxx>
|
||||||
|
#include <OpenGl_Texture.hxx>
|
||||||
#include <Standard_ProgramError.hxx>
|
#include <Standard_ProgramError.hxx>
|
||||||
#include <TCollection_ExtendedString.hxx>
|
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(D3DHost_FrameBuffer,OpenGl_FrameBuffer)
|
IMPLEMENT_STANDARD_RTTIEXT(D3DHost_FrameBuffer,OpenGl_FrameBuffer)
|
||||||
|
|
||||||
@ -114,9 +115,9 @@ Standard_Boolean D3DHost_FrameBuffer::InitD3dFallback (const Handle(OpenGl_Conte
|
|||||||
const Standard_Boolean theIsD3dEx,
|
const Standard_Boolean theIsD3dEx,
|
||||||
const Standard_Integer theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const Standard_Integer theSizeY,
|
const Standard_Integer theSizeY,
|
||||||
const GLint theDepthFormat)
|
const Standard_Integer theDepthFormat)
|
||||||
{
|
{
|
||||||
const Standard_Boolean isGlInit = OpenGl_FrameBuffer::Init (theCtx, theSizeX, theSizeY, GL_RGBA8, theDepthFormat, 0);
|
const Standard_Boolean isGlInit = OpenGl_FrameBuffer::Init (theCtx, Graphic3d_Vec2i (theSizeX, theSizeY), GL_RGBA8, theDepthFormat, 0);
|
||||||
myD3dFallback = Standard_True;
|
myD3dFallback = Standard_True;
|
||||||
|
|
||||||
const Standard_Integer aSizeX = theSizeX > 0 ? theSizeX : 2;
|
const Standard_Integer aSizeX = theSizeX > 0 ? theSizeX : 2;
|
||||||
@ -142,7 +143,7 @@ Standard_Boolean D3DHost_FrameBuffer::InitD3dInterop (const Handle(OpenGl_Contex
|
|||||||
const Standard_Boolean theIsD3dEx,
|
const Standard_Boolean theIsD3dEx,
|
||||||
const Standard_Integer theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const Standard_Integer theSizeY,
|
const Standard_Integer theSizeY,
|
||||||
const GLint theDepthFormat)
|
const Standard_Integer theDepthFormat)
|
||||||
{
|
{
|
||||||
Release (theCtx.operator->());
|
Release (theCtx.operator->());
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
|
@ -63,7 +63,7 @@ public:
|
|||||||
const Standard_Boolean theIsD3dEx,
|
const Standard_Boolean theIsD3dEx,
|
||||||
const Standard_Integer theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const Standard_Integer theSizeY,
|
const Standard_Integer theSizeY,
|
||||||
const GLint theDepthFormat);
|
const Standard_Integer theDepthFormat);
|
||||||
|
|
||||||
//! Initializes OpenGL FBO + Direct3D surface for copying memory using fallback.
|
//! Initializes OpenGL FBO + Direct3D surface for copying memory using fallback.
|
||||||
//! Color pixel format is always GL_RGBA8/D3DFMT_X8R8G8B8, no MSAA.
|
//! Color pixel format is always GL_RGBA8/D3DFMT_X8R8G8B8, no MSAA.
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
const Standard_Boolean theIsD3dEx,
|
const Standard_Boolean theIsD3dEx,
|
||||||
const Standard_Integer theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const Standard_Integer theSizeY,
|
const Standard_Integer theSizeY,
|
||||||
const GLint theDepthFormat);
|
const Standard_Integer theDepthFormat);
|
||||||
|
|
||||||
//! Binds Direct3D color buffer to OpenGL texture.
|
//! Binds Direct3D color buffer to OpenGL texture.
|
||||||
Standard_EXPORT Standard_Boolean registerD3dBuffer (const Handle(OpenGl_Context)& theCtx);
|
Standard_EXPORT Standard_Boolean registerD3dBuffer (const Handle(OpenGl_Context)& theCtx);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <D3DHost_GraphicDriver.hxx>
|
#include <D3DHost_GraphicDriver.hxx>
|
||||||
#include <TCollection_ExtendedString.hxx>
|
#include <TCollection_ExtendedString.hxx>
|
||||||
|
#include <OpenGl_Window.hxx>
|
||||||
|
|
||||||
#include <Standard_WarningDisableFunctionCast.hxx>
|
#include <Standard_WarningDisableFunctionCast.hxx>
|
||||||
|
|
||||||
|
@ -14,6 +14,9 @@ OpenGl_AspectsSprite.cxx
|
|||||||
OpenGl_AspectsSprite.hxx
|
OpenGl_AspectsSprite.hxx
|
||||||
OpenGl_AspectsTextureSet.cxx
|
OpenGl_AspectsTextureSet.cxx
|
||||||
OpenGl_AspectsTextureSet.hxx
|
OpenGl_AspectsTextureSet.hxx
|
||||||
|
OpenGl_Buffer.cxx
|
||||||
|
OpenGl_Buffer.hxx
|
||||||
|
OpenGl_BufferCompatT.hxx
|
||||||
OpenGl_FrameStats.cxx
|
OpenGl_FrameStats.cxx
|
||||||
OpenGl_FrameStats.hxx
|
OpenGl_FrameStats.hxx
|
||||||
OpenGl_FrameStatsPrs.cxx
|
OpenGl_FrameStatsPrs.cxx
|
||||||
@ -134,13 +137,14 @@ OpenGl_StencilTest.cxx
|
|||||||
OpenGl_StencilTest.hxx
|
OpenGl_StencilTest.hxx
|
||||||
OpenGl_TileSampler.hxx
|
OpenGl_TileSampler.hxx
|
||||||
OpenGl_TileSampler.cxx
|
OpenGl_TileSampler.cxx
|
||||||
OpenGl_TextureBufferArb.cxx
|
OpenGl_TextureBuffer.cxx
|
||||||
|
OpenGl_TextureBuffer.hxx
|
||||||
OpenGl_TextureBufferArb.hxx
|
OpenGl_TextureBufferArb.hxx
|
||||||
|
OpenGl_UniformBuffer.cxx
|
||||||
|
OpenGl_UniformBuffer.hxx
|
||||||
OpenGl_Vec.hxx
|
OpenGl_Vec.hxx
|
||||||
OpenGl_VertexBuffer.cxx
|
OpenGl_VertexBuffer.cxx
|
||||||
OpenGl_VertexBuffer.hxx
|
OpenGl_VertexBuffer.hxx
|
||||||
OpenGl_VertexBuffer.lxx
|
|
||||||
OpenGl_VertexBufferCompat.cxx
|
|
||||||
OpenGl_VertexBufferCompat.hxx
|
OpenGl_VertexBufferCompat.hxx
|
||||||
OpenGl_VertexBufferEditor.hxx
|
OpenGl_VertexBufferEditor.hxx
|
||||||
OpenGl_TextBuilder.hxx
|
OpenGl_TextBuilder.hxx
|
||||||
|
@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
#include <Aspect_GradientFillMethod.hxx>
|
#include <Aspect_GradientFillMethod.hxx>
|
||||||
#include <Aspect_FillMethod.hxx>
|
#include <Aspect_FillMethod.hxx>
|
||||||
|
#include <Graphic3d_Camera.hxx>
|
||||||
#include <Graphic3d_TypeOfBackground.hxx>
|
#include <Graphic3d_TypeOfBackground.hxx>
|
||||||
#include <OpenGl_Aspects.hxx>
|
#include <OpenGl_Aspects.hxx>
|
||||||
#include <OpenGl_PrimitiveArray.hxx>
|
#include <OpenGl_PrimitiveArray.hxx>
|
||||||
#include <OpenGl_Vec.hxx>
|
#include <OpenGl_Vec.hxx>
|
||||||
#include <OpenGl_Workspace.hxx>
|
|
||||||
|
|
||||||
//! Tool class for generating reusable data for
|
//! Tool class for generating reusable data for
|
||||||
//! gradient or texture background rendering.
|
//! gradient or texture background rendering.
|
||||||
|
446
src/OpenGl/OpenGl_Buffer.cxx
Normal file
446
src/OpenGl/OpenGl_Buffer.cxx
Normal file
@ -0,0 +1,446 @@
|
|||||||
|
// Created by: Kirill GAVRILOV
|
||||||
|
// Copyright (c) 2013-2014 OPEN CASCADE SAS
|
||||||
|
//
|
||||||
|
// This file is part of Open CASCADE Technology software library.
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||||
|
// by the Free Software Foundation, with special exception defined in the file
|
||||||
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||||
|
// distribution for complete text of the license and disclaimer of any warranty.
|
||||||
|
//
|
||||||
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
|
#include <OpenGl_Buffer.hxx>
|
||||||
|
|
||||||
|
#include <OpenGl_GlCore30.hxx>
|
||||||
|
#include <OpenGl_Context.hxx>
|
||||||
|
#include <OpenGl_ShaderManager.hxx>
|
||||||
|
#include <Standard_Assert.hxx>
|
||||||
|
|
||||||
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Buffer, OpenGl_Resource)
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : sizeOfGlType
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
size_t OpenGl_Buffer::sizeOfGlType (unsigned int theType)
|
||||||
|
{
|
||||||
|
switch (theType)
|
||||||
|
{
|
||||||
|
case GL_BYTE:
|
||||||
|
case GL_UNSIGNED_BYTE: return sizeof(Standard_Byte);
|
||||||
|
case GL_SHORT:
|
||||||
|
case GL_UNSIGNED_SHORT: return sizeof(unsigned short);
|
||||||
|
#ifdef GL_INT
|
||||||
|
case GL_INT:
|
||||||
|
#endif
|
||||||
|
case GL_UNSIGNED_INT: return sizeof(unsigned int);
|
||||||
|
case GL_FLOAT: return sizeof(float);
|
||||||
|
#ifdef GL_DOUBLE
|
||||||
|
case GL_DOUBLE: return sizeof(double);
|
||||||
|
#endif
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : FormatTarget
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
TCollection_AsciiString OpenGl_Buffer::FormatTarget (unsigned int theTarget)
|
||||||
|
{
|
||||||
|
switch (theTarget)
|
||||||
|
{
|
||||||
|
case GL_ARRAY_BUFFER: return "GL_ARRAY_BUFFER";
|
||||||
|
case GL_ELEMENT_ARRAY_BUFFER: return "GL_ELEMENT_ARRAY_BUFFER";
|
||||||
|
case GL_PIXEL_UNPACK_BUFFER: return "GL_PIXEL_UNPACK_BUFFER";
|
||||||
|
case GL_PIXEL_PACK_BUFFER: return "GL_PIXEL_PACK_BUFFER";
|
||||||
|
case GL_UNIFORM_BUFFER: return "GL_UNIFORM_BUFFER";
|
||||||
|
case GL_TEXTURE_BUFFER: return "GL_TEXTURE_BUFFER";
|
||||||
|
case GL_COPY_READ_BUFFER: return "GL_COPY_READ_BUFFER";
|
||||||
|
case GL_COPY_WRITE_BUFFER: return "GL_COPY_WRITE_BUFFER";
|
||||||
|
case GL_TRANSFORM_FEEDBACK_BUFFER: return "GL_TRANSFORM_FEEDBACK_BUFFER";
|
||||||
|
#ifdef GL_QUERY_BUFFER
|
||||||
|
case GL_QUERY_BUFFER: return "GL_QUERY_BUFFER";
|
||||||
|
case GL_DRAW_INDIRECT_BUFFER: return "GL_DRAW_INDIRECT_BUFFER";
|
||||||
|
case GL_ATOMIC_COUNTER_BUFFER: return "GL_ATOMIC_COUNTER_BUFFER";
|
||||||
|
case GL_DISPATCH_INDIRECT_BUFFER: return "GL_DISPATCH_INDIRECT_BUFFER";
|
||||||
|
case GL_SHADER_STORAGE_BUFFER: return "GL_SHADER_STORAGE_BUFFER";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return OpenGl_Context::FormatGlEnumHex (theTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : OpenGl_Buffer
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
OpenGl_Buffer::OpenGl_Buffer()
|
||||||
|
: OpenGl_Resource(),
|
||||||
|
myOffset (NULL),
|
||||||
|
myBufferId (NO_BUFFER),
|
||||||
|
myComponentsNb (4),
|
||||||
|
myElemsNb (0),
|
||||||
|
myDataType (GL_FLOAT)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : ~OpenGl_Buffer
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
OpenGl_Buffer::~OpenGl_Buffer()
|
||||||
|
{
|
||||||
|
Release (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Create
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::Create (const Handle(OpenGl_Context)& theGlCtx)
|
||||||
|
{
|
||||||
|
if (myBufferId == NO_BUFFER && theGlCtx->core15fwd != NULL)
|
||||||
|
{
|
||||||
|
theGlCtx->core15fwd->glGenBuffers (1, &myBufferId);
|
||||||
|
}
|
||||||
|
return myBufferId != NO_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Release
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_Buffer::Release (OpenGl_Context* theGlCtx)
|
||||||
|
{
|
||||||
|
if (myBufferId == NO_BUFFER)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// application can not handle this case by exception - this is bug in code
|
||||||
|
Standard_ASSERT_RETURN (theGlCtx != NULL,
|
||||||
|
"OpenGl_Buffer destroyed without GL context! Possible GPU memory leakage...",);
|
||||||
|
|
||||||
|
if (theGlCtx->IsValid())
|
||||||
|
{
|
||||||
|
theGlCtx->core15fwd->glDeleteBuffers (1, &myBufferId);
|
||||||
|
}
|
||||||
|
myOffset = NULL;
|
||||||
|
myBufferId = NO_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Bind
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_Buffer::Bind (const Handle(OpenGl_Context)& theGlCtx) const
|
||||||
|
{
|
||||||
|
theGlCtx->core15fwd->glBindBuffer (GetTarget(), myBufferId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Unbind
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_Buffer::Unbind (const Handle(OpenGl_Context)& theGlCtx) const
|
||||||
|
{
|
||||||
|
theGlCtx->core15fwd->glBindBuffer (GetTarget(), NO_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : BindBufferBase
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_Buffer::BindBufferBase (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
unsigned int theIndex)
|
||||||
|
{
|
||||||
|
theGlCtx->core30->glBindBufferBase (GetTarget(), theIndex, myBufferId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : UnbindBufferBase
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_Buffer::UnbindBufferBase (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
unsigned int theIndex)
|
||||||
|
{
|
||||||
|
theGlCtx->core30->glBindBufferBase (GetTarget(), theIndex, NO_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : BindBufferRange
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_Buffer::BindBufferRange (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
unsigned int theIndex,
|
||||||
|
const intptr_t theOffset,
|
||||||
|
const size_t theSize)
|
||||||
|
{
|
||||||
|
theGlCtx->core30->glBindBufferRange (GetTarget(), theIndex, myBufferId, (GLintptr )theOffset, (GLsizeiptr )theSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Init
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const float* theData)
|
||||||
|
{
|
||||||
|
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Init
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned int* theData)
|
||||||
|
{
|
||||||
|
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_UNSIGNED_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Init
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned short* theData)
|
||||||
|
{
|
||||||
|
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_UNSIGNED_SHORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Init
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const Standard_Byte* theData)
|
||||||
|
{
|
||||||
|
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_UNSIGNED_BYTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : init
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType,
|
||||||
|
const Standard_Integer theStride)
|
||||||
|
{
|
||||||
|
if (!Create (theGlCtx))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bind (theGlCtx);
|
||||||
|
myDataType = theDataType;
|
||||||
|
myComponentsNb = theComponentsNb;
|
||||||
|
myElemsNb = theElemsNb;
|
||||||
|
theGlCtx->core15fwd->glBufferData (GetTarget(), GLsizeiptr(myElemsNb) * theStride, theData, GL_STATIC_DRAW);
|
||||||
|
const int anErr = theGlCtx->core15fwd->glGetError();
|
||||||
|
if (anErr != GL_NO_ERROR
|
||||||
|
&& anErr != GL_OUT_OF_MEMORY) // pass-through out-of-memory error, but log unexpected errors
|
||||||
|
{
|
||||||
|
theGlCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
|
||||||
|
TCollection_AsciiString ("Error: glBufferData (")
|
||||||
|
+ FormatTarget (GetTarget()) + ","
|
||||||
|
+ OpenGl_Context::FormatSize (GLsizeiptr(myElemsNb) * theStride) + ","
|
||||||
|
+ OpenGl_Context::FormatPointer (theData) + ") Id: " + (int )myBufferId
|
||||||
|
+ " failed with " + OpenGl_Context::FormatGlError (anErr));
|
||||||
|
}
|
||||||
|
Unbind (theGlCtx);
|
||||||
|
return anErr == GL_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : SubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const float* theData)
|
||||||
|
{
|
||||||
|
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : SubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned int* theData)
|
||||||
|
{
|
||||||
|
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : SubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned short* theData)
|
||||||
|
{
|
||||||
|
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_SHORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : SubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const Standard_Byte* theData)
|
||||||
|
{
|
||||||
|
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_BYTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : subData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::subData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType)
|
||||||
|
{
|
||||||
|
if (!IsValid() || myDataType != theDataType ||
|
||||||
|
theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bind (theGlCtx);
|
||||||
|
const size_t aDataSize = sizeOfGlType (theDataType);
|
||||||
|
theGlCtx->core15fwd->glBufferSubData (GetTarget(),
|
||||||
|
GLintptr(theElemFrom) * GLintptr (myComponentsNb) * aDataSize, // offset in bytes
|
||||||
|
GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * aDataSize, // size in bytes
|
||||||
|
theData);
|
||||||
|
const int anErr = theGlCtx->core15fwd->glGetError();
|
||||||
|
if (anErr != GL_NO_ERROR)
|
||||||
|
{
|
||||||
|
theGlCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
|
||||||
|
TCollection_AsciiString ("Error: glBufferSubData (")
|
||||||
|
+ FormatTarget (GetTarget()) + ","
|
||||||
|
+ OpenGl_Context::FormatSize (GLintptr(theElemFrom) * GLintptr (myComponentsNb) * aDataSize) + ","
|
||||||
|
+ OpenGl_Context::FormatSize (GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * aDataSize) + ","
|
||||||
|
+ OpenGl_Context::FormatPointer (theData) + ") Id: " + (int )myBufferId
|
||||||
|
+ " failed with " + OpenGl_Context::FormatGlError (anErr));
|
||||||
|
}
|
||||||
|
Unbind (theGlCtx);
|
||||||
|
return anErr == GL_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : subData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
float* theData)
|
||||||
|
{
|
||||||
|
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : GetSubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
unsigned short* theData)
|
||||||
|
{
|
||||||
|
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_SHORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : GetSubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
unsigned int* theData)
|
||||||
|
{
|
||||||
|
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : GetSubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
Standard_Byte* theData)
|
||||||
|
{
|
||||||
|
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_BYTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : getSubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
bool OpenGl_Buffer::getSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
void* theData,
|
||||||
|
const unsigned int theDataType)
|
||||||
|
{
|
||||||
|
if (!IsValid() || myDataType != theDataType
|
||||||
|
|| theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb)
|
||||||
|
|| !theGlCtx->hasGetBufferData)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bind (theGlCtx);
|
||||||
|
const size_t aDataSize = sizeOfGlType (theDataType);
|
||||||
|
const GLintptr anOffset = GLintptr (theElemFrom) * GLintptr (myComponentsNb) * aDataSize;
|
||||||
|
const GLsizeiptr aSize = GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * aDataSize;
|
||||||
|
bool isDone = theGlCtx->GetBufferSubData (GetTarget(), anOffset, aSize, theData);
|
||||||
|
isDone = isDone && (theGlCtx->core15fwd->glGetError() == GL_NO_ERROR);
|
||||||
|
Unbind (theGlCtx);
|
||||||
|
return isDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : DumpJson
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_Buffer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
|
||||||
|
{
|
||||||
|
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
|
||||||
|
OCCT_DUMP_BASE_CLASS (theOStream, theDepth, OpenGl_Resource)
|
||||||
|
|
||||||
|
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, GetTarget())
|
||||||
|
OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myOffset)
|
||||||
|
|
||||||
|
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBufferId)
|
||||||
|
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComponentsNb)
|
||||||
|
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myElemsNb)
|
||||||
|
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDataType)
|
||||||
|
}
|
293
src/OpenGl/OpenGl_Buffer.hxx
Normal file
293
src/OpenGl/OpenGl_Buffer.hxx
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
// Created by: Kirill GAVRILOV
|
||||||
|
// Copyright (c) 2013-2014 OPEN CASCADE SAS
|
||||||
|
//
|
||||||
|
// This file is part of Open CASCADE Technology software library.
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||||
|
// by the Free Software Foundation, with special exception defined in the file
|
||||||
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||||
|
// distribution for complete text of the license and disclaimer of any warranty.
|
||||||
|
//
|
||||||
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
|
#ifndef _OpenGl_Buffer_H__
|
||||||
|
#define _OpenGl_Buffer_H__
|
||||||
|
|
||||||
|
#include <OpenGl_Resource.hxx>
|
||||||
|
#include <TCollection_AsciiString.hxx>
|
||||||
|
|
||||||
|
//! Buffer Object - is a general storage object for arbitrary data (see sub-classes).
|
||||||
|
class OpenGl_Buffer : public OpenGl_Resource
|
||||||
|
{
|
||||||
|
DEFINE_STANDARD_RTTIEXT(OpenGl_Buffer, OpenGl_Resource)
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Helpful constants
|
||||||
|
static const unsigned int NO_BUFFER = 0;
|
||||||
|
|
||||||
|
//! Format VBO target enumeration value.
|
||||||
|
Standard_EXPORT static TCollection_AsciiString FormatTarget (unsigned int theTarget);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Create uninitialized buffer.
|
||||||
|
Standard_EXPORT OpenGl_Buffer();
|
||||||
|
|
||||||
|
//! Destroy object.
|
||||||
|
Standard_EXPORT virtual ~OpenGl_Buffer();
|
||||||
|
|
||||||
|
//! Return buffer target.
|
||||||
|
virtual unsigned int GetTarget() const = 0;
|
||||||
|
|
||||||
|
//! Return TRUE if this is a virtual (for backward compatibility) VBO object.
|
||||||
|
virtual bool IsVirtual() const { return false; }
|
||||||
|
|
||||||
|
//! @return true if current object was initialized
|
||||||
|
bool IsValid() const { return myBufferId != NO_BUFFER; }
|
||||||
|
|
||||||
|
//! @return the number of components per generic vertex attribute.
|
||||||
|
unsigned int GetComponentsNb() const { return myComponentsNb; }
|
||||||
|
|
||||||
|
//! @return number of vertex attributes / number of vertices specified within ::Init()
|
||||||
|
Standard_Integer GetElemsNb() const { return myElemsNb; }
|
||||||
|
|
||||||
|
//! Overrides the number of vertex attributes / number of vertexes.
|
||||||
|
//! It is up to user specifying this number correct (e.g. below initial value)!
|
||||||
|
void SetElemsNb (Standard_Integer theNbElems) { myElemsNb = theNbElems; }
|
||||||
|
|
||||||
|
//! @return data type of each component in the array.
|
||||||
|
unsigned int GetDataType() const { return myDataType; }
|
||||||
|
|
||||||
|
//! @return offset to data, NULL by default
|
||||||
|
Standard_Byte* GetDataOffset() const { return myOffset; }
|
||||||
|
|
||||||
|
//! Creates buffer object name (id) if not yet generated.
|
||||||
|
//! Data should be initialized by another method.
|
||||||
|
Standard_EXPORT virtual bool Create (const Handle(OpenGl_Context)& theGlCtx);
|
||||||
|
|
||||||
|
//! Destroy object - will release GPU memory if any.
|
||||||
|
Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Bind this buffer object.
|
||||||
|
Standard_EXPORT virtual void Bind (const Handle(OpenGl_Context)& theGlCtx) const;
|
||||||
|
|
||||||
|
//! Unbind this buffer object.
|
||||||
|
Standard_EXPORT virtual void Unbind (const Handle(OpenGl_Context)& theGlCtx) const;
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! @param theComponentsNb [in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
||||||
|
//! @param theElemsNb [in] elements count;
|
||||||
|
//! @param theData [in] pointer to float data (vertices/normals etc.).
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const float* theData);
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! @param theComponentsNb [in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
||||||
|
//! @param theElemsNb [in] elements count;
|
||||||
|
//! @param theData [in] pointer to unsigned int data (indices etc.).
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned int* theData);
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! @param theComponentsNb [in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
||||||
|
//! @param theElemsNb [in] elements count;
|
||||||
|
//! @param theData [in] pointer to unsigned short data (indices etc.).
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned short* theData);
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! @param theComponentsNb [in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
||||||
|
//! @param theElemsNb [in] elements count;
|
||||||
|
//! @param theData [in] pointer to Standard_Byte data (indices/colors etc.).
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const Standard_Byte* theData);
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function replaces portion of data within this buffer object using glBufferSubData().
|
||||||
|
//! The buffer object should be initialized before call.
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [in] pointer to float data.
|
||||||
|
Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const float* theData);
|
||||||
|
|
||||||
|
//! Read back buffer sub-range.
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function reads portion of data from this buffer object using glGetBufferSubData().
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [out] destination pointer to float data.
|
||||||
|
Standard_EXPORT bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
float* theData);
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function replaces portion of data within this buffer object using glBufferSubData().
|
||||||
|
//! The buffer object should be initialized before call.
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [in] pointer to unsigned int data.
|
||||||
|
Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned int* theData);
|
||||||
|
|
||||||
|
//! Read back buffer sub-range.
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function reads portion of data from this buffer object using glGetBufferSubData().
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [out] destination pointer to unsigned int data.
|
||||||
|
Standard_EXPORT bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
unsigned int* theData);
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function replaces portion of data within this buffer object using glBufferSubData().
|
||||||
|
//! The buffer object should be initialized before call.
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [in] pointer to unsigned short data.
|
||||||
|
Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned short* theData);
|
||||||
|
|
||||||
|
//! Read back buffer sub-range.
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function reads portion of data from this buffer object using glGetBufferSubData().
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [out] destination pointer to unsigned short data.
|
||||||
|
Standard_EXPORT bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
unsigned short* theData);
|
||||||
|
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function replaces portion of data within this buffer object using glBufferSubData().
|
||||||
|
//! The buffer object should be initialized before call.
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [in] pointer to Standard_Byte data.
|
||||||
|
Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const Standard_Byte* theData);
|
||||||
|
|
||||||
|
//! Read back buffer sub-range.
|
||||||
|
//! Notice that buffer object will be unbound after this call.
|
||||||
|
//! Function reads portion of data from this buffer object using glGetBufferSubData().
|
||||||
|
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
||||||
|
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
||||||
|
//! @param theData [out] destination pointer to Standard_Byte data.
|
||||||
|
Standard_EXPORT bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
Standard_Byte* theData);
|
||||||
|
|
||||||
|
public: //! @name advanced methods
|
||||||
|
|
||||||
|
//! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
|
||||||
|
virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE
|
||||||
|
{
|
||||||
|
return IsValid()
|
||||||
|
? sizeOfGlType (myDataType) * myComponentsNb * myElemsNb
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @return size of specified GL type
|
||||||
|
Standard_EXPORT static size_t sizeOfGlType (unsigned int theType);
|
||||||
|
|
||||||
|
//! Initialize buffer with new data.
|
||||||
|
Standard_EXPORT virtual bool init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType,
|
||||||
|
const Standard_Integer theStride);
|
||||||
|
|
||||||
|
//! Initialize buffer with new data.
|
||||||
|
bool init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType)
|
||||||
|
{
|
||||||
|
return init (theGlCtx, theComponentsNb, theElemsNb, theData, theDataType,
|
||||||
|
Standard_Integer(theComponentsNb) * Standard_Integer(sizeOfGlType (theDataType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Update part of the buffer with new data.
|
||||||
|
Standard_EXPORT virtual bool subData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType);
|
||||||
|
|
||||||
|
//! Read back buffer sub-range.
|
||||||
|
Standard_EXPORT virtual bool getSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
void* theData,
|
||||||
|
const unsigned int theDataType);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Dumps the content of me into the stream
|
||||||
|
Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//! Binds a buffer object to an indexed buffer target.
|
||||||
|
//! Wrapper for glBindBufferBase().
|
||||||
|
//! @param theGlCtx [in] active OpenGL context
|
||||||
|
//! @param theIndex [in] index to bind
|
||||||
|
Standard_EXPORT void BindBufferBase (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
unsigned int theIndex);
|
||||||
|
|
||||||
|
//! Unbinds a buffer object from an indexed buffer target.
|
||||||
|
//! Wrapper for glBindBufferBase().
|
||||||
|
//! @param theGlCtx [in] active OpenGL context
|
||||||
|
//! @param theIndex [in] index to bind
|
||||||
|
Standard_EXPORT void UnbindBufferBase (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
unsigned int theIndex);
|
||||||
|
|
||||||
|
//! Binds a buffer object to an indexed buffer target with specified offset and size.
|
||||||
|
//! Wrapper for glBindBufferRange().
|
||||||
|
//! @param theGlCtx [in] active OpenGL context
|
||||||
|
//! @param theIndex [in] index to bind (@sa GL_MAX_UNIFORM_BUFFER_BINDINGS in case of uniform buffer)
|
||||||
|
//! @param theOffset [in] offset within the buffer (@sa GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT in case of uniform buffer)
|
||||||
|
//! @param theSize [in] sub-section length starting from offset
|
||||||
|
Standard_EXPORT void BindBufferRange (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
unsigned int theIndex,
|
||||||
|
const intptr_t theOffset,
|
||||||
|
const size_t theSize);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Standard_Byte* myOffset; //!< offset to data
|
||||||
|
unsigned int myBufferId; //!< VBO name (index)
|
||||||
|
unsigned int myComponentsNb; //!< Number of components per generic vertex attribute, must be 1, 2, 3, or 4
|
||||||
|
Standard_Integer myElemsNb; //!< Number of vertex attributes / number of vertices
|
||||||
|
unsigned int myDataType; //!< Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_STANDARD_HANDLE(OpenGl_Buffer, OpenGl_Resource)
|
||||||
|
|
||||||
|
#endif // _OpenGl_Buffer_H__
|
262
src/OpenGl/OpenGl_BufferCompatT.hxx
Normal file
262
src/OpenGl/OpenGl_BufferCompatT.hxx
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
// Created by: Kirill GAVRILOV
|
||||||
|
// Copyright (c) 2014 OPEN CASCADE SAS
|
||||||
|
//
|
||||||
|
// This file is part of Open CASCADE Technology software library.
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||||
|
// by the Free Software Foundation, with special exception defined in the file
|
||||||
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||||
|
// distribution for complete text of the license and disclaimer of any warranty.
|
||||||
|
//
|
||||||
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
|
#ifndef _OpenGl_BufferCompatT_HeaderFile
|
||||||
|
#define _OpenGl_BufferCompatT_HeaderFile
|
||||||
|
|
||||||
|
#include <NCollection_Buffer.hxx>
|
||||||
|
#include <OpenGl_Buffer.hxx>
|
||||||
|
|
||||||
|
//! Compatibility layer for old OpenGL without VBO.
|
||||||
|
//! Make sure to pass pointer from GetDataOffset() instead of NULL.
|
||||||
|
//! Method GetDataOffset() returns pointer to real data in this class
|
||||||
|
//! (while base class OpenGl_VertexBuffer always return NULL).
|
||||||
|
//!
|
||||||
|
//! Methods Bind()/Unbind() do nothing (do not affect OpenGL state)
|
||||||
|
//! and ::GetTarget() is never used.
|
||||||
|
//! For this reason there is no analog for OpenGl_IndexBuffer.
|
||||||
|
//! Just pass GetDataOffset() to glDrawElements() directly as last argument.
|
||||||
|
//!
|
||||||
|
//! Class overrides methods init() and subData() to copy data into own memory buffer.
|
||||||
|
//! Extra method initLink() might be used to pass existing buffer through handle without copying the data.
|
||||||
|
//!
|
||||||
|
//! Method Create() creates dummy identifier for this object which should NOT be passed to OpenGL functions.
|
||||||
|
template<class BaseBufferT>
|
||||||
|
class OpenGl_BufferCompatT : public BaseBufferT
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Create uninitialized VBO.
|
||||||
|
OpenGl_BufferCompatT()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Destroy object.
|
||||||
|
virtual ~OpenGl_BufferCompatT()
|
||||||
|
{
|
||||||
|
Release (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Return TRUE.
|
||||||
|
virtual bool IsVirtual() const Standard_OVERRIDE { return true; }
|
||||||
|
|
||||||
|
//! Creates VBO name (id) if not yet generated.
|
||||||
|
//! Data should be initialized by another method.
|
||||||
|
inline bool Create (const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Destroy object - will release memory if any.
|
||||||
|
inline virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Bind this VBO.
|
||||||
|
virtual void Bind (const Handle(OpenGl_Context)& ) const Standard_OVERRIDE
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Unbind this VBO.
|
||||||
|
virtual void Unbind (const Handle(OpenGl_Context)& ) const Standard_OVERRIDE
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public: //! @name advanced methods
|
||||||
|
|
||||||
|
//! Initialize buffer with existing data.
|
||||||
|
//! Data will NOT be copied by this method!
|
||||||
|
inline bool initLink (const Handle(NCollection_Buffer)& theData,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned int theDataType);
|
||||||
|
|
||||||
|
//! Initialize buffer with new data (data will be copied).
|
||||||
|
inline virtual bool init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType,
|
||||||
|
const Standard_Integer theStride) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Update part of the buffer with new data.
|
||||||
|
inline virtual bool subData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Read back buffer sub-range.
|
||||||
|
inline virtual bool getSubData (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
void* theData,
|
||||||
|
const unsigned int theDataType) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Handle(NCollection_Buffer) myData; //!< buffer data
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Create
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
template<class BaseBufferT>
|
||||||
|
bool OpenGl_BufferCompatT<BaseBufferT>::Create (const Handle(OpenGl_Context)& )
|
||||||
|
{
|
||||||
|
if (BaseBufferT::myBufferId == OpenGl_Buffer::NO_BUFFER)
|
||||||
|
{
|
||||||
|
BaseBufferT::myBufferId = (unsigned int )-1; // dummy identifier...
|
||||||
|
myData = new NCollection_Buffer (Graphic3d_Buffer::DefaultAllocator());
|
||||||
|
}
|
||||||
|
return BaseBufferT::myBufferId != OpenGl_Buffer::NO_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Release
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
template<class BaseBufferT>
|
||||||
|
void OpenGl_BufferCompatT<BaseBufferT>::Release (OpenGl_Context* )
|
||||||
|
{
|
||||||
|
if (BaseBufferT::myBufferId == OpenGl_Buffer::NO_BUFFER)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBufferT::myOffset = NULL;
|
||||||
|
BaseBufferT::myBufferId = OpenGl_Buffer::NO_BUFFER;
|
||||||
|
myData.Nullify();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : initLink
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
template<class BaseBufferT>
|
||||||
|
bool OpenGl_BufferCompatT<BaseBufferT>::initLink (const Handle(NCollection_Buffer)& theData,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned int theDataType)
|
||||||
|
{
|
||||||
|
if (theData.IsNull())
|
||||||
|
{
|
||||||
|
BaseBufferT::myOffset = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BaseBufferT::myBufferId == OpenGl_Buffer::NO_BUFFER)
|
||||||
|
{
|
||||||
|
BaseBufferT::myBufferId = (unsigned int )-1; // dummy identifier...
|
||||||
|
}
|
||||||
|
myData = theData;
|
||||||
|
BaseBufferT::myDataType = theDataType;
|
||||||
|
BaseBufferT::myComponentsNb = theComponentsNb;
|
||||||
|
BaseBufferT::myElemsNb = theElemsNb;
|
||||||
|
BaseBufferT::myOffset = myData->ChangeData();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : init
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
template<class BaseBufferT>
|
||||||
|
bool OpenGl_BufferCompatT<BaseBufferT>::init (const Handle(OpenGl_Context)& theCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType,
|
||||||
|
const Standard_Integer theStride)
|
||||||
|
{
|
||||||
|
if (!Create (theCtx))
|
||||||
|
{
|
||||||
|
BaseBufferT::myOffset = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBufferT::myDataType = theDataType;
|
||||||
|
BaseBufferT::myComponentsNb = theComponentsNb;
|
||||||
|
BaseBufferT::myElemsNb = theElemsNb;
|
||||||
|
|
||||||
|
const size_t aNbBytes = size_t(BaseBufferT::myElemsNb) * theStride;
|
||||||
|
if (!myData->Allocate (aNbBytes))
|
||||||
|
{
|
||||||
|
BaseBufferT::myOffset = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBufferT::myOffset = myData->ChangeData();
|
||||||
|
if (theData != NULL)
|
||||||
|
{
|
||||||
|
memcpy (myData->ChangeData(), theData, aNbBytes);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : subData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
template<class BaseBufferT>
|
||||||
|
bool OpenGl_BufferCompatT<BaseBufferT>::subData (const Handle(OpenGl_Context)& ,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const void* theData,
|
||||||
|
const unsigned int theDataType)
|
||||||
|
{
|
||||||
|
if (!BaseBufferT::IsValid() || BaseBufferT::myDataType != theDataType
|
||||||
|
|| theElemFrom < 0 || ((theElemFrom + theElemsNb) > BaseBufferT::myElemsNb))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (theData == NULL)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t aDataSize = BaseBufferT::sizeOfGlType (theDataType);
|
||||||
|
const size_t anOffset = size_t(theElemFrom) * size_t(BaseBufferT::myComponentsNb) * aDataSize;
|
||||||
|
const size_t aNbBytes = size_t(theElemsNb) * size_t(BaseBufferT::myComponentsNb) * aDataSize;
|
||||||
|
memcpy (myData->ChangeData() + anOffset, theData, aNbBytes);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : getSubData
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
template<class BaseBufferT>
|
||||||
|
bool OpenGl_BufferCompatT<BaseBufferT>::getSubData (const Handle(OpenGl_Context)& ,
|
||||||
|
const Standard_Integer theElemFrom,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
void* theData,
|
||||||
|
const unsigned int theDataType)
|
||||||
|
{
|
||||||
|
if (!BaseBufferT::IsValid() || BaseBufferT::myDataType != theDataType
|
||||||
|
|| theElemFrom < 0 || ((theElemFrom + theElemsNb) > BaseBufferT::myElemsNb)
|
||||||
|
|| theData == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t aDataSize = BaseBufferT::sizeOfGlType (theDataType);
|
||||||
|
const size_t anOffset = size_t(theElemFrom) * size_t(BaseBufferT::myComponentsNb) * aDataSize;
|
||||||
|
const size_t aNbBytes = size_t(theElemsNb) * size_t(BaseBufferT::myComponentsNb) * aDataSize;
|
||||||
|
memcpy (theData, myData->Data() + anOffset, aNbBytes);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _OpenGl_VertexBufferCompat_HeaderFile
|
@ -12,9 +12,12 @@
|
|||||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
#include <OpenGl_ArbFBO.hxx>
|
|
||||||
#include <OpenGl_DepthPeeling.hxx>
|
#include <OpenGl_DepthPeeling.hxx>
|
||||||
|
|
||||||
|
#include <OpenGl_ArbFBO.hxx>
|
||||||
|
#include <OpenGl_Context.hxx>
|
||||||
|
#include <OpenGl_Texture.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_DepthPeeling, OpenGl_NamedResource)
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_DepthPeeling, OpenGl_NamedResource)
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#define _OpenGl_DepthPeeling_HeaderFile
|
#define _OpenGl_DepthPeeling_HeaderFile
|
||||||
|
|
||||||
#include <OpenGl_FrameBuffer.hxx>
|
#include <OpenGl_FrameBuffer.hxx>
|
||||||
|
#include <OpenGl_NamedResource.hxx>
|
||||||
|
|
||||||
//! Class provides FBOs for dual depth peeling.
|
//! Class provides FBOs for dual depth peeling.
|
||||||
class OpenGl_DepthPeeling : public OpenGl_NamedResource
|
class OpenGl_DepthPeeling : public OpenGl_NamedResource
|
||||||
|
@ -13,7 +13,10 @@
|
|||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
#include <OpenGl_FrameBuffer.hxx>
|
#include <OpenGl_FrameBuffer.hxx>
|
||||||
|
|
||||||
#include <OpenGl_ArbFBO.hxx>
|
#include <OpenGl_ArbFBO.hxx>
|
||||||
|
#include <OpenGl_Context.hxx>
|
||||||
|
#include <OpenGl_Texture.hxx>
|
||||||
|
|
||||||
#include <Standard_Assert.hxx>
|
#include <Standard_Assert.hxx>
|
||||||
#include <TCollection_ExtendedString.hxx>
|
#include <TCollection_ExtendedString.hxx>
|
||||||
@ -91,6 +94,24 @@ OpenGl_FrameBuffer::~OpenGl_FrameBuffer()
|
|||||||
Release (NULL);
|
Release (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : GetSizeX
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
Standard_Integer OpenGl_FrameBuffer::GetSizeX() const
|
||||||
|
{
|
||||||
|
return !myColorTextures.IsEmpty() ? myColorTextures.First()->SizeX() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : GetSizeY
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
Standard_Integer OpenGl_FrameBuffer::GetSizeY() const
|
||||||
|
{
|
||||||
|
return !myColorTextures.IsEmpty() ? myColorTextures.First()->SizeY() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : InitWrapper
|
// function : InitWrapper
|
||||||
// purpose :
|
// purpose :
|
||||||
@ -164,18 +185,17 @@ Standard_Boolean OpenGl_FrameBuffer::InitWrapper (const Handle(OpenGl_Context)&
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlContext,
|
Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlContext,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
const Standard_Integer theColorFormat,
|
||||||
const GLint theColorFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theNbSamples)
|
||||||
const GLsizei theNbSamples)
|
|
||||||
{
|
{
|
||||||
OpenGl_ColorFormats aColorFormats;
|
OpenGl_ColorFormats aColorFormats;
|
||||||
if (theColorFormat != 0)
|
if (theColorFormat != 0)
|
||||||
{
|
{
|
||||||
aColorFormats.Append (theColorFormat);
|
aColorFormats.Append (theColorFormat);
|
||||||
}
|
}
|
||||||
return Init (theGlContext, theSizeX, theSizeY, aColorFormats, theDepthFormat, theNbSamples);
|
return Init (theGlContext, theSize, aColorFormats, theDepthFormat, theNbSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
@ -183,11 +203,10 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlContext,
|
Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlContext,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
|
||||||
const OpenGl_ColorFormats& theColorFormats,
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
const Handle(OpenGl_Texture)& theDepthStencilTexture,
|
const Handle(OpenGl_Texture)& theDepthStencilTexture,
|
||||||
const GLsizei theNbSamples)
|
const Standard_Integer theNbSamples)
|
||||||
{
|
{
|
||||||
myColorFormats = theColorFormats;
|
myColorFormats = theColorFormats;
|
||||||
|
|
||||||
@ -226,10 +245,10 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
|
|||||||
myIsOwnBuffer = true;
|
myIsOwnBuffer = true;
|
||||||
|
|
||||||
// setup viewport sizes as is
|
// setup viewport sizes as is
|
||||||
myVPSizeX = theSizeX;
|
myVPSizeX = theSize.x();
|
||||||
myVPSizeY = theSizeY;
|
myVPSizeY = theSize.y();
|
||||||
const Standard_Integer aSizeX = theSizeX > 0 ? theSizeX : 2;
|
const Standard_Integer aSizeX = theSize.x() > 0 ? theSize.x() : 2;
|
||||||
const Standard_Integer aSizeY = theSizeY > 0 ? theSizeY : 2;
|
const Standard_Integer aSizeY = theSize.y() > 0 ? theSize.y() : 2;
|
||||||
|
|
||||||
// Create the textures (will be used as color buffer and depth-stencil buffer)
|
// Create the textures (will be used as color buffer and depth-stencil buffer)
|
||||||
if (theNbSamples != 0)
|
if (theNbSamples != 0)
|
||||||
@ -306,11 +325,10 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlContext,
|
Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlContext,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
|
||||||
const OpenGl_ColorFormats& theColorFormats,
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLsizei theNbSamples)
|
const Standard_Integer theNbSamples)
|
||||||
{
|
{
|
||||||
myColorFormats = theColorFormats;
|
myColorFormats = theColorFormats;
|
||||||
|
|
||||||
@ -330,8 +348,8 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
|
|||||||
|
|
||||||
myDepthFormat = theDepthFormat;
|
myDepthFormat = theDepthFormat;
|
||||||
myNbSamples = theNbSamples;
|
myNbSamples = theNbSamples;
|
||||||
myInitVPSizeX = theSizeX;
|
myInitVPSizeX = theSize.x();
|
||||||
myInitVPSizeY = theSizeY;
|
myInitVPSizeY = theSize.y();
|
||||||
if (theGlContext->arbFBO == NULL)
|
if (theGlContext->arbFBO == NULL)
|
||||||
{
|
{
|
||||||
return Standard_False;
|
return Standard_False;
|
||||||
@ -350,10 +368,10 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
|
|||||||
myIsOwnDepth = true;
|
myIsOwnDepth = true;
|
||||||
|
|
||||||
// setup viewport sizes as is
|
// setup viewport sizes as is
|
||||||
myVPSizeX = theSizeX;
|
myVPSizeX = theSize.x();
|
||||||
myVPSizeY = theSizeY;
|
myVPSizeY = theSize.y();
|
||||||
const Standard_Integer aSizeX = theSizeX > 0 ? theSizeX : 2;
|
const Standard_Integer aSizeX = theSize.x() > 0 ? theSize.x() : 2;
|
||||||
const Standard_Integer aSizeY = theSizeY > 0 ? theSizeY : 2;
|
const Standard_Integer aSizeY = theSize.y() > 0 ? theSize.y() : 2;
|
||||||
bool hasStencilRB = false;
|
bool hasStencilRB = false;
|
||||||
|
|
||||||
// Create the textures (will be used as color buffer and depth-stencil buffer)
|
// Create the textures (will be used as color buffer and depth-stencil buffer)
|
||||||
@ -475,17 +493,14 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Boolean OpenGl_FrameBuffer::InitLazy (const Handle(OpenGl_Context)& theGlContext,
|
Standard_Boolean OpenGl_FrameBuffer::InitLazy (const Handle(OpenGl_Context)& theGlContext,
|
||||||
const GLsizei theViewportSizeX,
|
const Graphic3d_Vec2i& theViewportSize,
|
||||||
const GLsizei theViewportSizeY,
|
const Standard_Integer theColorFormat,
|
||||||
const GLint theColorFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theNbSamples)
|
||||||
const GLsizei theNbSamples)
|
|
||||||
{
|
{
|
||||||
OpenGl_ColorFormats aColorFormats;
|
OpenGl_ColorFormats aColorFormats;
|
||||||
|
|
||||||
aColorFormats.Append (theColorFormat);
|
aColorFormats.Append (theColorFormat);
|
||||||
|
return InitLazy (theGlContext, theViewportSize, aColorFormats, theDepthFormat, theNbSamples);
|
||||||
return InitLazy (theGlContext, theViewportSizeX, theViewportSizeY, aColorFormats, theDepthFormat, theNbSamples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
@ -493,14 +508,13 @@ Standard_Boolean OpenGl_FrameBuffer::InitLazy (const Handle(OpenGl_Context)& the
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Boolean OpenGl_FrameBuffer::InitLazy (const Handle(OpenGl_Context)& theGlContext,
|
Standard_Boolean OpenGl_FrameBuffer::InitLazy (const Handle(OpenGl_Context)& theGlContext,
|
||||||
const GLsizei theViewportSizeX,
|
const Graphic3d_Vec2i& theViewportSize,
|
||||||
const GLsizei theViewportSizeY,
|
|
||||||
const OpenGl_ColorFormats& theColorFormats,
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLsizei theNbSamples)
|
const Standard_Integer theNbSamples)
|
||||||
{
|
{
|
||||||
if (myVPSizeX == theViewportSizeX
|
if (myVPSizeX == theViewportSize.x()
|
||||||
&& myVPSizeY == theViewportSizeY
|
&& myVPSizeY == theViewportSize.y()
|
||||||
&& myColorFormats == theColorFormats
|
&& myColorFormats == theColorFormats
|
||||||
&& myDepthFormat == theDepthFormat
|
&& myDepthFormat == theDepthFormat
|
||||||
&& myNbSamples == theNbSamples)
|
&& myNbSamples == theNbSamples)
|
||||||
@ -508,7 +522,7 @@ Standard_Boolean OpenGl_FrameBuffer::InitLazy (const Handle(OpenGl_Context)& the
|
|||||||
return IsValid();
|
return IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Init (theGlContext, theViewportSizeX, theViewportSizeY, theColorFormats, theDepthFormat, theNbSamples);
|
return Init (theGlContext, theViewportSize, theColorFormats, theDepthFormat, theNbSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
@ -516,11 +530,10 @@ Standard_Boolean OpenGl_FrameBuffer::InitLazy (const Handle(OpenGl_Context)& the
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Boolean OpenGl_FrameBuffer::InitWithRB (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_Boolean OpenGl_FrameBuffer::InitWithRB (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
const Standard_Integer theColorFormat,
|
||||||
const GLint theColorFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLint theDepthFormat,
|
const unsigned int theColorRBufferFromWindow)
|
||||||
const GLuint theColorRBufferFromWindow)
|
|
||||||
{
|
{
|
||||||
myColorFormats.Clear();
|
myColorFormats.Clear();
|
||||||
myColorFormats.Append (theColorFormat);
|
myColorFormats.Append (theColorFormat);
|
||||||
@ -537,8 +550,8 @@ Standard_Boolean OpenGl_FrameBuffer::InitWithRB (const Handle(OpenGl_Context)& t
|
|||||||
|
|
||||||
myDepthFormat = theDepthFormat;
|
myDepthFormat = theDepthFormat;
|
||||||
myNbSamples = 0;
|
myNbSamples = 0;
|
||||||
myInitVPSizeX = theSizeX;
|
myInitVPSizeX = theSize.x();
|
||||||
myInitVPSizeY = theSizeY;
|
myInitVPSizeY = theSize.y();
|
||||||
if (theGlCtx->arbFBO == NULL)
|
if (theGlCtx->arbFBO == NULL)
|
||||||
{
|
{
|
||||||
return Standard_False;
|
return Standard_False;
|
||||||
@ -552,10 +565,10 @@ Standard_Boolean OpenGl_FrameBuffer::InitWithRB (const Handle(OpenGl_Context)& t
|
|||||||
myIsOwnDepth = true;
|
myIsOwnDepth = true;
|
||||||
|
|
||||||
// setup viewport sizes as is
|
// setup viewport sizes as is
|
||||||
myVPSizeX = theSizeX;
|
myVPSizeX = theSize.x();
|
||||||
myVPSizeY = theSizeY;
|
myVPSizeY = theSize.y();
|
||||||
const Standard_Integer aSizeX = theSizeX > 0 ? theSizeX : 2;
|
const Standard_Integer aSizeX = theSize.x() > 0 ? theSize.x() : 2;
|
||||||
const Standard_Integer aSizeY = theSizeY > 0 ? theSizeY : 2;
|
const Standard_Integer aSizeY = theSize.y() > 0 ? theSize.y() : 2;
|
||||||
|
|
||||||
// Create the render-buffers
|
// Create the render-buffers
|
||||||
if (theColorRBufferFromWindow != NO_RENDERBUFFER)
|
if (theColorRBufferFromWindow != NO_RENDERBUFFER)
|
||||||
@ -754,8 +767,8 @@ void OpenGl_FrameBuffer::SetupViewport (const Handle(OpenGl_Context)& theGlCtx)
|
|||||||
// function : ChangeViewport
|
// function : ChangeViewport
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_FrameBuffer::ChangeViewport (const GLsizei theVPSizeX,
|
void OpenGl_FrameBuffer::ChangeViewport (const Standard_Integer theVPSizeX,
|
||||||
const GLsizei theVPSizeY)
|
const Standard_Integer theVPSizeY)
|
||||||
{
|
{
|
||||||
myVPSizeX = theVPSizeX;
|
myVPSizeX = theVPSizeX;
|
||||||
myVPSizeY = theVPSizeY;
|
myVPSizeY = theVPSizeY;
|
||||||
|
@ -15,18 +15,20 @@
|
|||||||
#ifndef OPENGL_FRAME_BUFFER_H
|
#ifndef OPENGL_FRAME_BUFFER_H
|
||||||
#define OPENGL_FRAME_BUFFER_H
|
#define OPENGL_FRAME_BUFFER_H
|
||||||
|
|
||||||
#include <OpenGl_Context.hxx>
|
|
||||||
#include <OpenGl_Resource.hxx>
|
#include <OpenGl_Resource.hxx>
|
||||||
#include <OpenGl_Texture.hxx>
|
|
||||||
|
|
||||||
#include <Graphic3d_BufferType.hxx>
|
#include <Graphic3d_BufferType.hxx>
|
||||||
|
#include <Graphic3d_Vec2.hxx>
|
||||||
#include <NCollection_Vector.hxx>
|
#include <NCollection_Vector.hxx>
|
||||||
|
#include <NCollection_Sequence.hxx>
|
||||||
|
|
||||||
|
class Image_PixMap;
|
||||||
|
class OpenGl_Texture;
|
||||||
|
|
||||||
class OpenGl_FrameBuffer;
|
|
||||||
DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource)
|
DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource)
|
||||||
|
|
||||||
//! Short declaration of useful collection types.
|
//! Short declaration of useful collection types.
|
||||||
typedef NCollection_Vector<GLint> OpenGl_ColorFormats;
|
typedef NCollection_Vector<Standard_Integer> OpenGl_ColorFormats;
|
||||||
|
|
||||||
//! Class implements FrameBuffer Object (FBO) resource
|
//! Class implements FrameBuffer Object (FBO) resource
|
||||||
//! intended for off-screen rendering.
|
//! intended for off-screen rendering.
|
||||||
@ -36,8 +38,8 @@ class OpenGl_FrameBuffer : public OpenGl_Resource
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//! Helpful constants
|
//! Helpful constants
|
||||||
static const GLuint NO_FRAMEBUFFER = 0;
|
static const unsigned int NO_FRAMEBUFFER = 0;
|
||||||
static const GLuint NO_RENDERBUFFER = 0;
|
static const unsigned int NO_RENDERBUFFER = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -64,64 +66,43 @@ public:
|
|||||||
Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
||||||
|
|
||||||
//! Number of multisampling samples.
|
//! Number of multisampling samples.
|
||||||
GLsizei NbSamples() const
|
Standard_Integer NbSamples() const { return myNbSamples; }
|
||||||
{
|
|
||||||
return myNbSamples;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Number of color buffers.
|
//! Number of color buffers.
|
||||||
GLsizei NbColorBuffers() const
|
Standard_Integer NbColorBuffers() const { return myColorTextures.Length(); }
|
||||||
{
|
|
||||||
return myColorTextures.Length();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Return true if FBO has been created with color attachment.
|
//! Return true if FBO has been created with color attachment.
|
||||||
bool HasColor() const
|
bool HasColor() const { return !myColorFormats.IsEmpty(); }
|
||||||
{
|
|
||||||
return !myColorFormats.IsEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Return true if FBO has been created with depth attachment.
|
//! Return true if FBO has been created with depth attachment.
|
||||||
bool HasDepth() const
|
bool HasDepth() const { return myDepthFormat != 0; }
|
||||||
{
|
|
||||||
return myDepthFormat != 0;
|
//! Return textures width x height.
|
||||||
}
|
Graphic3d_Vec2i GetSize() const { return Graphic3d_Vec2i (GetSizeX(), GetSizeY()); }
|
||||||
|
|
||||||
//! Textures width.
|
//! Textures width.
|
||||||
GLsizei GetSizeX() const
|
Standard_EXPORT Standard_Integer GetSizeX() const;
|
||||||
{
|
|
||||||
return myColorTextures (0)->SizeX();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Textures height.
|
//! Textures height.
|
||||||
GLsizei GetSizeY() const
|
Standard_EXPORT Standard_Integer GetSizeY() const;
|
||||||
{
|
|
||||||
return myColorTextures (0)->SizeY();
|
//! Return viewport width x height.
|
||||||
}
|
Graphic3d_Vec2i GetVPSize() const { return Graphic3d_Vec2i (myVPSizeX, myVPSizeY); }
|
||||||
|
|
||||||
//! Viewport width.
|
//! Viewport width.
|
||||||
GLsizei GetVPSizeX() const
|
Standard_Integer GetVPSizeX() const { return myVPSizeX; }
|
||||||
{
|
|
||||||
return myVPSizeX;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Viewport height.
|
//! Viewport height.
|
||||||
GLsizei GetVPSizeY() const
|
Standard_Integer GetVPSizeY() const { return myVPSizeY; }
|
||||||
{
|
|
||||||
return myVPSizeY;
|
//! Return viewport width x height.
|
||||||
}
|
Graphic3d_Vec2i GetInitVPSize() const { return Graphic3d_Vec2i (myInitVPSizeX, myInitVPSizeY); }
|
||||||
|
|
||||||
//! Viewport width.
|
//! Viewport width.
|
||||||
GLsizei GetInitVPSizeX() const
|
Standard_Integer GetInitVPSizeX() const { return myInitVPSizeX; }
|
||||||
{
|
|
||||||
return myInitVPSizeX;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Viewport height.
|
//! Viewport height.
|
||||||
GLsizei GetInitVPSizeY() const
|
Standard_Integer GetInitVPSizeY() const { return myInitVPSizeY; }
|
||||||
{
|
|
||||||
return myInitVPSizeY;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Returns true if current object was initialized
|
//! Returns true if current object was initialized
|
||||||
Standard_Boolean IsValid() const
|
Standard_Boolean IsValid() const
|
||||||
@ -131,86 +112,76 @@ public:
|
|||||||
|
|
||||||
//! Initialize FBO for rendering into single/multiple color buffer and depth textures.
|
//! Initialize FBO for rendering into single/multiple color buffer and depth textures.
|
||||||
//! @param theGlCtx currently bound OpenGL context
|
//! @param theGlCtx currently bound OpenGL context
|
||||||
//! @param theSizeX texture width
|
//! @param theSize texture width x height
|
||||||
//! @param theSizeY texture height
|
|
||||||
//! @param theColorFormats list of color texture sized format (0 means no color attachment), e.g. GL_RGBA8
|
//! @param theColorFormats list of color texture sized format (0 means no color attachment), e.g. GL_RGBA8
|
||||||
//! @param theDepthStencilTexture depth-stencil texture
|
//! @param theDepthStencilTexture depth-stencil texture
|
||||||
//! @param theNbSamples MSAA number of samples (0 means normal texture)
|
//! @param theNbSamples MSAA number of samples (0 means normal texture)
|
||||||
//! @return true on success
|
//! @return true on success
|
||||||
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
|
||||||
const OpenGl_ColorFormats& theColorFormats,
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
const Handle(OpenGl_Texture)& theDepthStencilTexture,
|
const Handle(OpenGl_Texture)& theDepthStencilTexture,
|
||||||
const GLsizei theNbSamples = 0);
|
const Standard_Integer theNbSamples = 0);
|
||||||
|
|
||||||
//! Initialize FBO for rendering into textures.
|
//! Initialize FBO for rendering into textures.
|
||||||
//! @param theGlCtx currently bound OpenGL context
|
//! @param theGlCtx currently bound OpenGL context
|
||||||
//! @param theSizeX texture width
|
//! @param theSize texture width x height
|
||||||
//! @param theSizeY texture height
|
|
||||||
//! @param theColorFormat color texture sized format (0 means no color attachment), e.g. GL_RGBA8
|
//! @param theColorFormat color texture sized format (0 means no color attachment), e.g. GL_RGBA8
|
||||||
//! @param theDepthFormat depth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
|
//! @param theDepthFormat depth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
|
||||||
//! @param theNbSamples MSAA number of samples (0 means normal texture)
|
//! @param theNbSamples MSAA number of samples (0 means normal texture)
|
||||||
//! @return true on success
|
//! @return true on success
|
||||||
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
const Standard_Integer theColorFormat,
|
||||||
const GLint theColorFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theNbSamples = 0);
|
||||||
const GLsizei theNbSamples = 0);
|
|
||||||
|
|
||||||
//! Initialize FBO for rendering into single/multiple color buffer and depth textures.
|
//! Initialize FBO for rendering into single/multiple color buffer and depth textures.
|
||||||
//! @param theGlCtx currently bound OpenGL context
|
//! @param theGlCtx currently bound OpenGL context
|
||||||
//! @param theSizeX texture width
|
//! @param theSize texture width x height
|
||||||
//! @param theSizeY texture height
|
|
||||||
//! @param theColorFormats list of color texture sized format (0 means no color attachment), e.g. GL_RGBA8
|
//! @param theColorFormats list of color texture sized format (0 means no color attachment), e.g. GL_RGBA8
|
||||||
//! @param theDepthFormat depth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
|
//! @param theDepthFormat depth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
|
||||||
//! @param theNbSamples MSAA number of samples (0 means normal texture)
|
//! @param theNbSamples MSAA number of samples (0 means normal texture)
|
||||||
//! @return true on success
|
//! @return true on success
|
||||||
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
|
||||||
const OpenGl_ColorFormats& theColorFormats,
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLsizei theNbSamples = 0);
|
const Standard_Integer theNbSamples = 0);
|
||||||
|
|
||||||
//! (Re-)initialize FBO with specified dimensions.
|
//! (Re-)initialize FBO with specified dimensions.
|
||||||
Standard_EXPORT Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLsizei theViewportSizeX,
|
const Graphic3d_Vec2i& theViewportSize,
|
||||||
const GLsizei theViewportSizeY,
|
const Standard_Integer theColorFormat,
|
||||||
const GLint theColorFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theNbSamples = 0);
|
||||||
const GLsizei theNbSamples = 0);
|
|
||||||
|
|
||||||
//! (Re-)initialize FBO with specified dimensions.
|
//! (Re-)initialize FBO with specified dimensions.
|
||||||
Standard_EXPORT Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLsizei theViewportSizeX,
|
const Graphic3d_Vec2i& theViewportSize,
|
||||||
const GLsizei theViewportSizeY,
|
|
||||||
const OpenGl_ColorFormats& theColorFormats,
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
const GLint theDepthFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLsizei theNbSamples = 0);
|
const Standard_Integer theNbSamples = 0);
|
||||||
|
|
||||||
//! (Re-)initialize FBO with properties taken from another FBO.
|
//! (Re-)initialize FBO with properties taken from another FBO.
|
||||||
Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_Boolean InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const OpenGl_FrameBuffer& theFbo)
|
const OpenGl_FrameBuffer& theFbo)
|
||||||
{
|
{
|
||||||
return InitLazy (theGlCtx, theFbo.myVPSizeX, theFbo.myVPSizeY, theFbo.myColorFormats, theFbo.myDepthFormat, theFbo.myNbSamples);
|
return InitLazy (theGlCtx, Graphic3d_Vec2i (theFbo.myVPSizeX, theFbo.myVPSizeY), theFbo.myColorFormats, theFbo.myDepthFormat, theFbo.myNbSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! (Re-)initialize FBO with specified dimensions.
|
//! (Re-)initialize FBO with specified dimensions.
|
||||||
//! The Render Buffer Objects will be used for Color, Depth and Stencil attachments (as opposite to textures).
|
//! The Render Buffer Objects will be used for Color, Depth and Stencil attachments (as opposite to textures).
|
||||||
//! @param theGlCtx currently bound OpenGL context
|
//! @param theGlCtx currently bound OpenGL context
|
||||||
//! @param theSizeX render buffer width
|
//! @param theSize render buffer width x height
|
||||||
//! @param theSizeY render buffer height
|
|
||||||
//! @param theColorFormat color render buffer sized format, e.g. GL_RGBA8
|
//! @param theColorFormat color render buffer sized format, e.g. GL_RGBA8
|
||||||
//! @param theDepthFormat depth-stencil render buffer sized format, e.g. GL_DEPTH24_STENCIL8
|
//! @param theDepthFormat depth-stencil render buffer sized format, e.g. GL_DEPTH24_STENCIL8
|
||||||
//! @param theColorRBufferFromWindow when specified - should be ID of already initialized RB object, which will be released within this class
|
//! @param theColorRBufferFromWindow when specified - should be ID of already initialized RB object, which will be released within this class
|
||||||
Standard_EXPORT Standard_Boolean InitWithRB (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT Standard_Boolean InitWithRB (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLsizei theSizeX,
|
const Graphic3d_Vec2i& theSize,
|
||||||
const GLsizei theSizeY,
|
const Standard_Integer theColorFormat,
|
||||||
const GLint theColorFormat,
|
const Standard_Integer theDepthFormat,
|
||||||
const GLint theDepthFormat,
|
const unsigned int theColorRBufferFromWindow = 0);
|
||||||
const GLuint theColorRBufferFromWindow = 0);
|
|
||||||
|
|
||||||
//! Initialize class from currently bound FBO.
|
//! Initialize class from currently bound FBO.
|
||||||
//! Retrieved OpenGL objects will not be destroyed on Release.
|
//! Retrieved OpenGL objects will not be destroyed on Release.
|
||||||
@ -225,8 +196,8 @@ public:
|
|||||||
Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx);
|
Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx);
|
||||||
|
|
||||||
//! Override viewport settings
|
//! Override viewport settings
|
||||||
Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX,
|
Standard_EXPORT void ChangeViewport (const Standard_Integer theVPSizeX,
|
||||||
const GLsizei theVPSizeY);
|
const Standard_Integer theVPSizeY);
|
||||||
|
|
||||||
//! Bind frame buffer for drawing and reading (to render into the texture).
|
//! Bind frame buffer for drawing and reading (to render into the texture).
|
||||||
Standard_EXPORT virtual void BindBuffer (const Handle(OpenGl_Context)& theGlCtx);
|
Standard_EXPORT virtual void BindBuffer (const Handle(OpenGl_Context)& theGlCtx);
|
||||||
@ -241,32 +212,98 @@ public:
|
|||||||
Standard_EXPORT virtual void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx);
|
Standard_EXPORT virtual void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx);
|
||||||
|
|
||||||
//! Returns the color texture for the given color buffer index.
|
//! Returns the color texture for the given color buffer index.
|
||||||
const Handle(OpenGl_Texture)& ColorTexture (const GLint theColorBufferIndex = 0) const
|
const Handle(OpenGl_Texture)& ColorTexture (const Standard_Integer theColorBufferIndex = 0) const
|
||||||
{
|
{
|
||||||
return myColorTextures (theColorBufferIndex);
|
return myColorTextures.Value (theColorBufferIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Returns the depth-stencil texture.
|
//! Returns the depth-stencil texture.
|
||||||
const Handle(OpenGl_Texture)& DepthStencilTexture() const
|
const Handle(OpenGl_Texture)& DepthStencilTexture() const { return myDepthStencilTexture; }
|
||||||
{
|
|
||||||
return myDepthStencilTexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Returns the color Render Buffer.
|
//! Returns the color Render Buffer.
|
||||||
GLuint ColorRenderBuffer() const
|
unsigned int ColorRenderBuffer() const { return myGlColorRBufferId; }
|
||||||
{
|
|
||||||
return myGlColorRBufferId;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Returns the depth Render Buffer.
|
//! Returns the depth Render Buffer.
|
||||||
GLuint DepthStencilRenderBuffer() const
|
unsigned int DepthStencilRenderBuffer() const { return myGlDepthRBufferId; }
|
||||||
{
|
|
||||||
return myGlDepthRBufferId;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
|
//! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
|
||||||
Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
|
Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Initialize FBO for rendering into single/multiple color buffer and depth textures.
|
||||||
|
Standard_DEPRECATED("Obsolete method, use Init() taking Graphic3d_Vec2i")
|
||||||
|
bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theSizeX,
|
||||||
|
const Standard_Integer theSizeY,
|
||||||
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
|
const Handle(OpenGl_Texture)& theDepthStencilTexture,
|
||||||
|
const Standard_Integer theNbSamples = 0)
|
||||||
|
{
|
||||||
|
return Init (theGlCtx, Graphic3d_Vec2i (theSizeX, theSizeY), theColorFormats, theDepthStencilTexture, theNbSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Initialize FBO for rendering into textures.
|
||||||
|
Standard_DEPRECATED("Obsolete method, use Init() taking Graphic3d_Vec2i")
|
||||||
|
bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theSizeX,
|
||||||
|
const Standard_Integer theSizeY,
|
||||||
|
const Standard_Integer theColorFormat,
|
||||||
|
const Standard_Integer theDepthFormat,
|
||||||
|
const Standard_Integer theNbSamples = 0)
|
||||||
|
{
|
||||||
|
return Init (theGlCtx, Graphic3d_Vec2i (theSizeX, theSizeY), theColorFormat, theDepthFormat, theNbSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Initialize FBO for rendering into single/multiple color buffer and depth textures.
|
||||||
|
Standard_DEPRECATED("Obsolete method, use Init() taking Graphic3d_Vec2i")
|
||||||
|
bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theSizeX,
|
||||||
|
const Standard_Integer theSizeY,
|
||||||
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
|
const Standard_Integer theDepthFormat,
|
||||||
|
const Standard_Integer theNbSamples = 0)
|
||||||
|
{
|
||||||
|
return Init (theGlCtx, Graphic3d_Vec2i (theSizeX, theSizeY), theColorFormats, theDepthFormat, theNbSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! (Re-)initialize FBO with specified dimensions.
|
||||||
|
Standard_DEPRECATED("Obsolete method, use InitLazy() taking Graphic3d_Vec2i")
|
||||||
|
bool InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theViewportSizeX,
|
||||||
|
const Standard_Integer theViewportSizeY,
|
||||||
|
const Standard_Integer theColorFormat,
|
||||||
|
const Standard_Integer theDepthFormat,
|
||||||
|
const Standard_Integer theNbSamples = 0)
|
||||||
|
{
|
||||||
|
return InitLazy (theGlCtx, Graphic3d_Vec2i (theViewportSizeX, theViewportSizeY), theColorFormat, theDepthFormat, theNbSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! (Re-)initialize FBO with specified dimensions.
|
||||||
|
Standard_DEPRECATED("Obsolete method, use InitLazy() taking Graphic3d_Vec2i")
|
||||||
|
bool InitLazy (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theViewportSizeX,
|
||||||
|
const Standard_Integer theViewportSizeY,
|
||||||
|
const OpenGl_ColorFormats& theColorFormats,
|
||||||
|
const Standard_Integer theDepthFormat,
|
||||||
|
const Standard_Integer theNbSamples = 0)
|
||||||
|
{
|
||||||
|
return InitLazy (theGlCtx, Graphic3d_Vec2i (theViewportSizeX, theViewportSizeY), theColorFormats, theDepthFormat, theNbSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! (Re-)initialize FBO with specified dimensions.
|
||||||
|
//! The Render Buffer Objects will be used for Color, Depth and Stencil attachments (as opposite to textures).
|
||||||
|
Standard_DEPRECATED("Obsolete method, use InitWithRB() taking Graphic3d_Vec2i")
|
||||||
|
bool InitWithRB (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Standard_Integer theSizeX,
|
||||||
|
const Standard_Integer theSizeY,
|
||||||
|
const Standard_Integer theColorFormat,
|
||||||
|
const Standard_Integer theDepthFormat,
|
||||||
|
const unsigned int theColorRBufferFromWindow = 0)
|
||||||
|
{
|
||||||
|
return InitWithRB (theGlCtx, Graphic3d_Vec2i (theSizeX, theSizeY), theColorFormat, theDepthFormat, theColorRBufferFromWindow);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Standard_Boolean isValidFrameBuffer() const
|
Standard_Boolean isValidFrameBuffer() const
|
||||||
@ -280,16 +317,16 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
GLsizei myInitVPSizeX; //!< viewport width specified during initialization (kept even on failure)
|
Standard_Integer myInitVPSizeX; //!< viewport width specified during initialization (kept even on failure)
|
||||||
GLsizei myInitVPSizeY; //!< viewport height specified during initialization (kept even on failure)
|
Standard_Integer myInitVPSizeY; //!< viewport height specified during initialization (kept even on failure)
|
||||||
GLsizei myVPSizeX; //!< viewport width (should be <= texture width)
|
Standard_Integer myVPSizeX; //!< viewport width (should be <= texture width)
|
||||||
GLsizei myVPSizeY; //!< viewport height (should be <= texture height)
|
Standard_Integer myVPSizeY; //!< viewport height (should be <= texture height)
|
||||||
GLsizei myNbSamples; //!< number of MSAA samples
|
Standard_Integer myNbSamples; //!< number of MSAA samples
|
||||||
OpenGl_ColorFormats myColorFormats; //!< sized format for color texture, GL_RGBA8 by default
|
OpenGl_ColorFormats myColorFormats; //!< sized format for color texture, GL_RGBA8 by default
|
||||||
GLint myDepthFormat; //!< sized format for depth-stencil texture, GL_DEPTH24_STENCIL8 by default
|
Standard_Integer myDepthFormat; //!< sized format for depth-stencil texture, GL_DEPTH24_STENCIL8 by default
|
||||||
GLuint myGlFBufferId; //!< FBO object ID
|
unsigned int myGlFBufferId; //!< FBO object ID
|
||||||
GLuint myGlColorRBufferId; //!< color Render Buffer object (alternative to myColorTexture)
|
unsigned int myGlColorRBufferId; //!< color Render Buffer object (alternative to myColorTexture)
|
||||||
GLuint myGlDepthRBufferId; //!< depth-stencil Render Buffer object (alternative to myDepthStencilTexture)
|
unsigned int myGlDepthRBufferId; //!< depth-stencil Render Buffer object (alternative to myDepthStencilTexture)
|
||||||
bool myIsOwnBuffer; //!< flag indicating that FBO should be deallocated by this class
|
bool myIsOwnBuffer; //!< flag indicating that FBO should be deallocated by this class
|
||||||
bool myIsOwnColor; //!< flag indicating that color textures should be deallocated by this class
|
bool myIsOwnColor; //!< flag indicating that color textures should be deallocated by this class
|
||||||
bool myIsOwnDepth; //!< flag indicating that depth texture should be deallocated by this class
|
bool myIsOwnDepth; //!< flag indicating that depth texture should be deallocated by this class
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include <OpenGl_View.hxx>
|
#include <OpenGl_View.hxx>
|
||||||
#include <OpenGl_DepthPeeling.hxx>
|
#include <OpenGl_DepthPeeling.hxx>
|
||||||
#include <OpenGl_ShadowMap.hxx>
|
#include <OpenGl_ShadowMap.hxx>
|
||||||
|
#include <OpenGl_TextureBuffer.hxx>
|
||||||
|
#include <OpenGl_Window.hxx>
|
||||||
#include <OpenGl_Workspace.hxx>
|
#include <OpenGl_Workspace.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_FrameStats, Graphic3d_FrameStats)
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_FrameStats, Graphic3d_FrameStats)
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <OpenGl_FrameStatsPrs.hxx>
|
#include <OpenGl_FrameStatsPrs.hxx>
|
||||||
|
|
||||||
#include <OpenGl_View.hxx>
|
#include <OpenGl_View.hxx>
|
||||||
|
#include <OpenGl_IndexBuffer.hxx>
|
||||||
|
#include <OpenGl_VertexBuffer.hxx>
|
||||||
#include <OpenGl_ShaderManager.hxx>
|
#include <OpenGl_ShaderManager.hxx>
|
||||||
#include <OpenGl_Workspace.hxx>
|
#include <OpenGl_Workspace.hxx>
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <OpenGl_View.hxx>
|
#include <OpenGl_View.hxx>
|
||||||
#include <OpenGl_StencilTest.hxx>
|
#include <OpenGl_StencilTest.hxx>
|
||||||
#include <OpenGl_Text.hxx>
|
#include <OpenGl_Text.hxx>
|
||||||
|
#include <OpenGl_Window.hxx>
|
||||||
#include <OpenGl_Workspace.hxx>
|
#include <OpenGl_Workspace.hxx>
|
||||||
|
|
||||||
#include <Aspect_GraphicDeviceDefinitionError.hxx>
|
#include <Aspect_GraphicDeviceDefinitionError.hxx>
|
||||||
|
@ -17,21 +17,20 @@
|
|||||||
#include <OpenGl_Context.hxx>
|
#include <OpenGl_Context.hxx>
|
||||||
#include <Standard_Assert.hxx>
|
#include <Standard_Assert.hxx>
|
||||||
|
|
||||||
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_IndexBuffer, OpenGl_Buffer)
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_IndexBuffer,OpenGl_VertexBuffer)
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : OpenGl_IndexBuffer
|
// function : OpenGl_IndexBuffer
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
OpenGl_IndexBuffer::OpenGl_IndexBuffer()
|
OpenGl_IndexBuffer::OpenGl_IndexBuffer()
|
||||||
: OpenGl_VertexBuffer() {}
|
: OpenGl_Buffer() {}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : GetTarget
|
// function : GetTarget
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
GLenum OpenGl_IndexBuffer::GetTarget() const
|
unsigned int OpenGl_IndexBuffer::GetTarget() const
|
||||||
{
|
{
|
||||||
return GL_ELEMENT_ARRAY_BUFFER;
|
return GL_ELEMENT_ARRAY_BUFFER;
|
||||||
}
|
}
|
||||||
@ -43,5 +42,5 @@ GLenum OpenGl_IndexBuffer::GetTarget() const
|
|||||||
void OpenGl_IndexBuffer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
|
void OpenGl_IndexBuffer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
|
||||||
{
|
{
|
||||||
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
|
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
|
||||||
OCCT_DUMP_BASE_CLASS (theOStream, theDepth, OpenGl_VertexBuffer)
|
OCCT_DUMP_BASE_CLASS (theOStream, theDepth, OpenGl_Buffer)
|
||||||
}
|
}
|
||||||
|
@ -15,25 +15,28 @@
|
|||||||
#ifndef _OpenGl_IndexBuffer_H__
|
#ifndef _OpenGl_IndexBuffer_H__
|
||||||
#define _OpenGl_IndexBuffer_H__
|
#define _OpenGl_IndexBuffer_H__
|
||||||
|
|
||||||
#include <OpenGl_VertexBuffer.hxx>
|
#include <OpenGl_Buffer.hxx>
|
||||||
|
|
||||||
//! Index buffer is just a VBO with special target (GL_ELEMENT_ARRAY_BUFFER).
|
//! Index buffer is just a VBO with special target (GL_ELEMENT_ARRAY_BUFFER).
|
||||||
class OpenGl_IndexBuffer : public OpenGl_VertexBuffer
|
class OpenGl_IndexBuffer : public OpenGl_Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//! Empty constructor.
|
||||||
Standard_EXPORT OpenGl_IndexBuffer();
|
Standard_EXPORT OpenGl_IndexBuffer();
|
||||||
Standard_EXPORT virtual GLenum GetTarget() const Standard_OVERRIDE;
|
|
||||||
|
//! Return buffer object target (GL_ELEMENT_ARRAY_BUFFER).
|
||||||
|
Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
|
||||||
|
|
||||||
//! Dumps the content of me into the stream
|
//! Dumps the content of me into the stream
|
||||||
Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
|
Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DEFINE_STANDARD_RTTIEXT(OpenGl_IndexBuffer,OpenGl_VertexBuffer) // Type definition
|
DEFINE_STANDARD_RTTIEXT(OpenGl_IndexBuffer, OpenGl_Buffer)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STANDARD_HANDLE(OpenGl_IndexBuffer, OpenGl_VertexBuffer)
|
DEFINE_STANDARD_HANDLE(OpenGl_IndexBuffer, OpenGl_Buffer)
|
||||||
|
|
||||||
#endif // _OpenGl_IndexBuffer_H__
|
#endif // _OpenGl_IndexBuffer_H__
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <OpenGl_ArbFBO.hxx>
|
#include <OpenGl_ArbFBO.hxx>
|
||||||
#include <OpenGl_FrameBuffer.hxx>
|
#include <OpenGl_FrameBuffer.hxx>
|
||||||
#include <OpenGl_ShaderManager.hxx>
|
#include <OpenGl_ShaderManager.hxx>
|
||||||
|
#include <OpenGl_ShaderProgram.hxx>
|
||||||
#include <OSD_Timer.hxx>
|
#include <OSD_Timer.hxx>
|
||||||
#include <Message.hxx>
|
#include <Message.hxx>
|
||||||
#include <Message_Messenger.hxx>
|
#include <Message_Messenger.hxx>
|
||||||
|
@ -331,7 +331,7 @@ Standard_Boolean OpenGl_PrimitiveArray::buildVBO (const Handle(OpenGl_Context)&
|
|||||||
aVboAttribs->initLink (myAttribs, 0, myAttribs->NbElements, GL_NONE);
|
aVboAttribs->initLink (myAttribs, 0, myAttribs->NbElements, GL_NONE);
|
||||||
if (!myIndices.IsNull())
|
if (!myIndices.IsNull())
|
||||||
{
|
{
|
||||||
Handle(OpenGl_VertexBufferCompat) aVboIndices = new OpenGl_VertexBufferCompat();
|
Handle(OpenGl_IndexBufferCompat) aVboIndices = new OpenGl_IndexBufferCompat();
|
||||||
switch (myIndices->Stride)
|
switch (myIndices->Stride)
|
||||||
{
|
{
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
#ifndef OpenGl_PrimitiveArray_Header
|
#ifndef OpenGl_PrimitiveArray_Header
|
||||||
#define OpenGl_PrimitiveArray_Header
|
#define OpenGl_PrimitiveArray_Header
|
||||||
|
|
||||||
#include <OpenGl_IndexBuffer.hxx>
|
|
||||||
|
|
||||||
#include <Aspect_InteriorStyle.hxx>
|
#include <Aspect_InteriorStyle.hxx>
|
||||||
#include <Aspect_TypeOfMarker.hxx>
|
#include <Aspect_TypeOfMarker.hxx>
|
||||||
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
|
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
|
||||||
@ -26,6 +24,8 @@
|
|||||||
|
|
||||||
#include <OpenGl_Element.hxx>
|
#include <OpenGl_Element.hxx>
|
||||||
|
|
||||||
|
class OpenGl_IndexBuffer;
|
||||||
|
class OpenGl_VertexBuffer;
|
||||||
class OpenGl_GraphicDriver;
|
class OpenGl_GraphicDriver;
|
||||||
|
|
||||||
//! Class for rendering of arbitrary primitive array.
|
//! Class for rendering of arbitrary primitive array.
|
||||||
@ -74,7 +74,7 @@ public:
|
|||||||
void Invalidate() const { myIsVboInit = Standard_False; }
|
void Invalidate() const { myIsVboInit = Standard_False; }
|
||||||
|
|
||||||
//! @return primitive type (GL_LINES, GL_TRIANGLES and others)
|
//! @return primitive type (GL_LINES, GL_TRIANGLES and others)
|
||||||
GLint DrawMode() const { return myDrawMode; }
|
Standard_Integer DrawMode() const { return myDrawMode; }
|
||||||
|
|
||||||
//! Return TRUE if primitive type generates shaded triangulation.
|
//! Return TRUE if primitive type generates shaded triangulation.
|
||||||
virtual Standard_Boolean IsFillDrawMode() const Standard_OVERRIDE { return myIsFillType; }
|
virtual Standard_Boolean IsFillDrawMode() const Standard_OVERRIDE { return myIsFillType; }
|
||||||
@ -101,7 +101,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//! Returns index VBO.
|
//! Returns index VBO.
|
||||||
const Handle(OpenGl_VertexBuffer)& IndexVbo() const { return myVboIndices; }
|
const Handle(OpenGl_IndexBuffer)& IndexVbo() const { return myVboIndices; }
|
||||||
|
|
||||||
//! Returns attributes VBO.
|
//! Returns attributes VBO.
|
||||||
const Handle(OpenGl_VertexBuffer)& AttributesVbo() const { return myVboAttribs; }
|
const Handle(OpenGl_VertexBuffer)& AttributesVbo() const { return myVboAttribs; }
|
||||||
@ -148,13 +148,13 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
mutable Handle(OpenGl_VertexBuffer) myVboIndices;
|
mutable Handle(OpenGl_IndexBuffer) myVboIndices;
|
||||||
mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
|
mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
|
||||||
|
|
||||||
mutable Handle(Graphic3d_IndexBuffer) myIndices;
|
mutable Handle(Graphic3d_IndexBuffer) myIndices;
|
||||||
mutable Handle(Graphic3d_Buffer) myAttribs;
|
mutable Handle(Graphic3d_Buffer) myAttribs;
|
||||||
mutable Handle(Graphic3d_BoundBuffer) myBounds;
|
mutable Handle(Graphic3d_BoundBuffer) myBounds;
|
||||||
GLshort myDrawMode;
|
short myDrawMode;
|
||||||
mutable Standard_Boolean myIsFillType;
|
mutable Standard_Boolean myIsFillType;
|
||||||
mutable Standard_Boolean myIsVboInit;
|
mutable Standard_Boolean myIsVboInit;
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <OpenGl_Sampler.hxx>
|
#include <OpenGl_Sampler.hxx>
|
||||||
|
|
||||||
#include <OpenGl_ArbSamplerObject.hxx>
|
#include <OpenGl_ArbSamplerObject.hxx>
|
||||||
|
#include <OpenGl_Context.hxx>
|
||||||
#include <OpenGl_Texture.hxx>
|
#include <OpenGl_Texture.hxx>
|
||||||
#include <Standard_Assert.hxx>
|
#include <Standard_Assert.hxx>
|
||||||
|
|
||||||
@ -152,9 +153,9 @@ void OpenGl_Sampler::Unbind (const Handle(OpenGl_Context)& theCtx,
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_Sampler::setParameter (const Handle(OpenGl_Context)& theCtx,
|
void OpenGl_Sampler::setParameter (const Handle(OpenGl_Context)& theCtx,
|
||||||
OpenGl_Sampler* theSampler,
|
OpenGl_Sampler* theSampler,
|
||||||
GLenum theTarget,
|
unsigned int theTarget,
|
||||||
GLenum theParam,
|
unsigned int theParam,
|
||||||
GLint theValue)
|
Standard_Integer theValue)
|
||||||
{
|
{
|
||||||
if (theSampler != NULL && theSampler->isValidSampler())
|
if (theSampler != NULL && theSampler->isValidSampler())
|
||||||
{
|
{
|
||||||
@ -186,7 +187,7 @@ void OpenGl_Sampler::SetParameters (const Handle(Graphic3d_TextureParams)& thePa
|
|||||||
void OpenGl_Sampler::applySamplerParams (const Handle(OpenGl_Context)& theCtx,
|
void OpenGl_Sampler::applySamplerParams (const Handle(OpenGl_Context)& theCtx,
|
||||||
const Handle(Graphic3d_TextureParams)& theParams,
|
const Handle(Graphic3d_TextureParams)& theParams,
|
||||||
OpenGl_Sampler* theSampler,
|
OpenGl_Sampler* theSampler,
|
||||||
const GLenum theTarget,
|
const unsigned int theTarget,
|
||||||
const Standard_Integer theMaxMipLevels)
|
const Standard_Integer theMaxMipLevels)
|
||||||
{
|
{
|
||||||
if (theSampler != NULL && theSampler->Parameters() == theParams)
|
if (theSampler != NULL && theSampler->Parameters() == theParams)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#ifndef _OpenGl_Sampler_Header
|
#ifndef _OpenGl_Sampler_Header
|
||||||
#define _OpenGl_Sampler_Header
|
#define _OpenGl_Sampler_Header
|
||||||
|
|
||||||
#include <OpenGl_Context.hxx>
|
#include <Graphic3d_TextureParams.hxx>
|
||||||
#include <OpenGl_Resource.hxx>
|
#include <OpenGl_Resource.hxx>
|
||||||
|
|
||||||
class OpenGl_Texture;
|
class OpenGl_Texture;
|
||||||
@ -31,7 +31,7 @@ class OpenGl_Sampler : public OpenGl_Resource
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//! Helpful constant defining invalid sampler identifier
|
//! Helpful constant defining invalid sampler identifier
|
||||||
static const GLuint NO_SAMPLER = 0;
|
static const unsigned int NO_SAMPLER = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -84,15 +84,15 @@ public:
|
|||||||
|
|
||||||
//! Sets specific sampler parameter.
|
//! Sets specific sampler parameter.
|
||||||
void SetParameter (const Handle(OpenGl_Context)& theCtx,
|
void SetParameter (const Handle(OpenGl_Context)& theCtx,
|
||||||
GLenum theTarget,
|
unsigned int theTarget,
|
||||||
GLenum theParam,
|
unsigned int theParam,
|
||||||
GLint theValue)
|
Standard_Integer theValue)
|
||||||
{
|
{
|
||||||
setParameter (theCtx, this, theTarget, theParam, theValue);
|
setParameter (theCtx, this, theTarget, theParam, theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Returns OpenGL sampler ID.
|
//! Returns OpenGL sampler ID.
|
||||||
GLuint SamplerID() const
|
unsigned int SamplerID() const
|
||||||
{
|
{
|
||||||
return mySamplerID;
|
return mySamplerID;
|
||||||
}
|
}
|
||||||
@ -124,9 +124,9 @@ protected:
|
|||||||
//! Sets specific sampler parameter.
|
//! Sets specific sampler parameter.
|
||||||
Standard_EXPORT static void setParameter (const Handle(OpenGl_Context)& theContext,
|
Standard_EXPORT static void setParameter (const Handle(OpenGl_Context)& theContext,
|
||||||
OpenGl_Sampler* theSampler,
|
OpenGl_Sampler* theSampler,
|
||||||
GLenum theTarget,
|
unsigned int theTarget,
|
||||||
GLenum theParam,
|
unsigned int theParam,
|
||||||
GLint theValue);
|
Standard_Integer theValue);
|
||||||
|
|
||||||
//! Apply sampler parameters.
|
//! Apply sampler parameters.
|
||||||
//! @param theCtx [in] active OpenGL context
|
//! @param theCtx [in] active OpenGL context
|
||||||
@ -138,7 +138,7 @@ protected:
|
|||||||
Standard_EXPORT static void applySamplerParams (const Handle(OpenGl_Context)& theCtx,
|
Standard_EXPORT static void applySamplerParams (const Handle(OpenGl_Context)& theCtx,
|
||||||
const Handle(Graphic3d_TextureParams)& theParams,
|
const Handle(Graphic3d_TextureParams)& theParams,
|
||||||
OpenGl_Sampler* theSampler,
|
OpenGl_Sampler* theSampler,
|
||||||
const GLenum theTarget,
|
const unsigned int theTarget,
|
||||||
const Standard_Integer theMaxMipLevel);
|
const Standard_Integer theMaxMipLevel);
|
||||||
|
|
||||||
//! Apply global texture state for deprecated OpenGL functionality.
|
//! Apply global texture state for deprecated OpenGL functionality.
|
||||||
@ -155,7 +155,7 @@ protected:
|
|||||||
|
|
||||||
Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
|
Handle(Graphic3d_TextureParams) myParams; //!< texture parameters
|
||||||
unsigned int mySamplerRevision; //!< modification counter of parameters related to sampler state
|
unsigned int mySamplerRevision; //!< modification counter of parameters related to sampler state
|
||||||
GLuint mySamplerID; //!< OpenGL sampler object ID
|
unsigned int mySamplerID; //!< OpenGL sampler object ID
|
||||||
bool myIsImmutable; //!< immutable flag preventing further modifications of sampler parameters, FALSE by default
|
bool myIsImmutable; //!< immutable flag preventing further modifications of sampler parameters, FALSE by default
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -13,16 +13,18 @@
|
|||||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
#include <OSD_Timer.hxx>
|
#include <OpenGl_SceneGeometry.hxx>
|
||||||
|
|
||||||
|
#include <Graphic3d_GraphicDriver.hxx>
|
||||||
#include <OSD_Parallel.hxx>
|
#include <OSD_Parallel.hxx>
|
||||||
|
#include <OSD_Timer.hxx>
|
||||||
#include <Standard_Assert.hxx>
|
#include <Standard_Assert.hxx>
|
||||||
#include <OpenGl_ArbTexBindless.hxx>
|
#include <OpenGl_ArbTexBindless.hxx>
|
||||||
#include <OpenGl_PrimitiveArray.hxx>
|
#include <OpenGl_PrimitiveArray.hxx>
|
||||||
#include <OpenGl_SceneGeometry.hxx>
|
|
||||||
#include <OpenGl_Structure.hxx>
|
#include <OpenGl_Structure.hxx>
|
||||||
#include <Graphic3d_GraphicDriver.hxx>
|
#include <OpenGl_TextureBuffer.hxx>
|
||||||
|
|
||||||
//! Use this macro to output BVH profiling info
|
// Use this macro to output BVH profiling info
|
||||||
// #define RAY_TRACE_PRINT_INFO
|
// #define RAY_TRACE_PRINT_INFO
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <BVH_Triangulation.hxx>
|
#include <BVH_Triangulation.hxx>
|
||||||
#include <BVH_BinnedBuilder.hxx>
|
#include <BVH_BinnedBuilder.hxx>
|
||||||
#include <NCollection_StdAllocator.hxx>
|
#include <NCollection_StdAllocator.hxx>
|
||||||
#include <OpenGl_TextureBufferArb.hxx>
|
|
||||||
#include <OpenGl_Texture.hxx>
|
#include <OpenGl_Texture.hxx>
|
||||||
#include <OpenGl_Sampler.hxx>
|
#include <OpenGl_Sampler.hxx>
|
||||||
|
|
||||||
|
@ -18,12 +18,15 @@
|
|||||||
|
|
||||||
#include <Graphic3d_ShaderManager.hxx>
|
#include <Graphic3d_ShaderManager.hxx>
|
||||||
#include <NCollection_Sequence.hxx>
|
#include <NCollection_Sequence.hxx>
|
||||||
|
#include <OpenGl_Aspects.hxx>
|
||||||
|
#include <OpenGl_Context.hxx>
|
||||||
|
#include <OpenGl_MaterialState.hxx>
|
||||||
#include <OpenGl_PBREnvironment.hxx>
|
#include <OpenGl_PBREnvironment.hxx>
|
||||||
#include <OpenGl_SetOfShaderPrograms.hxx>
|
#include <OpenGl_SetOfShaderPrograms.hxx>
|
||||||
|
#include <OpenGl_ShaderProgram.hxx>
|
||||||
#include <OpenGl_ShaderStates.hxx>
|
#include <OpenGl_ShaderStates.hxx>
|
||||||
#include <OpenGl_Aspects.hxx>
|
|
||||||
#include <OpenGl_MaterialState.hxx>
|
|
||||||
#include <OpenGl_Texture.hxx>
|
#include <OpenGl_Texture.hxx>
|
||||||
|
#include <OpenGl_TextureSet.hxx>
|
||||||
|
|
||||||
class OpenGl_View;
|
class OpenGl_View;
|
||||||
class OpenGl_VertexBuffer;
|
class OpenGl_VertexBuffer;
|
||||||
|
@ -707,10 +707,10 @@ bool OpenGl_Texture::InitCompressed (const Handle(OpenGl_Context)& theCtx,
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
bool OpenGl_Texture::Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
|
bool OpenGl_Texture::Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
|
||||||
const GLsizei theNbSamples,
|
const Standard_Integer theNbSamples,
|
||||||
const GLint theTextFormat,
|
const Standard_Integer theTextFormat,
|
||||||
const GLsizei theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const GLsizei theSizeY)
|
const Standard_Integer theSizeY)
|
||||||
{
|
{
|
||||||
if (!Create (theCtx)
|
if (!Create (theCtx)
|
||||||
|| theNbSamples > theCtx->MaxMsaaSamples()
|
|| theNbSamples > theCtx->MaxMsaaSamples()
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#define _OpenGl_Texture_H__
|
#define _OpenGl_Texture_H__
|
||||||
|
|
||||||
#include <Graphic3d_CubeMap.hxx>
|
#include <Graphic3d_CubeMap.hxx>
|
||||||
|
#include <Graphic3d_Vec3.hxx>
|
||||||
#include <OpenGl_TextureFormat.hxx>
|
#include <OpenGl_TextureFormat.hxx>
|
||||||
#include <OpenGl_NamedResource.hxx>
|
#include <OpenGl_NamedResource.hxx>
|
||||||
#include <OpenGl_Sampler.hxx>
|
#include <OpenGl_Sampler.hxx>
|
||||||
@ -32,7 +33,7 @@ class OpenGl_Texture : public OpenGl_NamedResource
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//! Helpful constants
|
//! Helpful constants
|
||||||
static const GLuint NO_TEXTURE = 0;
|
static const unsigned int NO_TEXTURE = 0;
|
||||||
|
|
||||||
//! Return pixel size of pixel format in bytes.
|
//! Return pixel size of pixel format in bytes.
|
||||||
//! Note that this method considers that OpenGL natively supports this pixel format,
|
//! Note that this method considers that OpenGL natively supports this pixel format,
|
||||||
@ -52,7 +53,7 @@ public:
|
|||||||
virtual bool IsValid() const { return myTextureId != NO_TEXTURE; }
|
virtual bool IsValid() const { return myTextureId != NO_TEXTURE; }
|
||||||
|
|
||||||
//! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)
|
//! @return target to which the texture is bound (GL_TEXTURE_1D, GL_TEXTURE_2D)
|
||||||
GLenum GetTarget() const { return myTarget; }
|
unsigned int GetTarget() const { return myTarget; }
|
||||||
|
|
||||||
//! @return texture width (0 LOD)
|
//! @return texture width (0 LOD)
|
||||||
GLsizei SizeX() const { return mySizeX; }
|
GLsizei SizeX() const { return mySizeX; }
|
||||||
@ -61,13 +62,13 @@ public:
|
|||||||
GLsizei SizeY() const { return mySizeY; }
|
GLsizei SizeY() const { return mySizeY; }
|
||||||
|
|
||||||
//! @return texture ID
|
//! @return texture ID
|
||||||
GLuint TextureId() const { return myTextureId; }
|
unsigned int TextureId() const { return myTextureId; }
|
||||||
|
|
||||||
//! @return texture format (not sized)
|
//! @return texture format (not sized)
|
||||||
GLenum GetFormat() const { return myTextFormat; }
|
unsigned int GetFormat() const { return myTextFormat; }
|
||||||
|
|
||||||
//! @return texture format (sized)
|
//! @return texture format (sized)
|
||||||
GLint SizedFormat() const { return mySizedFormat; }
|
Standard_Integer SizedFormat() const { return mySizedFormat; }
|
||||||
|
|
||||||
//! Return true for GL_RED and GL_ALPHA formats.
|
//! Return true for GL_RED and GL_ALPHA formats.
|
||||||
bool IsAlpha() const { return myIsAlpha; }
|
bool IsAlpha() const { return myIsAlpha; }
|
||||||
@ -158,10 +159,10 @@ public:
|
|||||||
|
|
||||||
//! Initialize the 2D multisampling texture using glTexImage2DMultisample().
|
//! Initialize the 2D multisampling texture using glTexImage2DMultisample().
|
||||||
Standard_EXPORT bool Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
|
Standard_EXPORT bool Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
|
||||||
const GLsizei theNbSamples,
|
const Standard_Integer theNbSamples,
|
||||||
const GLint theTextFormat,
|
const Standard_Integer theTextFormat,
|
||||||
const GLsizei theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const GLsizei theSizeY);
|
const Standard_Integer theSizeY);
|
||||||
|
|
||||||
//! Allocates texture rectangle with specified format and size.
|
//! Allocates texture rectangle with specified format and size.
|
||||||
//! \note Texture data is not initialized (will contain trash).
|
//! \note Texture data is not initialized (will contain trash).
|
||||||
@ -209,9 +210,9 @@ public:
|
|||||||
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")
|
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")
|
||||||
static bool GetDataFormat (const Handle(OpenGl_Context)& theCtx,
|
static bool GetDataFormat (const Handle(OpenGl_Context)& theCtx,
|
||||||
const Image_Format theFormat,
|
const Image_Format theFormat,
|
||||||
GLint& theTextFormat,
|
Standard_Integer& theTextFormat,
|
||||||
GLenum& thePixelFormat,
|
unsigned int& thePixelFormat,
|
||||||
GLenum& theDataType)
|
unsigned int& theDataType)
|
||||||
{
|
{
|
||||||
OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindFormat (theCtx, theFormat, false);
|
OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindFormat (theCtx, theFormat, false);
|
||||||
theTextFormat = aFormat.InternalFormat();
|
theTextFormat = aFormat.InternalFormat();
|
||||||
@ -223,9 +224,9 @@ public:
|
|||||||
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")
|
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat::FindFormat() should be used instead")
|
||||||
static bool GetDataFormat (const Handle(OpenGl_Context)& theCtx,
|
static bool GetDataFormat (const Handle(OpenGl_Context)& theCtx,
|
||||||
const Image_PixMap& theData,
|
const Image_PixMap& theData,
|
||||||
GLint& theTextFormat,
|
Standard_Integer& theTextFormat,
|
||||||
GLenum& thePixelFormat,
|
unsigned int& thePixelFormat,
|
||||||
GLenum& theDataType)
|
unsigned int& theDataType)
|
||||||
{
|
{
|
||||||
OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindFormat (theCtx, theData.Format(), false);
|
OpenGl_TextureFormat aFormat = OpenGl_TextureFormat::FindFormat (theCtx, theData.Format(), false);
|
||||||
theTextFormat = aFormat.InternalFormat();
|
theTextFormat = aFormat.InternalFormat();
|
||||||
@ -236,11 +237,11 @@ public:
|
|||||||
|
|
||||||
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")
|
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")
|
||||||
bool Init (const Handle(OpenGl_Context)& theCtx,
|
bool Init (const Handle(OpenGl_Context)& theCtx,
|
||||||
const GLint theTextFormat,
|
const Standard_Integer theTextFormat,
|
||||||
const GLenum thePixelFormat,
|
const unsigned int thePixelFormat,
|
||||||
const GLenum theDataType,
|
const unsigned int theDataType,
|
||||||
const GLsizei theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const GLsizei theSizeY,
|
const Standard_Integer theSizeY,
|
||||||
const Graphic3d_TypeOfTexture theType,
|
const Graphic3d_TypeOfTexture theType,
|
||||||
const Image_PixMap* theImage = NULL)
|
const Image_PixMap* theImage = NULL)
|
||||||
{
|
{
|
||||||
@ -261,9 +262,9 @@ public:
|
|||||||
|
|
||||||
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")
|
Standard_DEPRECATED("Deprecated method, OpenGl_TextureFormat should be passed instead of separate parameters")
|
||||||
bool Init3D (const Handle(OpenGl_Context)& theCtx,
|
bool Init3D (const Handle(OpenGl_Context)& theCtx,
|
||||||
const GLint theTextFormat,
|
const Standard_Integer theTextFormat,
|
||||||
const GLenum thePixelFormat,
|
const unsigned int thePixelFormat,
|
||||||
const GLenum theDataType,
|
const unsigned int theDataType,
|
||||||
const Standard_Integer theSizeX,
|
const Standard_Integer theSizeX,
|
||||||
const Standard_Integer theSizeY,
|
const Standard_Integer theSizeY,
|
||||||
const Standard_Integer theSizeZ,
|
const Standard_Integer theSizeZ,
|
||||||
@ -278,7 +279,7 @@ public:
|
|||||||
|
|
||||||
//! Initializes 6 sides of cubemap.
|
//! Initializes 6 sides of cubemap.
|
||||||
//! If theCubeMap is not NULL then size and format will be taken from it and corresponding arguments will be ignored.
|
//! If theCubeMap is not NULL then size and format will be taken from it and corresponding arguments will be ignored.
|
||||||
//! Otherwise this parametres will be taken from arguments.
|
//! Otherwise this parameters will be taken from arguments.
|
||||||
//! @param theCtx [in] active OpenGL context
|
//! @param theCtx [in] active OpenGL context
|
||||||
//! @param theCubeMap [in] cubemap definition, can be NULL
|
//! @param theCubeMap [in] cubemap definition, can be NULL
|
||||||
//! @param theSize [in] cubemap dimensions
|
//! @param theSize [in] cubemap dimensions
|
||||||
@ -301,13 +302,13 @@ protected:
|
|||||||
|
|
||||||
Handle(OpenGl_Sampler) mySampler; //!< texture sampler
|
Handle(OpenGl_Sampler) mySampler; //!< texture sampler
|
||||||
Standard_Size myRevision; //!< revision of associated data source
|
Standard_Size myRevision; //!< revision of associated data source
|
||||||
GLuint myTextureId; //!< GL resource ID
|
unsigned int myTextureId; //!< GL resource ID
|
||||||
GLenum myTarget; //!< GL_TEXTURE_1D/GL_TEXTURE_2D/GL_TEXTURE_3D
|
unsigned int myTarget; //!< GL_TEXTURE_1D/GL_TEXTURE_2D/GL_TEXTURE_3D
|
||||||
GLsizei mySizeX; //!< texture width
|
Standard_Integer mySizeX; //!< texture width
|
||||||
GLsizei mySizeY; //!< texture height
|
Standard_Integer mySizeY; //!< texture height
|
||||||
GLsizei mySizeZ; //!< texture depth
|
Standard_Integer mySizeZ; //!< texture depth
|
||||||
GLenum myTextFormat; //!< texture format - GL_RGB, GL_RGBA,...
|
unsigned int myTextFormat; //!< texture format - GL_RGB, GL_RGBA,...
|
||||||
GLint mySizedFormat;//!< internal (sized) texture format
|
Standard_Integer mySizedFormat;//!< internal (sized) texture format
|
||||||
Standard_Integer myNbSamples; //!< number of MSAA samples
|
Standard_Integer myNbSamples; //!< number of MSAA samples
|
||||||
Standard_Integer myMaxMipLevel;//!< upper mipmap level index (0 means no mipmaps)
|
Standard_Integer myMaxMipLevel;//!< upper mipmap level index (0 means no mipmaps)
|
||||||
bool myIsAlpha; //!< indicates alpha format
|
bool myIsAlpha; //!< indicates alpha format
|
||||||
|
@ -12,20 +12,21 @@
|
|||||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
#include <OpenGl_TextureBufferArb.hxx>
|
#include <OpenGl_TextureBuffer.hxx>
|
||||||
|
|
||||||
|
#include <OpenGl_ArbTBO.hxx>
|
||||||
|
#include <OpenGl_GlCore20.hxx>
|
||||||
#include <OpenGl_Context.hxx>
|
#include <OpenGl_Context.hxx>
|
||||||
#include <Standard_Assert.hxx>
|
#include <Standard_Assert.hxx>
|
||||||
|
|
||||||
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_TextureBuffer, OpenGl_Buffer)
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_TextureBufferArb,OpenGl_VertexBuffer)
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : OpenGl_TextureBufferArb
|
// function : OpenGl_TextureBuffer
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
OpenGl_TextureBufferArb::OpenGl_TextureBufferArb()
|
OpenGl_TextureBuffer::OpenGl_TextureBuffer()
|
||||||
: OpenGl_VertexBuffer(),
|
: OpenGl_Buffer(),
|
||||||
myTextureId (NO_TEXTURE),
|
myTextureId (NO_TEXTURE),
|
||||||
myTexFormat (GL_RGBA32F)
|
myTexFormat (GL_RGBA32F)
|
||||||
{
|
{
|
||||||
@ -33,10 +34,10 @@ OpenGl_TextureBufferArb::OpenGl_TextureBufferArb()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : ~OpenGl_TextureBufferArb
|
// function : ~OpenGl_TextureBuffer
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
OpenGl_TextureBufferArb::~OpenGl_TextureBufferArb()
|
OpenGl_TextureBuffer::~OpenGl_TextureBuffer()
|
||||||
{
|
{
|
||||||
Release (NULL);
|
Release (NULL);
|
||||||
}
|
}
|
||||||
@ -45,7 +46,7 @@ OpenGl_TextureBufferArb::~OpenGl_TextureBufferArb()
|
|||||||
// function : GetTarget
|
// function : GetTarget
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
GLenum OpenGl_TextureBufferArb::GetTarget() const
|
unsigned int OpenGl_TextureBuffer::GetTarget() const
|
||||||
{
|
{
|
||||||
return GL_TEXTURE_BUFFER; // GL_TEXTURE_BUFFER for OpenGL 3.1+, OpenGL ES 3.2
|
return GL_TEXTURE_BUFFER; // GL_TEXTURE_BUFFER for OpenGL 3.1+, OpenGL ES 3.2
|
||||||
}
|
}
|
||||||
@ -54,37 +55,37 @@ GLenum OpenGl_TextureBufferArb::GetTarget() const
|
|||||||
// function : Release
|
// function : Release
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_TextureBufferArb::Release (OpenGl_Context* theGlCtx)
|
void OpenGl_TextureBuffer::Release (OpenGl_Context* theGlCtx)
|
||||||
{
|
{
|
||||||
if (myTextureId != NO_TEXTURE)
|
if (myTextureId != NO_TEXTURE)
|
||||||
{
|
{
|
||||||
// application can not handle this case by exception - this is bug in code
|
// application can not handle this case by exception - this is bug in code
|
||||||
Standard_ASSERT_RETURN (theGlCtx != NULL,
|
Standard_ASSERT_RETURN (theGlCtx != NULL,
|
||||||
"OpenGl_TextureBufferExt destroyed without GL context! Possible GPU memory leakage...",);
|
"OpenGl_TextureBuffer destroyed without GL context! Possible GPU memory leakage...",);
|
||||||
|
|
||||||
if (theGlCtx->IsValid())
|
if (theGlCtx->IsValid())
|
||||||
{
|
{
|
||||||
glDeleteTextures (1, &myTextureId);
|
theGlCtx->core20fwd->glDeleteTextures (1, &myTextureId);
|
||||||
}
|
}
|
||||||
myTextureId = NO_TEXTURE;
|
myTextureId = NO_TEXTURE;
|
||||||
}
|
}
|
||||||
OpenGl_VertexBuffer::Release (theGlCtx);
|
base_type::Release (theGlCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : Create
|
// function : Create
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
bool OpenGl_TextureBufferArb::Create (const Handle(OpenGl_Context)& theGlCtx)
|
bool OpenGl_TextureBuffer::Create (const Handle(OpenGl_Context)& theGlCtx)
|
||||||
{
|
{
|
||||||
if (!OpenGl_VertexBuffer::Create (theGlCtx))
|
if (!base_type::Create (theGlCtx))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myTextureId == NO_TEXTURE)
|
if (myTextureId == NO_TEXTURE)
|
||||||
{
|
{
|
||||||
glGenTextures (1, &myTextureId);
|
theGlCtx->core20fwd->glGenTextures (1, &myTextureId);
|
||||||
}
|
}
|
||||||
return myTextureId != NO_TEXTURE;
|
return myTextureId != NO_TEXTURE;
|
||||||
}
|
}
|
||||||
@ -93,10 +94,10 @@ bool OpenGl_TextureBufferArb::Create (const Handle(OpenGl_Context)& theGlCtx)
|
|||||||
// function : Init
|
// function : Init
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
bool OpenGl_TextureBuffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theComponentsNb,
|
const unsigned int theComponentsNb,
|
||||||
const GLsizei theElemsNb,
|
const Standard_Integer theElemsNb,
|
||||||
const GLfloat* theData)
|
const float* theData)
|
||||||
{
|
{
|
||||||
if (theGlCtx->arbTBO == NULL)
|
if (theGlCtx->arbTBO == NULL)
|
||||||
{
|
{
|
||||||
@ -114,7 +115,7 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (!Create (theGlCtx)
|
else if (!Create (theGlCtx)
|
||||||
|| !OpenGl_VertexBuffer::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
|| !base_type::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -139,10 +140,10 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
// function : Init
|
// function : Init
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
bool OpenGl_TextureBuffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theComponentsNb,
|
const unsigned int theComponentsNb,
|
||||||
const GLsizei theElemsNb,
|
const Standard_Integer theElemsNb,
|
||||||
const GLuint* theData)
|
const unsigned int* theData)
|
||||||
{
|
{
|
||||||
if (theGlCtx->arbTBO == NULL)
|
if (theGlCtx->arbTBO == NULL)
|
||||||
{
|
{
|
||||||
@ -160,7 +161,7 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (!Create (theGlCtx)
|
else if (!Create (theGlCtx)
|
||||||
|| !OpenGl_VertexBuffer::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
|| !base_type::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -185,10 +186,10 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
// function : Init
|
// function : Init
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
bool OpenGl_TextureBuffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theComponentsNb,
|
const unsigned int theComponentsNb,
|
||||||
const GLsizei theElemsNb,
|
const Standard_Integer theElemsNb,
|
||||||
const GLushort* theData)
|
const unsigned short* theData)
|
||||||
{
|
{
|
||||||
if (theGlCtx->arbTBO == NULL)
|
if (theGlCtx->arbTBO == NULL)
|
||||||
{
|
{
|
||||||
@ -201,7 +202,7 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (!Create (theGlCtx)
|
else if (!Create (theGlCtx)
|
||||||
|| !OpenGl_VertexBuffer::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
|| !base_type::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -226,10 +227,10 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
// function : Init
|
// function : Init
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
bool OpenGl_TextureBuffer::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theComponentsNb,
|
const unsigned int theComponentsNb,
|
||||||
const GLsizei theElemsNb,
|
const Standard_Integer theElemsNb,
|
||||||
const GLubyte* theData)
|
const Standard_Byte* theData)
|
||||||
{
|
{
|
||||||
if (theGlCtx->arbTBO == NULL)
|
if (theGlCtx->arbTBO == NULL)
|
||||||
{
|
{
|
||||||
@ -242,7 +243,7 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (!Create (theGlCtx)
|
else if (!Create (theGlCtx)
|
||||||
|| !OpenGl_VertexBuffer::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
|| !base_type::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -267,20 +268,20 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
|||||||
// function : BindTexture
|
// function : BindTexture
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_TextureBufferArb::BindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
void OpenGl_TextureBuffer::BindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const Graphic3d_TextureUnit theTextureUnit) const
|
const Graphic3d_TextureUnit theTextureUnit) const
|
||||||
{
|
{
|
||||||
theGlCtx->core20fwd->glActiveTexture (GL_TEXTURE0 + theTextureUnit);
|
theGlCtx->core20fwd->glActiveTexture (GL_TEXTURE0 + theTextureUnit);
|
||||||
glBindTexture (GetTarget(), myTextureId);
|
theGlCtx->core20fwd->glBindTexture (GetTarget(), myTextureId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : UnbindTexture
|
// function : UnbindTexture
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_TextureBufferArb::UnbindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
void OpenGl_TextureBuffer::UnbindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const Graphic3d_TextureUnit theTextureUnit) const
|
const Graphic3d_TextureUnit theTextureUnit) const
|
||||||
{
|
{
|
||||||
theGlCtx->core20fwd->glActiveTexture (GL_TEXTURE0 + theTextureUnit);
|
theGlCtx->core20fwd->glActiveTexture (GL_TEXTURE0 + theTextureUnit);
|
||||||
glBindTexture (GetTarget(), NO_TEXTURE);
|
theGlCtx->core20fwd->glBindTexture (GetTarget(), NO_TEXTURE);
|
||||||
}
|
}
|
116
src/OpenGl/OpenGl_TextureBuffer.hxx
Normal file
116
src/OpenGl/OpenGl_TextureBuffer.hxx
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
// Created by: Kirill GAVRILOV
|
||||||
|
// Copyright (c) 2013-2014 OPEN CASCADE SAS
|
||||||
|
//
|
||||||
|
// This file is part of Open CASCADE Technology software library.
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||||
|
// by the Free Software Foundation, with special exception defined in the file
|
||||||
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||||
|
// distribution for complete text of the license and disclaimer of any warranty.
|
||||||
|
//
|
||||||
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
|
#ifndef _OpenGl_TextureBuffer_H__
|
||||||
|
#define _OpenGl_TextureBuffer_H__
|
||||||
|
|
||||||
|
#include <Graphic3d_TextureUnit.hxx>
|
||||||
|
#include <OpenGl_Buffer.hxx>
|
||||||
|
|
||||||
|
//! Texture Buffer Object.
|
||||||
|
//! This is a special 1D texture that VBO-style initialized.
|
||||||
|
//! The main differences from general 1D texture:
|
||||||
|
//! - no interpolation between field;
|
||||||
|
//! - greater sizes;
|
||||||
|
//! - special sampler object in GLSL shader to access data by index.
|
||||||
|
//!
|
||||||
|
//! Notice that though TBO is inherited from VBO this is to unify design
|
||||||
|
//! user shouldn't cast it to base class and all really useful methods
|
||||||
|
//! are declared in this class.
|
||||||
|
class OpenGl_TextureBuffer : public OpenGl_Buffer
|
||||||
|
{
|
||||||
|
DEFINE_STANDARD_RTTIEXT(OpenGl_TextureBuffer, OpenGl_Buffer)
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Helpful constants
|
||||||
|
static const unsigned int NO_TEXTURE = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Create uninitialized TBO.
|
||||||
|
Standard_EXPORT OpenGl_TextureBuffer();
|
||||||
|
|
||||||
|
//! Destroy object, will throw exception if GPU memory not released with Release() before.
|
||||||
|
Standard_EXPORT virtual ~OpenGl_TextureBuffer();
|
||||||
|
|
||||||
|
//! Override VBO target
|
||||||
|
Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Returns true if TBO is valid.
|
||||||
|
//! Notice that no any real GL call is performed!
|
||||||
|
bool IsValid() const
|
||||||
|
{
|
||||||
|
return OpenGl_Buffer::IsValid()
|
||||||
|
&& myTextureId != NO_TEXTURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Destroy object - will release GPU memory if any.
|
||||||
|
Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Creates VBO and Texture names (ids) if not yet generated.
|
||||||
|
//! Data should be initialized by another method.
|
||||||
|
Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Perform TBO initialization with specified data.
|
||||||
|
//! Existing data will be deleted.
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const float* theData);
|
||||||
|
|
||||||
|
//! Perform TBO initialization with specified data.
|
||||||
|
//! Existing data will be deleted.
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned int* theData);
|
||||||
|
|
||||||
|
//! Perform TBO initialization with specified data.
|
||||||
|
//! Existing data will be deleted.
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const unsigned short* theData);
|
||||||
|
|
||||||
|
//! Perform TBO initialization with specified data.
|
||||||
|
//! Existing data will be deleted.
|
||||||
|
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const unsigned int theComponentsNb,
|
||||||
|
const Standard_Integer theElemsNb,
|
||||||
|
const Standard_Byte* theData);
|
||||||
|
|
||||||
|
//! Bind TBO to specified Texture Unit.
|
||||||
|
Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Graphic3d_TextureUnit theTextureUnit) const;
|
||||||
|
|
||||||
|
//! Unbind TBO.
|
||||||
|
Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
|
const Graphic3d_TextureUnit theTextureUnit) const;
|
||||||
|
|
||||||
|
//! Returns name of TBO.
|
||||||
|
unsigned int TextureId() const { return myTextureId; }
|
||||||
|
|
||||||
|
//! Returns internal texture format.
|
||||||
|
unsigned int TextureFormat() const { return myTexFormat; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
unsigned int myTextureId; //!< texture id
|
||||||
|
unsigned int myTexFormat; //!< internal texture format
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_STANDARD_HANDLE(OpenGl_TextureBuffer, OpenGl_Buffer)
|
||||||
|
|
||||||
|
#endif // _OpenGl_TextureBuffer_H__
|
@ -15,102 +15,9 @@
|
|||||||
#ifndef _OpenGl_TextureBufferArb_H__
|
#ifndef _OpenGl_TextureBufferArb_H__
|
||||||
#define _OpenGl_TextureBufferArb_H__
|
#define _OpenGl_TextureBufferArb_H__
|
||||||
|
|
||||||
#include <OpenGl_VertexBuffer.hxx>
|
#include <OpenGl_TextureBuffer.hxx>
|
||||||
#include <OpenGl_ArbTBO.hxx>
|
|
||||||
|
|
||||||
//! Texture Buffer Object.
|
Standard_DEPRECATED("Obsolete alias - OpenGl_TextureBuffer should be used instead")
|
||||||
//! This is a special 1D texture that VBO-style initialized.
|
typedef OpenGl_TextureBuffer OpenGl_TextureBufferArb;
|
||||||
//! The main differences from general 1D texture:
|
|
||||||
//! - no interpolation between field;
|
|
||||||
//! - greater sizes;
|
|
||||||
//! - special sampler object in GLSL shader to access data by index.
|
|
||||||
//!
|
|
||||||
//! Notice that though TBO is inherited from VBO this is to unify design
|
|
||||||
//! user shouldn't cast it to base class and all really useful methods
|
|
||||||
//! are declared in this class.
|
|
||||||
class OpenGl_TextureBufferArb : public OpenGl_VertexBuffer
|
|
||||||
{
|
|
||||||
DEFINE_STANDARD_RTTIEXT(OpenGl_TextureBufferArb, OpenGl_VertexBuffer)
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Helpful constants
|
|
||||||
static const GLuint NO_TEXTURE = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Create uninitialized TBO.
|
|
||||||
Standard_EXPORT OpenGl_TextureBufferArb();
|
|
||||||
|
|
||||||
//! Destroy object, will throw exception if GPU memory not released with Release() before.
|
|
||||||
Standard_EXPORT virtual ~OpenGl_TextureBufferArb();
|
|
||||||
|
|
||||||
//! Override VBO target
|
|
||||||
Standard_EXPORT virtual GLenum GetTarget() const Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Returns true if TBO is valid.
|
|
||||||
//! Notice that no any real GL call is performed!
|
|
||||||
bool IsValid() const
|
|
||||||
{
|
|
||||||
return OpenGl_VertexBuffer::IsValid()
|
|
||||||
&& myTextureId != NO_TEXTURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Destroy object - will release GPU memory if any.
|
|
||||||
Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Creates VBO and Texture names (ids) if not yet generated.
|
|
||||||
//! Data should be initialized by another method.
|
|
||||||
Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Perform TBO initialization with specified data.
|
|
||||||
//! Existing data will be deleted.
|
|
||||||
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLfloat* theData);
|
|
||||||
|
|
||||||
//! Perform TBO initialization with specified data.
|
|
||||||
//! Existing data will be deleted.
|
|
||||||
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLuint* theData);
|
|
||||||
|
|
||||||
//! Perform TBO initialization with specified data.
|
|
||||||
//! Existing data will be deleted.
|
|
||||||
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLushort* theData);
|
|
||||||
|
|
||||||
//! Perform TBO initialization with specified data.
|
|
||||||
//! Existing data will be deleted.
|
|
||||||
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLubyte* theData);
|
|
||||||
|
|
||||||
//! Bind TBO to specified Texture Unit.
|
|
||||||
Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const Graphic3d_TextureUnit theTextureUnit) const;
|
|
||||||
|
|
||||||
//! Unbind TBO.
|
|
||||||
Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const Graphic3d_TextureUnit theTextureUnit) const;
|
|
||||||
|
|
||||||
//! Returns name of TBO.
|
|
||||||
GLuint TextureId() const { return myTextureId; }
|
|
||||||
|
|
||||||
//! Returns internal texture format.
|
|
||||||
GLenum TextureFormat() const { return myTexFormat; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
GLuint myTextureId; //!< texture id
|
|
||||||
GLenum myTexFormat; //!< internal texture format
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_STANDARD_HANDLE(OpenGl_TextureBufferArb, OpenGl_VertexBuffer)
|
|
||||||
|
|
||||||
#endif // _OpenGl_TextureBufferArb_H__
|
#endif // _OpenGl_TextureBufferArb_H__
|
||||||
|
35
src/OpenGl/OpenGl_UniformBuffer.cxx
Normal file
35
src/OpenGl/OpenGl_UniformBuffer.cxx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2021 OPEN CASCADE SAS
|
||||||
|
//
|
||||||
|
// This file is part of Open CASCADE Technology software library.
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||||
|
// by the Free Software Foundation, with special exception defined in the file
|
||||||
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||||
|
// distribution for complete text of the license and disclaimer of any warranty.
|
||||||
|
//
|
||||||
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
|
#include <OpenGl_UniformBuffer.hxx>
|
||||||
|
|
||||||
|
#include <OpenGl_Context.hxx>
|
||||||
|
#include <Standard_Assert.hxx>
|
||||||
|
|
||||||
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_UniformBuffer, OpenGl_Buffer)
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : OpenGl_UniformBuffer
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
OpenGl_UniformBuffer::OpenGl_UniformBuffer()
|
||||||
|
: OpenGl_Buffer() {}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : GetTarget
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
unsigned int OpenGl_UniformBuffer::GetTarget() const
|
||||||
|
{
|
||||||
|
return GL_UNIFORM_BUFFER;
|
||||||
|
}
|
37
src/OpenGl/OpenGl_UniformBuffer.hxx
Normal file
37
src/OpenGl/OpenGl_UniformBuffer.hxx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (c) 2021 OPEN CASCADE SAS
|
||||||
|
//
|
||||||
|
// This file is part of Open CASCADE Technology software library.
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||||
|
// by the Free Software Foundation, with special exception defined in the file
|
||||||
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||||
|
// distribution for complete text of the license and disclaimer of any warranty.
|
||||||
|
//
|
||||||
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
|
#ifndef _OpenGl_UniformBuffer_H__
|
||||||
|
#define _OpenGl_UniformBuffer_H__
|
||||||
|
|
||||||
|
#include <OpenGl_Buffer.hxx>
|
||||||
|
|
||||||
|
//! Uniform buffer object.
|
||||||
|
class OpenGl_UniformBuffer : public OpenGl_Buffer
|
||||||
|
{
|
||||||
|
DEFINE_STANDARD_RTTIEXT(OpenGl_UniformBuffer, OpenGl_Buffer)
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Empty constructor.
|
||||||
|
Standard_EXPORT OpenGl_UniformBuffer();
|
||||||
|
|
||||||
|
//! Return buffer object target (GL_UNIFORM_BUFFER).
|
||||||
|
Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
|
||||||
|
|
||||||
|
using OpenGl_Buffer::BindBufferBase;
|
||||||
|
using OpenGl_Buffer::UnbindBufferBase;
|
||||||
|
using OpenGl_Buffer::BindBufferRange;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _OpenGl_UniformBuffer_H__
|
@ -18,34 +18,13 @@
|
|||||||
#include <OpenGl_ShaderManager.hxx>
|
#include <OpenGl_ShaderManager.hxx>
|
||||||
#include <Standard_Assert.hxx>
|
#include <Standard_Assert.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_VertexBuffer,OpenGl_Resource)
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_VertexBuffer, OpenGl_Buffer)
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : FormatTarget
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
TCollection_AsciiString OpenGl_VertexBuffer::FormatTarget (GLenum theTarget)
|
|
||||||
{
|
|
||||||
switch (theTarget)
|
|
||||||
{
|
|
||||||
case GL_ARRAY_BUFFER: return "GL_ARRAY_BUFFER";
|
|
||||||
case GL_ELEMENT_ARRAY_BUFFER: return "GL_ELEMENT_ARRAY_BUFFER";
|
|
||||||
case GL_TEXTURE_BUFFER: return "GL_TEXTURE_BUFFER";
|
|
||||||
}
|
|
||||||
return OpenGl_Context::FormatGlEnumHex (theTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : OpenGl_VertexBuffer
|
// function : OpenGl_VertexBuffer
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
OpenGl_VertexBuffer::OpenGl_VertexBuffer()
|
OpenGl_VertexBuffer::OpenGl_VertexBuffer()
|
||||||
: OpenGl_Resource(),
|
|
||||||
myOffset (NULL),
|
|
||||||
myBufferId (NO_BUFFER),
|
|
||||||
myComponentsNb (4),
|
|
||||||
myElemsNb (0),
|
|
||||||
myDataType (GL_FLOAT)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@ -56,178 +35,24 @@ OpenGl_VertexBuffer::OpenGl_VertexBuffer()
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
OpenGl_VertexBuffer::~OpenGl_VertexBuffer()
|
OpenGl_VertexBuffer::~OpenGl_VertexBuffer()
|
||||||
{
|
{
|
||||||
Release (NULL);
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : GetTarget
|
// function : GetTarget
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
GLenum OpenGl_VertexBuffer::GetTarget() const
|
unsigned int OpenGl_VertexBuffer::GetTarget() const
|
||||||
{
|
{
|
||||||
return GL_ARRAY_BUFFER;
|
return GL_ARRAY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Create
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBuffer::Create (const Handle(OpenGl_Context)& theGlCtx)
|
|
||||||
{
|
|
||||||
if (myBufferId == NO_BUFFER && theGlCtx->core15fwd != NULL)
|
|
||||||
{
|
|
||||||
theGlCtx->core15fwd->glGenBuffers (1, &myBufferId);
|
|
||||||
}
|
|
||||||
return myBufferId != NO_BUFFER;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Release
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
void OpenGl_VertexBuffer::Release (OpenGl_Context* theGlCtx)
|
|
||||||
{
|
|
||||||
if (myBufferId == NO_BUFFER)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// application can not handle this case by exception - this is bug in code
|
|
||||||
Standard_ASSERT_RETURN (theGlCtx != NULL,
|
|
||||||
"OpenGl_VertexBuffer destroyed without GL context! Possible GPU memory leakage...",);
|
|
||||||
|
|
||||||
if (theGlCtx->IsValid())
|
|
||||||
{
|
|
||||||
theGlCtx->core15fwd->glDeleteBuffers (1, &myBufferId);
|
|
||||||
}
|
|
||||||
myOffset = NULL;
|
|
||||||
myBufferId = NO_BUFFER;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Bind
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
void OpenGl_VertexBuffer::Bind (const Handle(OpenGl_Context)& theGlCtx) const
|
|
||||||
{
|
|
||||||
theGlCtx->core15fwd->glBindBuffer (GetTarget(), myBufferId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Unbind
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
void OpenGl_VertexBuffer::Unbind (const Handle(OpenGl_Context)& theGlCtx) const
|
|
||||||
{
|
|
||||||
theGlCtx->core15fwd->glBindBuffer (GetTarget(), NO_BUFFER);
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : init
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBuffer::init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType,
|
|
||||||
const GLsizei theStride)
|
|
||||||
{
|
|
||||||
if (!Create (theGlCtx))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bind (theGlCtx);
|
|
||||||
myDataType = theDataType;
|
|
||||||
myComponentsNb = theComponentsNb;
|
|
||||||
myElemsNb = theElemsNb;
|
|
||||||
theGlCtx->core15fwd->glBufferData (GetTarget(), GLsizeiptr(myElemsNb) * theStride, theData, GL_STATIC_DRAW);
|
|
||||||
const int anErr = theGlCtx->core15fwd->glGetError();
|
|
||||||
if (anErr != GL_NO_ERROR
|
|
||||||
&& anErr != GL_OUT_OF_MEMORY) // pass-through out-of-memory error, but log unexpected errors
|
|
||||||
{
|
|
||||||
theGlCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
|
|
||||||
TCollection_AsciiString ("Error: glBufferData (")
|
|
||||||
+ FormatTarget (GetTarget()) + ","
|
|
||||||
+ OpenGl_Context::FormatSize (GLsizeiptr(myElemsNb) * theStride) + ","
|
|
||||||
+ OpenGl_Context::FormatPointer (theData) + ") Id: " + (int )myBufferId
|
|
||||||
+ " failed with " + OpenGl_Context::FormatGlError (anErr));
|
|
||||||
}
|
|
||||||
Unbind (theGlCtx);
|
|
||||||
return anErr == GL_NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : subData
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBuffer::subData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType)
|
|
||||||
{
|
|
||||||
if (!IsValid() || myDataType != theDataType ||
|
|
||||||
theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bind (theGlCtx);
|
|
||||||
const size_t aDataSize = sizeOfGlType (theDataType);
|
|
||||||
theGlCtx->core15fwd->glBufferSubData (GetTarget(),
|
|
||||||
GLintptr(theElemFrom) * GLintptr (myComponentsNb) * aDataSize, // offset in bytes
|
|
||||||
GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * aDataSize, // size in bytes
|
|
||||||
theData);
|
|
||||||
const int anErr = theGlCtx->core15fwd->glGetError();
|
|
||||||
if (anErr != GL_NO_ERROR)
|
|
||||||
{
|
|
||||||
theGlCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
|
|
||||||
TCollection_AsciiString ("Error: glBufferSubData (")
|
|
||||||
+ FormatTarget (GetTarget()) + ","
|
|
||||||
+ OpenGl_Context::FormatSize (GLintptr(theElemFrom) * GLintptr (myComponentsNb) * aDataSize) + ","
|
|
||||||
+ OpenGl_Context::FormatSize (GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * aDataSize) + ","
|
|
||||||
+ OpenGl_Context::FormatPointer (theData) + ") Id: " + (int )myBufferId
|
|
||||||
+ " failed with " + OpenGl_Context::FormatGlError (anErr));
|
|
||||||
}
|
|
||||||
Unbind (theGlCtx);
|
|
||||||
return anErr == GL_NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : getSubData
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBuffer::getSubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
void* theData,
|
|
||||||
const GLenum theDataType)
|
|
||||||
{
|
|
||||||
if (!IsValid() || myDataType != theDataType
|
|
||||||
|| theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb)
|
|
||||||
|| !theGlCtx->hasGetBufferData)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bind (theGlCtx);
|
|
||||||
const size_t aDataSize = sizeOfGlType (theDataType);
|
|
||||||
const GLintptr anOffset = GLintptr (theElemFrom) * GLintptr (myComponentsNb) * aDataSize;
|
|
||||||
const GLsizeiptr aSize = GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * aDataSize;
|
|
||||||
bool isDone = theGlCtx->GetBufferSubData (GetTarget(), anOffset, aSize, theData);
|
|
||||||
isDone = isDone && (glGetError() == GL_NO_ERROR);
|
|
||||||
Unbind (theGlCtx);
|
|
||||||
return isDone;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : BindVertexAttrib
|
// function : BindVertexAttrib
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_VertexBuffer::BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
void OpenGl_VertexBuffer::BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theAttribLoc) const
|
const unsigned int theAttribLoc) const
|
||||||
{
|
{
|
||||||
if (!IsValid() || theAttribLoc == GLuint (-1))
|
if (!IsValid() || theAttribLoc == GLuint (-1))
|
||||||
{
|
{
|
||||||
@ -243,7 +68,7 @@ void OpenGl_VertexBuffer::BindVertexAttrib (const Handle(OpenGl_Context)& theGlC
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_VertexBuffer::UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
void OpenGl_VertexBuffer::UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theAttribLoc) const
|
const unsigned int theAttribLoc) const
|
||||||
{
|
{
|
||||||
if (!IsValid() || theAttribLoc == GLuint (-1))
|
if (!IsValid() || theAttribLoc == GLuint (-1))
|
||||||
{
|
{
|
||||||
@ -298,7 +123,126 @@ bool OpenGl_VertexBuffer::HasNormalAttribute() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : bindAttribute
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_VertexBuffer::bindAttribute (const Handle(OpenGl_Context)& theCtx,
|
||||||
|
const Graphic3d_TypeOfAttribute theAttribute,
|
||||||
|
const Standard_Integer theNbComp,
|
||||||
|
const unsigned int theDataType,
|
||||||
|
const Standard_Integer theStride,
|
||||||
|
const void* theOffset)
|
||||||
|
{
|
||||||
|
if (theCtx->ActiveProgram().IsNull())
|
||||||
|
{
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
|
if (theCtx->core11ffp != NULL)
|
||||||
|
{
|
||||||
|
bindFixed (theCtx, theAttribute, theNbComp, theDataType, theStride, theOffset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// OpenGL handles vertex attribute setup independently from active GLSL program,
|
||||||
|
// but OCCT historically requires program to be bound beforehand (this check could be removed in future).
|
||||||
|
Message::SendFail ("Error: OpenGl_VertexBuffer::bindAttribute() does nothing without active GLSL program");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
theCtx->core20fwd->glEnableVertexAttribArray (theAttribute);
|
||||||
|
theCtx->core20fwd->glVertexAttribPointer (theAttribute, theNbComp, theDataType, theDataType != GL_FLOAT, theStride, theOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : unbindAttribute
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_VertexBuffer::unbindAttribute (const Handle(OpenGl_Context)& theCtx,
|
||||||
|
const Graphic3d_TypeOfAttribute theAttribute)
|
||||||
|
{
|
||||||
|
if (theCtx->ActiveProgram().IsNull())
|
||||||
|
{
|
||||||
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
|
if (theCtx->core11ffp != NULL)
|
||||||
|
{
|
||||||
|
unbindFixed (theCtx, theAttribute);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
theCtx->core20fwd->glDisableVertexAttribArray (theAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
|
// =======================================================================
|
||||||
|
// function : bindFixed
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_VertexBuffer::bindFixed (const Handle(OpenGl_Context)& theCtx,
|
||||||
|
const Graphic3d_TypeOfAttribute theMode,
|
||||||
|
const Standard_Integer theNbComp,
|
||||||
|
const unsigned int theDataType,
|
||||||
|
const Standard_Integer theStride,
|
||||||
|
const void* theOffset)
|
||||||
|
{
|
||||||
|
switch (theMode)
|
||||||
|
{
|
||||||
|
case Graphic3d_TOA_POS:
|
||||||
|
{
|
||||||
|
theCtx->core11ffp->glEnableClientState (GL_VERTEX_ARRAY);
|
||||||
|
theCtx->core11ffp->glVertexPointer (theNbComp, theDataType, theStride, theOffset);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case Graphic3d_TOA_NORM:
|
||||||
|
{
|
||||||
|
theCtx->core11ffp->glEnableClientState (GL_NORMAL_ARRAY);
|
||||||
|
theCtx->core11ffp->glNormalPointer (theDataType, theStride, theOffset);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case Graphic3d_TOA_UV:
|
||||||
|
{
|
||||||
|
theCtx->core11ffp->glEnableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||||
|
theCtx->core11ffp->glTexCoordPointer (theNbComp, theDataType, theStride, theOffset);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case Graphic3d_TOA_COLOR:
|
||||||
|
{
|
||||||
|
theCtx->core11ffp->glEnableClientState (GL_COLOR_ARRAY);
|
||||||
|
theCtx->core11ffp->glColorPointer (theNbComp, theDataType, theStride, theOffset);
|
||||||
|
theCtx->core11ffp->glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
|
||||||
|
theCtx->core11fwd->glEnable (GL_COLOR_MATERIAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case Graphic3d_TOA_CUSTOM:
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : unbindFixed
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OpenGl_VertexBuffer::unbindFixed (const Handle(OpenGl_Context)& theCtx,
|
||||||
|
const Graphic3d_TypeOfAttribute theMode)
|
||||||
|
{
|
||||||
|
switch (theMode)
|
||||||
|
{
|
||||||
|
case Graphic3d_TOA_POS: theCtx->core11ffp->glDisableClientState (GL_VERTEX_ARRAY); return;
|
||||||
|
case Graphic3d_TOA_NORM: theCtx->core11ffp->glDisableClientState (GL_NORMAL_ARRAY); return;
|
||||||
|
case Graphic3d_TOA_UV: theCtx->core11ffp->glDisableClientState (GL_TEXTURE_COORD_ARRAY); return;
|
||||||
|
case Graphic3d_TOA_COLOR: unbindFixedColor (theCtx); return;
|
||||||
|
case Graphic3d_TOA_CUSTOM:
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : unbindFixedColor
|
// function : unbindFixedColor
|
||||||
// purpose :
|
// purpose :
|
||||||
@ -312,21 +256,3 @@ void OpenGl_VertexBuffer::unbindFixedColor (const Handle(OpenGl_Context)& theCtx
|
|||||||
theCtx->ShaderManager()->UpdateMaterialState();
|
theCtx->ShaderManager()->UpdateMaterialState();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : DumpJson
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
void OpenGl_VertexBuffer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
|
|
||||||
{
|
|
||||||
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
|
|
||||||
OCCT_DUMP_BASE_CLASS (theOStream, theDepth, OpenGl_Resource)
|
|
||||||
|
|
||||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, GetTarget())
|
|
||||||
OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myOffset)
|
|
||||||
|
|
||||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBufferId)
|
|
||||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComponentsNb)
|
|
||||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myElemsNb)
|
|
||||||
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDataType)
|
|
||||||
}
|
|
||||||
|
@ -15,26 +15,13 @@
|
|||||||
#ifndef _OpenGl_VertexBuffer_H__
|
#ifndef _OpenGl_VertexBuffer_H__
|
||||||
#define _OpenGl_VertexBuffer_H__
|
#define _OpenGl_VertexBuffer_H__
|
||||||
|
|
||||||
#include <OpenGl_GlCore20.hxx>
|
#include <OpenGl_Buffer.hxx>
|
||||||
#include <OpenGl_Resource.hxx>
|
#include <Graphic3d_Buffer.hxx>
|
||||||
#include <OpenGl_Context.hxx>
|
|
||||||
#include <OpenGl_ShaderProgram.hxx>
|
|
||||||
|
|
||||||
#include <Graphic3d_IndexBuffer.hxx>
|
|
||||||
|
|
||||||
//! Vertex Buffer Object - is a general storage object for vertex attributes (position, normal, color).
|
//! Vertex Buffer Object - is a general storage object for vertex attributes (position, normal, color).
|
||||||
//! Notice that you should use OpenGl_IndexBuffer specialization for array of indices.
|
//! Notice that you should use OpenGl_IndexBuffer specialization for array of indices.
|
||||||
class OpenGl_VertexBuffer : public OpenGl_Resource
|
class OpenGl_VertexBuffer : public OpenGl_Buffer
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Helpful constants
|
|
||||||
static const GLuint NO_BUFFER = 0;
|
|
||||||
|
|
||||||
//! Format VBO target enumeration value.
|
|
||||||
Standard_EXPORT static TCollection_AsciiString FormatTarget (GLenum theTarget);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Create uninitialized VBO.
|
//! Create uninitialized VBO.
|
||||||
@ -43,225 +30,16 @@ public:
|
|||||||
//! Destroy object.
|
//! Destroy object.
|
||||||
Standard_EXPORT virtual ~OpenGl_VertexBuffer();
|
Standard_EXPORT virtual ~OpenGl_VertexBuffer();
|
||||||
|
|
||||||
Standard_EXPORT virtual GLenum GetTarget() const;
|
//! Return buffer target GL_ARRAY_BUFFER.
|
||||||
|
Standard_EXPORT virtual unsigned int GetTarget() const Standard_OVERRIDE;
|
||||||
//! Return TRUE if this is a virtual (for backward compatibility) VBO object.
|
|
||||||
virtual bool IsVirtual() const { return false; }
|
|
||||||
|
|
||||||
//! @return true if current object was initialized
|
|
||||||
inline bool IsValid() const
|
|
||||||
{
|
|
||||||
return myBufferId != NO_BUFFER;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! @return the number of components per generic vertex attribute.
|
|
||||||
inline GLuint GetComponentsNb() const
|
|
||||||
{
|
|
||||||
return myComponentsNb;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! @return number of vertex attributes / number of vertices specified within ::Init()
|
|
||||||
inline GLsizei GetElemsNb() const
|
|
||||||
{
|
|
||||||
return myElemsNb;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Overrides the number of vertex attributes / number of vertexes.
|
|
||||||
//! It is up to user specifying this number correct (e.g. below initial value)!
|
|
||||||
void SetElemsNb (GLsizei theNbElems) { myElemsNb = theNbElems; }
|
|
||||||
|
|
||||||
//! @return data type of each component in the array.
|
|
||||||
inline GLenum GetDataType() const
|
|
||||||
{
|
|
||||||
return myDataType;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! @return offset to data, NULL by default
|
|
||||||
inline GLubyte* GetDataOffset() const
|
|
||||||
{
|
|
||||||
return myOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Creates VBO name (id) if not yet generated.
|
|
||||||
//! Data should be initialized by another method.
|
|
||||||
Standard_EXPORT virtual bool Create (const Handle(OpenGl_Context)& theGlCtx);
|
|
||||||
|
|
||||||
//! Destroy object - will release GPU memory if any.
|
|
||||||
Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Bind this VBO.
|
|
||||||
Standard_EXPORT virtual void Bind (const Handle(OpenGl_Context)& theGlCtx) const;
|
|
||||||
|
|
||||||
//! Unbind this VBO.
|
|
||||||
Standard_EXPORT virtual void Unbind (const Handle(OpenGl_Context)& theGlCtx) const;
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! @param theComponentsNb - specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
|
||||||
//! @param theElemsNb - elements count;
|
|
||||||
//! @param theData - pointer to GLfloat data (vertices/normals etc.).
|
|
||||||
bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLfloat* theData)
|
|
||||||
{
|
|
||||||
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! @param theComponentsNb - specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
|
||||||
//! @param theElemsNb - elements count;
|
|
||||||
//! @param theData - pointer to GLuint data (indices etc.).
|
|
||||||
bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLuint* theData)
|
|
||||||
{
|
|
||||||
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_UNSIGNED_INT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! @param theComponentsNb - specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
|
||||||
//! @param theElemsNb - elements count;
|
|
||||||
//! @param theData - pointer to GLushort data (indices etc.).
|
|
||||||
bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLushort* theData)
|
|
||||||
{
|
|
||||||
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_UNSIGNED_SHORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! @param theComponentsNb - specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
|
|
||||||
//! @param theElemsNb - elements count;
|
|
||||||
//! @param theData - pointer to GLubyte data (indices/colors etc.).
|
|
||||||
bool Init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLubyte* theData)
|
|
||||||
{
|
|
||||||
return init (theGlCtx, theComponentsNb, theElemsNb, theData, GL_UNSIGNED_BYTE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function replaces portion of data within this VBO using glBufferSubData().
|
|
||||||
//! The VBO should be initialized before call.
|
|
||||||
//! @param theElemFrom - element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb - elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData - pointer to GLfloat data.
|
|
||||||
bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLfloat* theData)
|
|
||||||
{
|
|
||||||
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Read back buffer sub-range.
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function reads portion of data from this VBO using glGetBufferSubData().
|
|
||||||
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData [out] destination pointer to GLfloat data.
|
|
||||||
bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
GLfloat* theData)
|
|
||||||
{
|
|
||||||
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function replaces portion of data within this VBO using glBufferSubData().
|
|
||||||
//! The VBO should be initialized before call.
|
|
||||||
//! @param theElemFrom element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData pointer to GLuint data.
|
|
||||||
bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLuint* theData)
|
|
||||||
{
|
|
||||||
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_INT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Read back buffer sub-range.
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function reads portion of data from this VBO using glGetBufferSubData().
|
|
||||||
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData [out] destination pointer to GLuint data.
|
|
||||||
bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
GLuint* theData)
|
|
||||||
{
|
|
||||||
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_INT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function replaces portion of data within this VBO using glBufferSubData().
|
|
||||||
//! The VBO should be initialized before call.
|
|
||||||
//! @param theElemFrom element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData pointer to GLushort data.
|
|
||||||
bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLushort* theData)
|
|
||||||
{
|
|
||||||
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_SHORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Read back buffer sub-range.
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function reads portion of data from this VBO using glGetBufferSubData().
|
|
||||||
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData [out] destination pointer to GLushort data.
|
|
||||||
bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
GLushort* theData)
|
|
||||||
{
|
|
||||||
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_SHORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function replaces portion of data within this VBO using glBufferSubData().
|
|
||||||
//! The VBO should be initialized before call.
|
|
||||||
//! @param theElemFrom element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData pointer to GLubyte data.
|
|
||||||
bool SubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLubyte* theData)
|
|
||||||
{
|
|
||||||
return subData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_BYTE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Read back buffer sub-range.
|
|
||||||
//! Notice that VBO will be unbound after this call.
|
|
||||||
//! Function reads portion of data from this VBO using glGetBufferSubData().
|
|
||||||
//! @param theElemFrom [in] element id from which replace buffer data (>=0);
|
|
||||||
//! @param theElemsNb [in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
|
|
||||||
//! @param theData [out] destination pointer to GLubyte data.
|
|
||||||
bool GetSubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
GLubyte* theData)
|
|
||||||
{
|
|
||||||
return getSubData (theGlCtx, theElemFrom, theElemsNb, theData, GL_UNSIGNED_BYTE);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Bind this VBO to active GLSL program.
|
//! Bind this VBO to active GLSL program.
|
||||||
Standard_EXPORT void BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT void BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theAttribLoc) const;
|
const unsigned int theAttribLoc) const;
|
||||||
|
|
||||||
//! Unbind any VBO from active GLSL program.
|
//! Unbind any VBO from active GLSL program.
|
||||||
Standard_EXPORT void UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT void UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const GLuint theAttribLoc) const;
|
const unsigned int theAttribLoc) const;
|
||||||
|
|
||||||
//! Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
|
//! Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
|
||||||
//! @param theGlCtx - handle to bound GL context;
|
//! @param theGlCtx - handle to bound GL context;
|
||||||
@ -272,7 +50,7 @@ public:
|
|||||||
if (IsValid())
|
if (IsValid())
|
||||||
{
|
{
|
||||||
Bind (theCtx);
|
Bind (theCtx);
|
||||||
bindAttribute (theCtx, theMode, static_cast<GLint> (myComponentsNb), myDataType, 0, myOffset);
|
bindAttribute (theCtx, theMode, static_cast<int> (myComponentsNb), myDataType, 0, myOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,93 +69,32 @@ public:
|
|||||||
|
|
||||||
public: //! @name advanced methods
|
public: //! @name advanced methods
|
||||||
|
|
||||||
//! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
|
|
||||||
virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE
|
|
||||||
{
|
|
||||||
return IsValid()
|
|
||||||
? sizeOfGlType (myDataType) * myComponentsNb * myElemsNb
|
|
||||||
: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! @return size of specified GL type
|
|
||||||
static size_t sizeOfGlType (const GLenum theType)
|
|
||||||
{
|
|
||||||
switch (theType)
|
|
||||||
{
|
|
||||||
case GL_BYTE:
|
|
||||||
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
|
|
||||||
case GL_SHORT:
|
|
||||||
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
|
|
||||||
#ifdef GL_INT
|
|
||||||
case GL_INT:
|
|
||||||
#endif
|
|
||||||
case GL_UNSIGNED_INT: return sizeof(GLuint);
|
|
||||||
case GL_FLOAT: return sizeof(GLfloat);
|
|
||||||
#ifdef GL_DOUBLE
|
|
||||||
case GL_DOUBLE: return sizeof(GLdouble);
|
|
||||||
#endif
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Initialize buffer with new data.
|
|
||||||
Standard_EXPORT virtual bool init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType,
|
|
||||||
const GLsizei theStride);
|
|
||||||
|
|
||||||
//! Initialize buffer with new data.
|
|
||||||
bool init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType)
|
|
||||||
{
|
|
||||||
return init (theGlCtx, theComponentsNb, theElemsNb, theData, theDataType, GLsizei(theComponentsNb) * GLsizei(sizeOfGlType (theDataType)));
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Update part of the buffer with new data.
|
|
||||||
Standard_EXPORT virtual bool subData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType);
|
|
||||||
|
|
||||||
//! Read back buffer sub-range.
|
|
||||||
Standard_EXPORT virtual bool getSubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
void* theData,
|
|
||||||
const GLenum theDataType);
|
|
||||||
|
|
||||||
//! Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
|
//! Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
|
||||||
//! or for FFP using bindFixed() when no program bound.
|
//! or for FFP using bindFixed() when no program bound.
|
||||||
static void bindAttribute (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT static void bindAttribute (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const Graphic3d_TypeOfAttribute theMode,
|
const Graphic3d_TypeOfAttribute theMode,
|
||||||
const GLint theNbComp,
|
const Standard_Integer theNbComp,
|
||||||
const GLenum theDataType,
|
const unsigned int theDataType,
|
||||||
const GLsizei theStride,
|
const Standard_Integer theStride,
|
||||||
const GLvoid* theOffset);
|
const void* theOffset);
|
||||||
|
|
||||||
//! Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
|
//! Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram()
|
||||||
//! or for FFP using unbindFixed() when no program bound.
|
//! or for FFP using unbindFixed() when no program bound.
|
||||||
static void unbindAttribute (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT static void unbindAttribute (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const Graphic3d_TypeOfAttribute theMode);
|
const Graphic3d_TypeOfAttribute theMode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
//! Setup FFP array pointer.
|
//! Setup FFP array pointer.
|
||||||
static void bindFixed (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT static void bindFixed (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const Graphic3d_TypeOfAttribute theMode,
|
const Graphic3d_TypeOfAttribute theMode,
|
||||||
const GLint theNbComp,
|
const Standard_Integer theNbComp,
|
||||||
const GLenum theDataType,
|
const unsigned int theDataType,
|
||||||
const GLsizei theStride,
|
const Standard_Integer theStride,
|
||||||
const GLvoid* theOffset);
|
const void* theOffset);
|
||||||
|
|
||||||
//! Disable FFP array pointer.
|
//! Disable FFP array pointer.
|
||||||
static void unbindFixed (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_EXPORT static void unbindFixed (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const Graphic3d_TypeOfAttribute theMode);
|
const Graphic3d_TypeOfAttribute theMode);
|
||||||
|
|
||||||
//! Disable FFP color array pointer.
|
//! Disable FFP color array pointer.
|
||||||
@ -402,25 +119,12 @@ public: //! @name methods for interleaved attributes array
|
|||||||
//! Unbind all vertex attributes. Default implementation does nothing.
|
//! Unbind all vertex attributes. Default implementation does nothing.
|
||||||
Standard_EXPORT virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
|
Standard_EXPORT virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const;
|
||||||
|
|
||||||
//! Dumps the content of me into the stream
|
|
||||||
Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
GLubyte* myOffset; //!< offset to data
|
|
||||||
GLuint myBufferId; //!< VBO name (index)
|
|
||||||
GLuint myComponentsNb; //!< Number of components per generic vertex attribute, must be 1, 2, 3, or 4
|
|
||||||
GLsizei myElemsNb; //!< Number of vertex attributes / number of vertices
|
|
||||||
GLenum myDataType; //!< Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBuffer,OpenGl_Resource) // Type definition
|
DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBuffer, OpenGl_Buffer)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STANDARD_HANDLE(OpenGl_VertexBuffer, OpenGl_Resource)
|
DEFINE_STANDARD_HANDLE(OpenGl_VertexBuffer, OpenGl_Buffer)
|
||||||
|
|
||||||
#include <OpenGl_VertexBuffer.lxx>
|
|
||||||
|
|
||||||
#endif // _OpenGl_VertexBuffer_H__
|
#endif // _OpenGl_VertexBuffer_H__
|
||||||
|
@ -1,136 +0,0 @@
|
|||||||
// Created by: Kirill GAVRILOV
|
|
||||||
// Copyright (c) 2014 OPEN CASCADE SAS
|
|
||||||
//
|
|
||||||
// This file is part of Open CASCADE Technology software library.
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or modify it under
|
|
||||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
|
||||||
// by the Free Software Foundation, with special exception defined in the file
|
|
||||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
|
||||||
// distribution for complete text of the license and disclaimer of any warranty.
|
|
||||||
//
|
|
||||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
|
||||||
// commercial license or contractual agreement.
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : bindAttribute
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
inline void OpenGl_VertexBuffer::bindAttribute (const Handle(OpenGl_Context)& theCtx,
|
|
||||||
const Graphic3d_TypeOfAttribute theAttribute,
|
|
||||||
const GLint theNbComp,
|
|
||||||
const GLenum theDataType,
|
|
||||||
const GLsizei theStride,
|
|
||||||
const GLvoid* theOffset)
|
|
||||||
{
|
|
||||||
if (theCtx->ActiveProgram().IsNull())
|
|
||||||
{
|
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
|
||||||
if (theCtx->core11ffp != NULL)
|
|
||||||
{
|
|
||||||
bindFixed (theCtx, theAttribute, theNbComp, theDataType, theStride, theOffset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
// OpenGL handles vertex attribute setup independently from active GLSL program,
|
|
||||||
// but OCCT historically requires program to be bound beforehand (this check could be removed in future).
|
|
||||||
Message::SendFail ("Error: OpenGl_VertexBuffer::bindAttribute() does nothing without active GLSL program");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
theCtx->core20fwd->glEnableVertexAttribArray (theAttribute);
|
|
||||||
theCtx->core20fwd->glVertexAttribPointer (theAttribute, theNbComp, theDataType, theDataType != GL_FLOAT, theStride, theOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
|
||||||
// =======================================================================
|
|
||||||
// function : bindFixed
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
inline void OpenGl_VertexBuffer::bindFixed (const Handle(OpenGl_Context)& theCtx,
|
|
||||||
const Graphic3d_TypeOfAttribute theMode,
|
|
||||||
const GLint theNbComp,
|
|
||||||
const GLenum theDataType,
|
|
||||||
const GLsizei theStride,
|
|
||||||
const GLvoid* theOffset)
|
|
||||||
{
|
|
||||||
switch (theMode)
|
|
||||||
{
|
|
||||||
case Graphic3d_TOA_POS:
|
|
||||||
{
|
|
||||||
theCtx->core11ffp->glEnableClientState (GL_VERTEX_ARRAY);
|
|
||||||
theCtx->core11ffp->glVertexPointer (theNbComp, theDataType, theStride, theOffset);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case Graphic3d_TOA_NORM:
|
|
||||||
{
|
|
||||||
theCtx->core11ffp->glEnableClientState (GL_NORMAL_ARRAY);
|
|
||||||
theCtx->core11ffp->glNormalPointer (theDataType, theStride, theOffset);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case Graphic3d_TOA_UV:
|
|
||||||
{
|
|
||||||
theCtx->core11ffp->glEnableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
||||||
theCtx->core11ffp->glTexCoordPointer (theNbComp, theDataType, theStride, theOffset);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case Graphic3d_TOA_COLOR:
|
|
||||||
{
|
|
||||||
theCtx->core11ffp->glEnableClientState (GL_COLOR_ARRAY);
|
|
||||||
theCtx->core11ffp->glColorPointer (theNbComp, theDataType, theStride, theOffset);
|
|
||||||
theCtx->core11ffp->glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
|
|
||||||
theCtx->core11fwd->glEnable (GL_COLOR_MATERIAL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case Graphic3d_TOA_CUSTOM:
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : unbindAttribute
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
inline void OpenGl_VertexBuffer::unbindAttribute (const Handle(OpenGl_Context)& theCtx,
|
|
||||||
const Graphic3d_TypeOfAttribute theAttribute)
|
|
||||||
{
|
|
||||||
if (theCtx->ActiveProgram().IsNull())
|
|
||||||
{
|
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
|
||||||
if (theCtx->core11ffp != NULL)
|
|
||||||
{
|
|
||||||
unbindFixed (theCtx, theAttribute);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
theCtx->core20fwd->glDisableVertexAttribArray (theAttribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
|
||||||
// =======================================================================
|
|
||||||
// function : unbindFixed
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
inline void OpenGl_VertexBuffer::unbindFixed (const Handle(OpenGl_Context)& theCtx,
|
|
||||||
const Graphic3d_TypeOfAttribute theMode)
|
|
||||||
{
|
|
||||||
switch (theMode)
|
|
||||||
{
|
|
||||||
case Graphic3d_TOA_POS: theCtx->core11ffp->glDisableClientState (GL_VERTEX_ARRAY); return;
|
|
||||||
case Graphic3d_TOA_NORM: theCtx->core11ffp->glDisableClientState (GL_NORMAL_ARRAY); return;
|
|
||||||
case Graphic3d_TOA_UV: theCtx->core11ffp->glDisableClientState (GL_TEXTURE_COORD_ARRAY); return;
|
|
||||||
case Graphic3d_TOA_COLOR: unbindFixedColor (theCtx); return;
|
|
||||||
case Graphic3d_TOA_CUSTOM:
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,197 +0,0 @@
|
|||||||
// Created by: Kirill GAVRILOV
|
|
||||||
// Copyright (c) 2013-2014 OPEN CASCADE SAS
|
|
||||||
//
|
|
||||||
// This file is part of Open CASCADE Technology software library.
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or modify it under
|
|
||||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
|
||||||
// by the Free Software Foundation, with special exception defined in the file
|
|
||||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
|
||||||
// distribution for complete text of the license and disclaimer of any warranty.
|
|
||||||
//
|
|
||||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
|
||||||
// commercial license or contractual agreement.
|
|
||||||
|
|
||||||
#include <OpenGl_VertexBufferCompat.hxx>
|
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_VertexBufferCompat,OpenGl_VertexBuffer)
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : OpenGl_VertexBufferCompat
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
OpenGl_VertexBufferCompat::OpenGl_VertexBufferCompat()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : ~OpenGl_VertexBufferCompat
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
OpenGl_VertexBufferCompat::~OpenGl_VertexBufferCompat()
|
|
||||||
{
|
|
||||||
Release (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Create
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBufferCompat::Create (const Handle(OpenGl_Context)& )
|
|
||||||
{
|
|
||||||
if (myBufferId == NO_BUFFER)
|
|
||||||
{
|
|
||||||
myBufferId = (GLuint )-1; // dummy identifier...
|
|
||||||
myData = new NCollection_Buffer (Graphic3d_Buffer::DefaultAllocator());
|
|
||||||
}
|
|
||||||
return myBufferId != NO_BUFFER;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Release
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
void OpenGl_VertexBufferCompat::Release (OpenGl_Context* )
|
|
||||||
{
|
|
||||||
if (myBufferId == NO_BUFFER)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
myOffset = NULL;
|
|
||||||
myBufferId = NO_BUFFER;
|
|
||||||
myData.Nullify();
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Bind
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
void OpenGl_VertexBufferCompat::Bind (const Handle(OpenGl_Context)& ) const
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : Unbind
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
void OpenGl_VertexBufferCompat::Unbind (const Handle(OpenGl_Context)& ) const
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : initLink
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBufferCompat::initLink (const Handle(NCollection_Buffer)& theData,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLenum theDataType)
|
|
||||||
{
|
|
||||||
if (theData.IsNull())
|
|
||||||
{
|
|
||||||
myOffset = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myBufferId == NO_BUFFER)
|
|
||||||
{
|
|
||||||
myBufferId = (GLuint )-1; // dummy identifier...
|
|
||||||
}
|
|
||||||
myData = theData;
|
|
||||||
myDataType = theDataType;
|
|
||||||
myComponentsNb = theComponentsNb;
|
|
||||||
myElemsNb = theElemsNb;
|
|
||||||
myOffset = myData->ChangeData();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : init
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBufferCompat::init (const Handle(OpenGl_Context)& theCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType,
|
|
||||||
const GLsizei theStride)
|
|
||||||
{
|
|
||||||
if (!Create (theCtx))
|
|
||||||
{
|
|
||||||
myOffset = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
myDataType = theDataType;
|
|
||||||
myComponentsNb = theComponentsNb;
|
|
||||||
myElemsNb = theElemsNb;
|
|
||||||
|
|
||||||
const size_t aNbBytes = size_t(myElemsNb) * theStride;
|
|
||||||
if (!myData->Allocate (aNbBytes))
|
|
||||||
{
|
|
||||||
myOffset = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
myOffset = myData->ChangeData();
|
|
||||||
if (theData != NULL)
|
|
||||||
{
|
|
||||||
memcpy (myData->ChangeData(), theData, aNbBytes);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : subData
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBufferCompat::subData (const Handle(OpenGl_Context)& ,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType)
|
|
||||||
{
|
|
||||||
if (!IsValid() || myDataType != theDataType ||
|
|
||||||
theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (theData == NULL)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t aDataSize = sizeOfGlType (theDataType);
|
|
||||||
const size_t anOffset = size_t(theElemFrom) * size_t(myComponentsNb) * aDataSize;
|
|
||||||
const size_t aNbBytes = size_t(theElemsNb) * size_t(myComponentsNb) * aDataSize;
|
|
||||||
memcpy (myData->ChangeData() + anOffset, theData, aNbBytes);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : getSubData
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_VertexBufferCompat::getSubData (const Handle(OpenGl_Context)& ,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
void* theData,
|
|
||||||
const GLenum theDataType)
|
|
||||||
{
|
|
||||||
if (!IsValid() || myDataType != theDataType
|
|
||||||
|| theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb)
|
|
||||||
|| theData == NULL)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t aDataSize = sizeOfGlType (theDataType);
|
|
||||||
const size_t anOffset = size_t(theElemFrom) * size_t(myComponentsNb) * aDataSize;
|
|
||||||
const size_t aNbBytes = size_t(theElemsNb) * size_t(myComponentsNb) * aDataSize;
|
|
||||||
memcpy (theData, myData->Data() + anOffset, aNbBytes);
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -15,90 +15,11 @@
|
|||||||
#ifndef _OpenGl_VertexBufferCompat_HeaderFile
|
#ifndef _OpenGl_VertexBufferCompat_HeaderFile
|
||||||
#define _OpenGl_VertexBufferCompat_HeaderFile
|
#define _OpenGl_VertexBufferCompat_HeaderFile
|
||||||
|
|
||||||
|
#include <OpenGl_BufferCompatT.hxx>
|
||||||
#include <OpenGl_VertexBuffer.hxx>
|
#include <OpenGl_VertexBuffer.hxx>
|
||||||
|
#include <OpenGl_IndexBuffer.hxx>
|
||||||
|
|
||||||
//! Compatibility layer for old OpenGL without VBO.
|
typedef OpenGl_BufferCompatT<OpenGl_VertexBuffer> OpenGl_VertexBufferCompat;
|
||||||
//! Make sure to pass pointer from GetDataOffset() instead of NULL.
|
typedef OpenGl_BufferCompatT<OpenGl_IndexBuffer> OpenGl_IndexBufferCompat;
|
||||||
//! Method GetDataOffset() returns pointer to real data in this class
|
|
||||||
//! (while base class OpenGl_VertexBuffer always return NULL).
|
|
||||||
//!
|
|
||||||
//! Methods Bind()/Unbind() do nothing (do not affect OpenGL state)
|
|
||||||
//! and ::GetTarget() is never used.
|
|
||||||
//! For this reason there is no analog for OpenGl_IndexBuffer.
|
|
||||||
//! Just pass GetDataOffset() to glDrawElements() directly as last argument.
|
|
||||||
//!
|
|
||||||
//! Class overrides methods init() and subData() to copy data into own memory buffer.
|
|
||||||
//! Extra method initLink() might be used to pass existing buffer through handle without copying the data.
|
|
||||||
//!
|
|
||||||
//! Method Create() creates dummy identifier for this object which should NOT be passed to OpenGL functions.
|
|
||||||
class OpenGl_VertexBufferCompat : public OpenGl_VertexBuffer
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//! Create uninitialized VBO.
|
|
||||||
Standard_EXPORT OpenGl_VertexBufferCompat();
|
|
||||||
|
|
||||||
//! Destroy object.
|
|
||||||
Standard_EXPORT virtual ~OpenGl_VertexBufferCompat();
|
|
||||||
|
|
||||||
//! Return TRUE.
|
|
||||||
virtual bool IsVirtual() const Standard_OVERRIDE { return true; }
|
|
||||||
|
|
||||||
//! Creates VBO name (id) if not yet generated.
|
|
||||||
//! Data should be initialized by another method.
|
|
||||||
Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theGlCtx) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Destroy object - will release memory if any.
|
|
||||||
Standard_EXPORT virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Bind this VBO.
|
|
||||||
Standard_EXPORT virtual void Bind (const Handle(OpenGl_Context)& theGlCtx) const Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Unbind this VBO.
|
|
||||||
Standard_EXPORT virtual void Unbind (const Handle(OpenGl_Context)& theGlCtx) const Standard_OVERRIDE;
|
|
||||||
|
|
||||||
public: //! @name advanced methods
|
|
||||||
|
|
||||||
//! Initialize buffer with existing data.
|
|
||||||
//! Data will NOT be copied by this method!
|
|
||||||
Standard_EXPORT bool initLink (const Handle(NCollection_Buffer)& theData,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const GLenum theDataType);
|
|
||||||
|
|
||||||
//! Initialize buffer with new data (data will be copied).
|
|
||||||
Standard_EXPORT virtual bool init (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLuint theComponentsNb,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType,
|
|
||||||
const GLsizei theStride) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Update part of the buffer with new data.
|
|
||||||
Standard_EXPORT virtual bool subData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
const void* theData,
|
|
||||||
const GLenum theDataType) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
//! Read back buffer sub-range.
|
|
||||||
Standard_EXPORT virtual bool getSubData (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
const GLsizei theElemFrom,
|
|
||||||
const GLsizei theElemsNb,
|
|
||||||
void* theData,
|
|
||||||
const GLenum theDataType) Standard_OVERRIDE;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
Handle(NCollection_Buffer) myData; //!< buffer data
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DEFINE_STANDARD_RTTIEXT(OpenGl_VertexBufferCompat,OpenGl_VertexBuffer) // Type definition
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_STANDARD_HANDLE(OpenGl_VertexBufferCompat, OpenGl_VertexBuffer)
|
|
||||||
|
|
||||||
#endif // _OpenGl_VertexBufferCompat_HeaderFile
|
#endif // _OpenGl_VertexBufferCompat_HeaderFile
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#ifndef _OpenGl_VertexBufferEditor_H__
|
#ifndef _OpenGl_VertexBufferEditor_H__
|
||||||
#define _OpenGl_VertexBufferEditor_H__
|
#define _OpenGl_VertexBufferEditor_H__
|
||||||
|
|
||||||
#include <OpenGl_VertexBuffer.hxx>
|
#include <OpenGl_Buffer.hxx>
|
||||||
#include <OpenGl_Context.hxx>
|
#include <OpenGl_Context.hxx>
|
||||||
|
|
||||||
#include <NCollection_Array1.hxx>
|
#include <NCollection_Array1.hxx>
|
||||||
@ -39,26 +39,26 @@ class OpenGl_VertexBufferEditor
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//! Creates empty editor
|
//! Creates empty editor
|
||||||
//! theTmpBufferLength - temporary buffer length
|
//! theTmpBufferLength [in] temporary buffer length
|
||||||
OpenGl_VertexBufferEditor (const Standard_Integer theTmpBufferLength = 0)
|
explicit OpenGl_VertexBufferEditor (const Standard_Integer theTmpBufferLength = 0)
|
||||||
: myElemFrom (0),
|
: myElemFrom (0),
|
||||||
myElemsNb (0),
|
myElemsNb (0),
|
||||||
myTmpBuffer (0, theTmpBufferLength > 0 ? (theTmpBufferLength - 1) : 2047) {}
|
myTmpBuffer (0, theTmpBufferLength > 0 ? (theTmpBufferLength - 1) : 2047) {}
|
||||||
|
|
||||||
//! Creates empty editor
|
//! Creates empty editor
|
||||||
//! theTmpBuffer - pointer to temporary buffer
|
//! theTmpBuffer [in] pointer to temporary buffer
|
||||||
//! theTmpBufferLength - temporary buffer length
|
//! theTmpBufferLength [in] temporary buffer length
|
||||||
OpenGl_VertexBufferEditor (theVec_t* theTmpBuffer,
|
OpenGl_VertexBufferEditor (theVec_t* theTmpBuffer,
|
||||||
const Standard_Integer theTmpBufferLength)
|
const Standard_Integer theTmpBufferLength)
|
||||||
: myElemFrom (0),
|
: myElemFrom (0),
|
||||||
myElemsNb (0),
|
myElemsNb (0),
|
||||||
myTmpBuffer (theTmpBuffer[0], 0, theTmpBufferLength - 1) {}
|
myTmpBuffer (theTmpBuffer[0], 0, theTmpBufferLength - 1) {}
|
||||||
|
|
||||||
//! Initialize editor for specified VBO.
|
//! Initialize editor for specified buffer object.
|
||||||
//! theGlCtx - bound OpenGL context to edit VBO
|
//! theGlCtx [in] bound OpenGL context to edit buffer object
|
||||||
//! theVbo - VBO to edit
|
//! theVbo [in] buffer to edit
|
||||||
Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||||
const Handle(OpenGl_VertexBuffer)& theVbo)
|
const Handle(OpenGl_Buffer)& theVbo)
|
||||||
{
|
{
|
||||||
myGlCtx = theGlCtx;
|
myGlCtx = theGlCtx;
|
||||||
myVbo = theVbo;
|
myVbo = theVbo;
|
||||||
@ -108,15 +108,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! @return assigned VBO
|
//! @return assigned VBO
|
||||||
inline const Handle(OpenGl_VertexBuffer)& GetVBO() const
|
const Handle(OpenGl_Buffer)& GetVBO() const { return myVbo; }
|
||||||
{
|
|
||||||
return myVbo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Handle(OpenGl_Context) myGlCtx; //!< handle to current OpenGL context
|
Handle(OpenGl_Context) myGlCtx; //!< handle to current OpenGL context
|
||||||
Handle(OpenGl_VertexBuffer) myVbo; //!< edited VBO
|
Handle(OpenGl_Buffer) myVbo; //!< edited VBO
|
||||||
Standard_Integer myElemFrom; //!< element in VBO to upload from
|
Standard_Integer myElemFrom; //!< element in VBO to upload from
|
||||||
Standard_Integer myElemsNb; //!< current element in temporary buffer
|
Standard_Integer myElemsNb; //!< current element in temporary buffer
|
||||||
NCollection_Array1<theVec_t> myTmpBuffer; //!< temporary array
|
NCollection_Array1<theVec_t> myTmpBuffer; //!< temporary array
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <Graphic3d_Mat4d.hxx>
|
#include <Graphic3d_Mat4d.hxx>
|
||||||
#include <Image_AlienPixMap.hxx>
|
#include <Image_AlienPixMap.hxx>
|
||||||
#include <OpenGl_ArbFBO.hxx>
|
#include <OpenGl_ArbFBO.hxx>
|
||||||
|
#include <OpenGl_BackgroundArray.hxx>
|
||||||
#include <OpenGl_Context.hxx>
|
#include <OpenGl_Context.hxx>
|
||||||
#include <OpenGl_DepthPeeling.hxx>
|
#include <OpenGl_DepthPeeling.hxx>
|
||||||
#include <OpenGl_FrameBuffer.hxx>
|
#include <OpenGl_FrameBuffer.hxx>
|
||||||
@ -67,6 +68,30 @@ namespace
|
|||||||
{
|
{
|
||||||
return checkWasFailedFbo (theFboToCheck, theFboRef->GetVPSizeX(), theFboRef->GetVPSizeY(), theFboRef->NbSamples());
|
return checkWasFailedFbo (theFboToCheck, theFboRef->GetVPSizeX(), theFboRef->GetVPSizeY(), theFboRef->NbSamples());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Chooses compatible internal color format for OIT frame buffer.
|
||||||
|
static bool chooseOitColorConfiguration (const Handle(OpenGl_Context)& theGlContext,
|
||||||
|
const Standard_Integer theConfigIndex,
|
||||||
|
OpenGl_ColorFormats& theFormats)
|
||||||
|
{
|
||||||
|
theFormats.Clear();
|
||||||
|
switch (theConfigIndex)
|
||||||
|
{
|
||||||
|
case 0: // choose best applicable color format combination
|
||||||
|
{
|
||||||
|
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
|
||||||
|
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_R16F : GL_R32F);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case 1: // choose non-optimal applicable color format combination
|
||||||
|
{
|
||||||
|
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
|
||||||
|
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false; // color combination does not exist
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
|
||||||
@ -336,6 +361,15 @@ Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolea
|
|||||||
return aPrevMode;
|
return aPrevMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : Window
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
Handle(Aspect_Window) OpenGl_View::Window() const
|
||||||
|
{
|
||||||
|
return myWindow->PlatformWindow();
|
||||||
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : SetWindow
|
// function : SetWindow
|
||||||
// purpose :
|
// purpose :
|
||||||
@ -998,12 +1032,12 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
aSizeY = myWindow->Height();
|
aSizeY = myWindow->Height();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
|
const Graphic3d_Vec2i aRendSize (Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f),
|
||||||
const Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
|
Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f));
|
||||||
if (aSizeX < 1
|
if (aSizeX < 1
|
||||||
|| aSizeY < 1
|
|| aSizeY < 1
|
||||||
|| aRendSizeX < 1
|
|| aRendSize.x() < 1
|
||||||
|| aRendSizeY < 1)
|
|| aRendSize.y() < 1)
|
||||||
{
|
{
|
||||||
myBackBufferRestored = Standard_False;
|
myBackBufferRestored = Standard_False;
|
||||||
myIsImmediateDrawn = Standard_False;
|
myIsImmediateDrawn = Standard_False;
|
||||||
@ -1011,7 +1045,7 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// determine multisampling parameters
|
// determine multisampling parameters
|
||||||
Standard_Integer aNbSamples = !myToDisableMSAA && aSizeX == aRendSizeX
|
Standard_Integer aNbSamples = !myToDisableMSAA && aSizeX == aRendSize.x()
|
||||||
? Max (Min (myRenderParams.NbMsaaSamples, aCtx->MaxMsaaSamples()), 0)
|
? Max (Min (myRenderParams.NbMsaaSamples, aCtx->MaxMsaaSamples()), 0)
|
||||||
: 0;
|
: 0;
|
||||||
if (aNbSamples != 0)
|
if (aNbSamples != 0)
|
||||||
@ -1037,10 +1071,9 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
|| theProj == Graphic3d_Camera::Projection_Stereo
|
|| theProj == Graphic3d_Camera::Projection_Stereo
|
||||||
|| aNbSamples != 0
|
|| aNbSamples != 0
|
||||||
|| toUseOit
|
|| toUseOit
|
||||||
|| aSizeX != aRendSizeX))
|
|| aSizeX != aRendSize.x()))
|
||||||
{
|
{
|
||||||
if (myMainSceneFbos[0]->GetVPSizeX() != aRendSizeX
|
if (myMainSceneFbos[0]->GetVPSize() != aRendSize
|
||||||
|| myMainSceneFbos[0]->GetVPSizeY() != aRendSizeY
|
|
||||||
|| myMainSceneFbos[0]->NbSamples() != aNbSamples)
|
|| myMainSceneFbos[0]->NbSamples() != aNbSamples)
|
||||||
{
|
{
|
||||||
if (!myTransientDrawToFront)
|
if (!myTransientDrawToFront)
|
||||||
@ -1055,8 +1088,8 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
// for further blitting and rendering immediate presentations on top
|
// for further blitting and rendering immediate presentations on top
|
||||||
if (aCtx->core20fwd != NULL)
|
if (aCtx->core20fwd != NULL)
|
||||||
{
|
{
|
||||||
const bool wasFailedMain0 = checkWasFailedFbo (myMainSceneFbos[0], aRendSizeX, aRendSizeY, aNbSamples);
|
const bool wasFailedMain0 = checkWasFailedFbo (myMainSceneFbos[0], aRendSize.x(), aRendSize.y(), aNbSamples);
|
||||||
if (!myMainSceneFbos[0]->Init (aCtx, aRendSizeX, aRendSizeY, myFboColorFormat, myFboDepthFormat, aNbSamples)
|
if (!myMainSceneFbos[0]->Init (aCtx, aRendSize, myFboColorFormat, myFboDepthFormat, aNbSamples)
|
||||||
&& !wasFailedMain0)
|
&& !wasFailedMain0)
|
||||||
{
|
{
|
||||||
TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Main FBO "
|
TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Main FBO "
|
||||||
@ -1098,9 +1131,9 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
&& myMainSceneFbos[0]->IsValid())
|
&& myMainSceneFbos[0]->IsValid())
|
||||||
{
|
{
|
||||||
if (aNbSamples != 0
|
if (aNbSamples != 0
|
||||||
|| aSizeX != aRendSizeX)
|
|| aSizeX != aRendSize.x())
|
||||||
{
|
{
|
||||||
hasXRBlitFbo = myXrSceneFbo->InitLazy (aCtx, aSizeX, aSizeY, myFboColorFormat, myFboDepthFormat, 0);
|
hasXRBlitFbo = myXrSceneFbo->InitLazy (aCtx, Graphic3d_Vec2i (aSizeX, aSizeY), myFboColorFormat, myFboDepthFormat, 0);
|
||||||
if (!hasXRBlitFbo)
|
if (!hasXRBlitFbo)
|
||||||
{
|
{
|
||||||
TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! VR FBO "
|
TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! VR FBO "
|
||||||
@ -1273,10 +1306,9 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
if (toUseOit
|
if (toUseOit
|
||||||
&& myRenderParams.TransparencyMethod == Graphic3d_RTM_DEPTH_PEELING_OIT)
|
&& myRenderParams.TransparencyMethod == Graphic3d_RTM_DEPTH_PEELING_OIT)
|
||||||
{
|
{
|
||||||
if (myDepthPeelingFbos->BlendBackFboOit()->GetSizeX() != aRendSizeX
|
if (myDepthPeelingFbos->BlendBackFboOit()->GetSize() != aRendSize)
|
||||||
|| myDepthPeelingFbos->BlendBackFboOit()->GetSizeY() != aRendSizeY)
|
|
||||||
{
|
{
|
||||||
if (myDepthPeelingFbos->BlendBackFboOit()->Init (aCtx, aRendSizeX, aRendSizeY, GL_RGBA16F, 0))
|
if (myDepthPeelingFbos->BlendBackFboOit()->Init (aCtx, aRendSize, GL_RGBA16F, 0))
|
||||||
{
|
{
|
||||||
for (int aPairIter = 0; aPairIter < 2; ++aPairIter)
|
for (int aPairIter = 0; aPairIter < 2; ++aPairIter)
|
||||||
{
|
{
|
||||||
@ -1284,7 +1316,7 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
aColorFormats.Append (GL_RG32F);
|
aColorFormats.Append (GL_RG32F);
|
||||||
aColorFormats.Append (GL_RGBA16F);
|
aColorFormats.Append (GL_RGBA16F);
|
||||||
aColorFormats.Append (GL_RGBA16F);
|
aColorFormats.Append (GL_RGBA16F);
|
||||||
myDepthPeelingFbos->DepthPeelFbosOit()[aPairIter]->Init (aCtx, aRendSizeX, aRendSizeY, aColorFormats, 0);
|
myDepthPeelingFbos->DepthPeelFbosOit()[aPairIter]->Init (aCtx, aRendSize, aColorFormats, 0);
|
||||||
|
|
||||||
NCollection_Sequence<Handle(OpenGl_Texture)> anAttachments;
|
NCollection_Sequence<Handle(OpenGl_Texture)> anAttachments;
|
||||||
anAttachments.Append (myDepthPeelingFbos->DepthPeelFbosOit()[aPairIter]->ColorTexture (1));
|
anAttachments.Append (myDepthPeelingFbos->DepthPeelFbosOit()[aPairIter]->ColorTexture (1));
|
||||||
@ -1317,8 +1349,7 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
Handle(OpenGl_FrameBuffer)& anImmediateSceneFbo = myImmediateSceneFbos [anFboIt];
|
Handle(OpenGl_FrameBuffer)& anImmediateSceneFbo = myImmediateSceneFbos [anFboIt];
|
||||||
Handle(OpenGl_FrameBuffer)& anImmediateSceneFboOit = myImmediateSceneFbosOit[anFboIt];
|
Handle(OpenGl_FrameBuffer)& anImmediateSceneFboOit = myImmediateSceneFbosOit[anFboIt];
|
||||||
if (aMainSceneFbo->IsValid()
|
if (aMainSceneFbo->IsValid()
|
||||||
&& (aMainSceneFboOit->GetVPSizeX() != aRendSizeX
|
&& (aMainSceneFboOit->GetVPSize() != aRendSize
|
||||||
|| aMainSceneFboOit->GetVPSizeY() != aRendSizeY
|
|
||||||
|| aMainSceneFboOit->NbSamples() != aNbSamples))
|
|| aMainSceneFboOit->NbSamples() != aNbSamples))
|
||||||
{
|
{
|
||||||
Standard_Integer aColorConfig = 0;
|
Standard_Integer aColorConfig = 0;
|
||||||
@ -1331,7 +1362,7 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aMainSceneFboOit->Init (aCtx, aRendSizeX, aRendSizeY, myFboOitColorConfig, aMainSceneFbo->DepthStencilTexture(), aNbSamples))
|
if (aMainSceneFboOit->Init (aCtx, aRendSize, myFboOitColorConfig, aMainSceneFbo->DepthStencilTexture(), aNbSamples))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1349,11 +1380,10 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (anImmediateSceneFbo->IsValid()
|
if (anImmediateSceneFbo->IsValid()
|
||||||
&& (anImmediateSceneFboOit->GetVPSizeX() != aRendSizeX
|
&& (anImmediateSceneFboOit->GetVPSize() != aRendSize
|
||||||
|| anImmediateSceneFboOit->GetVPSizeY() != aRendSizeY
|
|
||||||
|| anImmediateSceneFboOit->NbSamples() != aNbSamples))
|
|| anImmediateSceneFboOit->NbSamples() != aNbSamples))
|
||||||
{
|
{
|
||||||
if (!anImmediateSceneFboOit->Init (aCtx, aRendSizeX, aRendSizeY, myFboOitColorConfig,
|
if (!anImmediateSceneFboOit->Init (aCtx, aRendSize, myFboOitColorConfig,
|
||||||
anImmediateSceneFbo->DepthStencilTexture(), aNbSamples))
|
anImmediateSceneFbo->DepthStencilTexture(), aNbSamples))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -1430,7 +1460,7 @@ bool OpenGl_View::prepareFrameBuffers (Graphic3d_Camera::Projection& theProj)
|
|||||||
&& toUseShadowMap)
|
&& toUseShadowMap)
|
||||||
{
|
{
|
||||||
OpenGl_ColorFormats aDummy;
|
OpenGl_ColorFormats aDummy;
|
||||||
if (!aShadowFbo->Init (aCtx, myRenderParams.ShadowMapResolution, myRenderParams.ShadowMapResolution, aDummy, myFboDepthFormat, 0))
|
if (!aShadowFbo->Init (aCtx, Graphic3d_Vec2i (myRenderParams.ShadowMapResolution), aDummy, myFboDepthFormat, 0))
|
||||||
{
|
{
|
||||||
toUseShadowMap = false;
|
toUseShadowMap = false;
|
||||||
}
|
}
|
||||||
@ -2306,20 +2336,22 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
|
|||||||
|
|
||||||
if (!toRenderGL)
|
if (!toRenderGL)
|
||||||
{
|
{
|
||||||
const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width();
|
const Graphic3d_Vec2i aSizeXY = theReadDrawFbo != NULL
|
||||||
const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height();
|
? theReadDrawFbo->GetVPSize()
|
||||||
|
: Graphic3d_Vec2i (myWindow->Width(), myWindow->Height());
|
||||||
|
|
||||||
toRenderGL = !initRaytraceResources (aSizeX, aSizeY, aCtx)
|
toRenderGL = !initRaytraceResources (aSizeXY.x(), aSizeXY.y(), aCtx)
|
||||||
|| !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
|
|| !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
|
||||||
|
|
||||||
toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL
|
toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL
|
||||||
|
|
||||||
if (!toRenderGL)
|
if (!toRenderGL)
|
||||||
{
|
{
|
||||||
myOpenGlFBO ->InitLazy (aCtx, aSizeX, aSizeY, myFboColorFormat, myFboDepthFormat, 0);
|
myOpenGlFBO ->InitLazy (aCtx, aSizeXY, myFboColorFormat, myFboDepthFormat, 0);
|
||||||
|
|
||||||
if (theReadDrawFbo != NULL)
|
if (theReadDrawFbo != NULL)
|
||||||
|
{
|
||||||
theReadDrawFbo->UnbindBuffer (aCtx);
|
theReadDrawFbo->UnbindBuffer (aCtx);
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare preliminary OpenGL output
|
// Prepare preliminary OpenGL output
|
||||||
if (aCtx->arbFBOBlit != NULL)
|
if (aCtx->arbFBOBlit != NULL)
|
||||||
@ -2361,7 +2393,7 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
|
|||||||
myWorkspace->ResetAppliedAspect();
|
myWorkspace->ResetAppliedAspect();
|
||||||
|
|
||||||
// Ray-tracing polygonal primitive arrays
|
// Ray-tracing polygonal primitive arrays
|
||||||
raytrace (aSizeX, aSizeY, theProjection, theReadDrawFbo, aCtx);
|
raytrace (aSizeXY.x(), aSizeXY.y(), theProjection, theReadDrawFbo, aCtx);
|
||||||
|
|
||||||
// Render upper (top and topmost) OpenGL layers
|
// Render upper (top and topmost) OpenGL layers
|
||||||
myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Upper, theReadDrawFbo, theOitAccumFbo);
|
myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Upper, theReadDrawFbo, theOitAccumFbo);
|
||||||
@ -2731,8 +2763,8 @@ void OpenGl_View::drawStereoPair (OpenGl_FrameBuffer* theDrawFbo)
|
|||||||
if (aPair[0]->NbSamples() != 0)
|
if (aPair[0]->NbSamples() != 0)
|
||||||
{
|
{
|
||||||
// resolve MSAA buffers before drawing
|
// resolve MSAA buffers before drawing
|
||||||
if (!myOpenGlFBO ->InitLazy (aCtx, aPair[0]->GetVPSizeX(), aPair[0]->GetVPSizeY(), myFboColorFormat, myFboDepthFormat, 0)
|
if (!myOpenGlFBO ->InitLazy (aCtx, aPair[0]->GetVPSize(), myFboColorFormat, myFboDepthFormat, 0)
|
||||||
|| !myOpenGlFBO2->InitLazy (aCtx, aPair[0]->GetVPSizeX(), aPair[0]->GetVPSizeY(), myFboColorFormat, 0, 0))
|
|| !myOpenGlFBO2->InitLazy (aCtx, aPair[0]->GetVPSize(), myFboColorFormat, 0, 0))
|
||||||
{
|
{
|
||||||
aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
|
aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
|
||||||
GL_DEBUG_TYPE_ERROR,
|
GL_DEBUG_TYPE_ERROR,
|
||||||
@ -3001,33 +3033,6 @@ Standard_Boolean OpenGl_View::checkOitCompatibility (const Handle(OpenGl_Context
|
|||||||
return Standard_False;
|
return Standard_False;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// function : chooseOitColorConfiguration
|
|
||||||
// purpose :
|
|
||||||
// =======================================================================
|
|
||||||
bool OpenGl_View::chooseOitColorConfiguration (const Handle(OpenGl_Context)& theGlContext,
|
|
||||||
const Standard_Integer theConfigIndex,
|
|
||||||
OpenGl_ColorFormats& theFormats)
|
|
||||||
{
|
|
||||||
theFormats.Clear();
|
|
||||||
switch (theConfigIndex)
|
|
||||||
{
|
|
||||||
case 0: // choose best applicable color format combination
|
|
||||||
{
|
|
||||||
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
|
|
||||||
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_R16F : GL_R32F);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case 1: // choose non-optimal applicable color format combination
|
|
||||||
{
|
|
||||||
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
|
|
||||||
theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false; // color combination does not exist
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : checkPBRAvailability
|
// function : checkPBRAvailability
|
||||||
// purpose :
|
// purpose :
|
||||||
|
@ -16,53 +16,44 @@
|
|||||||
#ifndef _OpenGl_View_Header
|
#ifndef _OpenGl_View_Header
|
||||||
#define _OpenGl_View_Header
|
#define _OpenGl_View_Header
|
||||||
|
|
||||||
#include <Standard_Transient.hxx>
|
|
||||||
#include <Standard_Type.hxx>
|
|
||||||
|
|
||||||
#include <TColStd_Array2OfReal.hxx>
|
|
||||||
#include <NCollection_List.hxx>
|
|
||||||
#include <math_BullardGenerator.hxx>
|
|
||||||
|
|
||||||
#include <Quantity_NameOfColor.hxx>
|
|
||||||
#include <Aspect_FillMethod.hxx>
|
#include <Aspect_FillMethod.hxx>
|
||||||
#include <Aspect_GradientFillMethod.hxx>
|
#include <Aspect_GradientFillMethod.hxx>
|
||||||
|
|
||||||
#include <Graphic3d_CView.hxx>
|
#include <Graphic3d_CView.hxx>
|
||||||
#include <Graphic3d_CullingTool.hxx>
|
#include <Graphic3d_CullingTool.hxx>
|
||||||
#include <Graphic3d_GraduatedTrihedron.hxx>
|
#include <Graphic3d_GraduatedTrihedron.hxx>
|
||||||
#include <Graphic3d_SequenceOfHClipPlane.hxx>
|
#include <Graphic3d_SequenceOfHClipPlane.hxx>
|
||||||
#include <Graphic3d_ToneMappingMethod.hxx>
|
#include <Graphic3d_ToneMappingMethod.hxx>
|
||||||
|
#include <Graphic3d_TypeOfBackground.hxx>
|
||||||
#include <Graphic3d_TypeOfShadingModel.hxx>
|
#include <Graphic3d_TypeOfShadingModel.hxx>
|
||||||
#include <Graphic3d_WorldViewProjState.hxx>
|
#include <Graphic3d_WorldViewProjState.hxx>
|
||||||
#include <Graphic3d_ZLayerSettings.hxx>
|
#include <Graphic3d_ZLayerSettings.hxx>
|
||||||
|
#include <math_BullardGenerator.hxx>
|
||||||
|
|
||||||
#include <OpenGl_Aspects.hxx>
|
#include <OpenGl_Aspects.hxx>
|
||||||
#include <OpenGl_BackgroundArray.hxx>
|
|
||||||
#include <OpenGl_Context.hxx>
|
|
||||||
#include <OpenGl_FrameBuffer.hxx>
|
#include <OpenGl_FrameBuffer.hxx>
|
||||||
#include <OpenGl_FrameStatsPrs.hxx>
|
#include <OpenGl_FrameStatsPrs.hxx>
|
||||||
#include <OpenGl_GraduatedTrihedron.hxx>
|
#include <OpenGl_GraduatedTrihedron.hxx>
|
||||||
#include <OpenGl_LayerList.hxx>
|
#include <OpenGl_LayerList.hxx>
|
||||||
#include <OpenGl_LineAttributes.hxx>
|
|
||||||
#include <OpenGl_SceneGeometry.hxx>
|
#include <OpenGl_SceneGeometry.hxx>
|
||||||
#include <OpenGl_Structure.hxx>
|
#include <OpenGl_Structure.hxx>
|
||||||
#include <OpenGl_Window.hxx>
|
|
||||||
#include <OpenGl_Workspace.hxx>
|
|
||||||
#include <OpenGl_TileSampler.hxx>
|
#include <OpenGl_TileSampler.hxx>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
class Graphic3d_StructureManager;
|
class Graphic3d_StructureManager;
|
||||||
|
class OpenGl_BackgroundArray;
|
||||||
class OpenGl_DepthPeeling;
|
class OpenGl_DepthPeeling;
|
||||||
class OpenGl_GraphicDriver;
|
class OpenGl_GraphicDriver;
|
||||||
class OpenGl_PBREnvironment;
|
class OpenGl_PBREnvironment;
|
||||||
|
struct OpenGl_RaytraceMaterial;
|
||||||
class OpenGl_StateCounter;
|
class OpenGl_StateCounter;
|
||||||
class OpenGl_ShadowMap;
|
class OpenGl_ShadowMap;
|
||||||
class OpenGl_ShadowMapArray;
|
class OpenGl_ShadowMapArray;
|
||||||
|
class OpenGl_ShaderObject;
|
||||||
|
class OpenGl_TextureBuffer;
|
||||||
class OpenGl_TriangleSet;
|
class OpenGl_TriangleSet;
|
||||||
class OpenGl_Workspace;
|
class OpenGl_Workspace;
|
||||||
class OpenGl_View;
|
|
||||||
|
|
||||||
DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
|
DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
|
||||||
|
|
||||||
@ -108,8 +99,7 @@ public:
|
|||||||
const Aspect_RenderingContext theContext) Standard_OVERRIDE;
|
const Aspect_RenderingContext theContext) Standard_OVERRIDE;
|
||||||
|
|
||||||
//! Returns window associated with the view.
|
//! Returns window associated with the view.
|
||||||
virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE
|
Standard_EXPORT virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE;
|
||||||
{ return myWindow->PlatformWindow(); }
|
|
||||||
|
|
||||||
//! Returns True if the window associated to the view is defined.
|
//! Returns True if the window associated to the view is defined.
|
||||||
virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
|
virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
|
||||||
@ -468,11 +458,6 @@ private:
|
|||||||
bool checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
|
bool checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
|
||||||
const Standard_Boolean theMSAA);
|
const Standard_Boolean theMSAA);
|
||||||
|
|
||||||
//! Chooses compatible internal color format for OIT frame buffer.
|
|
||||||
bool chooseOitColorConfiguration (const Handle(OpenGl_Context)& theGlContext,
|
|
||||||
const Standard_Integer theConfigIndex,
|
|
||||||
OpenGl_ColorFormats& theFormats);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
OpenGl_GraphicDriver* myDriver;
|
OpenGl_GraphicDriver* myDriver;
|
||||||
@ -1053,27 +1038,27 @@ protected: //! @name fields related to ray-tracing
|
|||||||
Handle(OpenGl_ShaderProgram) myOutImageProgram;
|
Handle(OpenGl_ShaderProgram) myOutImageProgram;
|
||||||
|
|
||||||
//! Texture buffer of data records of bottom-level BVH nodes.
|
//! Texture buffer of data records of bottom-level BVH nodes.
|
||||||
Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
|
Handle(OpenGl_TextureBuffer) mySceneNodeInfoTexture;
|
||||||
//! Texture buffer of minimum points of bottom-level BVH nodes.
|
//! Texture buffer of minimum points of bottom-level BVH nodes.
|
||||||
Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
|
Handle(OpenGl_TextureBuffer) mySceneMinPointTexture;
|
||||||
//! Texture buffer of maximum points of bottom-level BVH nodes.
|
//! Texture buffer of maximum points of bottom-level BVH nodes.
|
||||||
Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
|
Handle(OpenGl_TextureBuffer) mySceneMaxPointTexture;
|
||||||
//! Texture buffer of transformations of high-level BVH nodes.
|
//! Texture buffer of transformations of high-level BVH nodes.
|
||||||
Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
|
Handle(OpenGl_TextureBuffer) mySceneTransformTexture;
|
||||||
|
|
||||||
//! Texture buffer of vertex coords.
|
//! Texture buffer of vertex coords.
|
||||||
Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
|
Handle(OpenGl_TextureBuffer) myGeometryVertexTexture;
|
||||||
//! Texture buffer of vertex normals.
|
//! Texture buffer of vertex normals.
|
||||||
Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
|
Handle(OpenGl_TextureBuffer) myGeometryNormalTexture;
|
||||||
//! Texture buffer of vertex UV coords.
|
//! Texture buffer of vertex UV coords.
|
||||||
Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
|
Handle(OpenGl_TextureBuffer) myGeometryTexCrdTexture;
|
||||||
//! Texture buffer of triangle indices.
|
//! Texture buffer of triangle indices.
|
||||||
Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
|
Handle(OpenGl_TextureBuffer) myGeometryTriangTexture;
|
||||||
|
|
||||||
//! Texture buffer of material properties.
|
//! Texture buffer of material properties.
|
||||||
Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
|
Handle(OpenGl_TextureBuffer) myRaytraceMaterialTexture;
|
||||||
//! Texture buffer of light source properties.
|
//! Texture buffer of light source properties.
|
||||||
Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
|
Handle(OpenGl_TextureBuffer) myRaytraceLightSrcTexture;
|
||||||
|
|
||||||
//! 1st framebuffer (FBO) to perform adaptive FSAA.
|
//! 1st framebuffer (FBO) to perform adaptive FSAA.
|
||||||
//! Used in compatibility mode (no adaptive sampling).
|
//! Used in compatibility mode (no adaptive sampling).
|
||||||
|
@ -16,8 +16,13 @@
|
|||||||
#include <OpenGl_View.hxx>
|
#include <OpenGl_View.hxx>
|
||||||
|
|
||||||
#include <Graphic3d_TextureParams.hxx>
|
#include <Graphic3d_TextureParams.hxx>
|
||||||
|
#include <OpenGl_BackgroundArray.hxx>
|
||||||
|
#include <OpenGl_FrameBuffer.hxx>
|
||||||
#include <OpenGl_PrimitiveArray.hxx>
|
#include <OpenGl_PrimitiveArray.hxx>
|
||||||
#include <OpenGl_VertexBuffer.hxx>
|
#include <OpenGl_VertexBuffer.hxx>
|
||||||
|
#include <OpenGl_SceneGeometry.hxx>
|
||||||
|
#include <OpenGl_ShaderProgram.hxx>
|
||||||
|
#include <OpenGl_TextureBuffer.hxx>
|
||||||
#include <OpenGl_GlCore44.hxx>
|
#include <OpenGl_GlCore44.hxx>
|
||||||
#include <OSD_Protection.hxx>
|
#include <OSD_Protection.hxx>
|
||||||
#include <OSD_File.hxx>
|
#include <OSD_File.hxx>
|
||||||
@ -1885,8 +1890,8 @@ Standard_Boolean OpenGl_View::updateRaytraceBuffers (const Standard_Integer
|
|||||||
if (myRaytraceParameters.AdaptiveScreenSampling)
|
if (myRaytraceParameters.AdaptiveScreenSampling)
|
||||||
{
|
{
|
||||||
Graphic3d_Vec2i aMaxViewport = myTileSampler.OffsetTilesViewportMax().cwiseMax (Graphic3d_Vec2i (theSizeX, theSizeY));
|
Graphic3d_Vec2i aMaxViewport = myTileSampler.OffsetTilesViewportMax().cwiseMax (Graphic3d_Vec2i (theSizeX, theSizeY));
|
||||||
myRaytraceFBO1[0]->InitLazy (theGlContext, aMaxViewport.x(), aMaxViewport.y(), GL_RGBA32F, myFboDepthFormat);
|
myRaytraceFBO1[0]->InitLazy (theGlContext, aMaxViewport, GL_RGBA32F, myFboDepthFormat);
|
||||||
myRaytraceFBO2[0]->InitLazy (theGlContext, aMaxViewport.x(), aMaxViewport.y(), GL_RGBA32F, myFboDepthFormat);
|
myRaytraceFBO2[0]->InitLazy (theGlContext, aMaxViewport, GL_RGBA32F, myFboDepthFormat);
|
||||||
if (myRaytraceFBO1[1]->IsValid()) // second FBO not needed
|
if (myRaytraceFBO1[1]->IsValid()) // second FBO not needed
|
||||||
{
|
{
|
||||||
myRaytraceFBO1[1]->Release (theGlContext.operator->());
|
myRaytraceFBO1[1]->Release (theGlContext.operator->());
|
||||||
@ -1969,8 +1974,8 @@ Standard_Boolean OpenGl_View::updateRaytraceBuffers (const Standard_Integer
|
|||||||
myAccumFrames = 0; // accumulation should be restarted
|
myAccumFrames = 0; // accumulation should be restarted
|
||||||
}
|
}
|
||||||
|
|
||||||
myRaytraceFBO1[aViewIter]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
|
myRaytraceFBO1[aViewIter]->InitLazy (theGlContext, Graphic3d_Vec2i (theSizeX, theSizeY), GL_RGBA32F, myFboDepthFormat);
|
||||||
myRaytraceFBO2[aViewIter]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
|
myRaytraceFBO2[aViewIter]->InitLazy (theGlContext, Graphic3d_Vec2i (theSizeX, theSizeY), GL_RGBA32F, myFboDepthFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Standard_True;
|
return Standard_True;
|
||||||
@ -2149,10 +2154,10 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
|
|||||||
|
|
||||||
if (mySceneNodeInfoTexture.IsNull()) // create scene BVH buffers
|
if (mySceneNodeInfoTexture.IsNull()) // create scene BVH buffers
|
||||||
{
|
{
|
||||||
mySceneNodeInfoTexture = new OpenGl_TextureBufferArb;
|
mySceneNodeInfoTexture = new OpenGl_TextureBuffer();
|
||||||
mySceneMinPointTexture = new OpenGl_TextureBufferArb;
|
mySceneMinPointTexture = new OpenGl_TextureBuffer();
|
||||||
mySceneMaxPointTexture = new OpenGl_TextureBufferArb;
|
mySceneMaxPointTexture = new OpenGl_TextureBuffer();
|
||||||
mySceneTransformTexture = new OpenGl_TextureBufferArb;
|
mySceneTransformTexture = new OpenGl_TextureBuffer();
|
||||||
|
|
||||||
if (!mySceneNodeInfoTexture->Create (theGlContext)
|
if (!mySceneNodeInfoTexture->Create (theGlContext)
|
||||||
|| !mySceneMinPointTexture->Create (theGlContext)
|
|| !mySceneMinPointTexture->Create (theGlContext)
|
||||||
@ -2166,10 +2171,10 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
|
|||||||
|
|
||||||
if (myGeometryVertexTexture.IsNull()) // create geometry buffers
|
if (myGeometryVertexTexture.IsNull()) // create geometry buffers
|
||||||
{
|
{
|
||||||
myGeometryVertexTexture = new OpenGl_TextureBufferArb;
|
myGeometryVertexTexture = new OpenGl_TextureBuffer();
|
||||||
myGeometryNormalTexture = new OpenGl_TextureBufferArb;
|
myGeometryNormalTexture = new OpenGl_TextureBuffer();
|
||||||
myGeometryTexCrdTexture = new OpenGl_TextureBufferArb;
|
myGeometryTexCrdTexture = new OpenGl_TextureBuffer();
|
||||||
myGeometryTriangTexture = new OpenGl_TextureBufferArb;
|
myGeometryTriangTexture = new OpenGl_TextureBuffer();
|
||||||
|
|
||||||
if (!myGeometryVertexTexture->Create (theGlContext)
|
if (!myGeometryVertexTexture->Create (theGlContext)
|
||||||
|| !myGeometryNormalTexture->Create (theGlContext)
|
|| !myGeometryNormalTexture->Create (theGlContext)
|
||||||
@ -2183,7 +2188,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
|
|||||||
|
|
||||||
if (myRaytraceMaterialTexture.IsNull()) // create material buffer
|
if (myRaytraceMaterialTexture.IsNull()) // create material buffer
|
||||||
{
|
{
|
||||||
myRaytraceMaterialTexture = new OpenGl_TextureBufferArb();
|
myRaytraceMaterialTexture = new OpenGl_TextureBuffer();
|
||||||
if (!myRaytraceMaterialTexture->Create (theGlContext))
|
if (!myRaytraceMaterialTexture->Create (theGlContext))
|
||||||
{
|
{
|
||||||
Message::SendTrace() << "Error: Failed to create buffers for material data";
|
Message::SendTrace() << "Error: Failed to create buffers for material data";
|
||||||
@ -2516,7 +2521,7 @@ Standard_Boolean OpenGl_View::updateRaytraceLightSources (const OpenGl_Mat4& the
|
|||||||
|
|
||||||
if (myRaytraceLightSrcTexture.IsNull()) // create light source buffer
|
if (myRaytraceLightSrcTexture.IsNull()) // create light source buffer
|
||||||
{
|
{
|
||||||
myRaytraceLightSrcTexture = new OpenGl_TextureBufferArb;
|
myRaytraceLightSrcTexture = new OpenGl_TextureBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myRaytraceGeometry.Sources.size() != 0 && wasUpdated)
|
if (myRaytraceGeometry.Sources.size() != 0 && wasUpdated)
|
||||||
|
@ -785,7 +785,7 @@ void OpenGl_Window::Init()
|
|||||||
aDefFbo = new OpenGl_FrameBuffer();
|
aDefFbo = new OpenGl_FrameBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aDefFbo->InitWithRB (myGlContext, myWidth, myHeight, GL_RGBA8, GL_DEPTH24_STENCIL8))
|
if (!aDefFbo->InitWithRB (myGlContext, Graphic3d_Vec2i (myWidth, myHeight), GL_RGBA8, GL_DEPTH24_STENCIL8))
|
||||||
{
|
{
|
||||||
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: default FBO creation failed");
|
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: default FBO creation failed");
|
||||||
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
|
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
|
||||||
|
@ -329,7 +329,7 @@ void OpenGl_Window::Init()
|
|||||||
::glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &myHeight);
|
::glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &myHeight);
|
||||||
::glBindRenderbuffer (GL_RENDERBUFFER, 0);
|
::glBindRenderbuffer (GL_RENDERBUFFER, 0);
|
||||||
|
|
||||||
if (!aDefFbo->InitWithRB (myGlContext, myWidth, myHeight, GL_RGBA8, GL_DEPTH24_STENCIL8, aWinRBColor))
|
if (!aDefFbo->InitWithRB (myGlContext, Graphic3d_Vec2i (myWidth, myHeight), GL_RGBA8, GL_DEPTH24_STENCIL8, aWinRBColor))
|
||||||
{
|
{
|
||||||
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: default FBO creation failed");
|
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: default FBO creation failed");
|
||||||
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
|
throw Aspect_GraphicDeviceDefinitionError(aMsg.ToCString());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include <OpenGl_Workspace.hxx>
|
#include <OpenGl_Workspace.hxx>
|
||||||
|
|
||||||
#include <OpenGl_ArbFBO.hxx>
|
|
||||||
#include <OpenGl_Aspects.hxx>
|
#include <OpenGl_Aspects.hxx>
|
||||||
#include <OpenGl_Context.hxx>
|
#include <OpenGl_Context.hxx>
|
||||||
#include <OpenGl_Element.hxx>
|
#include <OpenGl_Element.hxx>
|
||||||
@ -386,7 +385,7 @@ Handle(OpenGl_FrameBuffer) OpenGl_Workspace::FBOCreate (const Standard_Integer t
|
|||||||
const Handle(OpenGl_Context)& aCtx = GetGlContext();
|
const Handle(OpenGl_Context)& aCtx = GetGlContext();
|
||||||
aCtx->BindTextures (Handle(OpenGl_TextureSet)(), Handle(OpenGl_ShaderProgram)());
|
aCtx->BindTextures (Handle(OpenGl_TextureSet)(), Handle(OpenGl_ShaderProgram)());
|
||||||
Handle(OpenGl_FrameBuffer) aFrameBuffer = new OpenGl_FrameBuffer();
|
Handle(OpenGl_FrameBuffer) aFrameBuffer = new OpenGl_FrameBuffer();
|
||||||
if (!aFrameBuffer->Init (aCtx, theWidth, theHeight, GL_SRGB8_ALPHA8, GL_DEPTH24_STENCIL8, 0))
|
if (!aFrameBuffer->Init (aCtx, Graphic3d_Vec2i (theWidth, theHeight), GL_SRGB8_ALPHA8, GL_DEPTH24_STENCIL8, 0))
|
||||||
{
|
{
|
||||||
aFrameBuffer->Release (aCtx.operator->());
|
aFrameBuffer->Release (aCtx.operator->());
|
||||||
return Handle(OpenGl_FrameBuffer)();
|
return Handle(OpenGl_FrameBuffer)();
|
||||||
|
@ -17,19 +17,15 @@
|
|||||||
#define _OpenGl_Workspace_Header
|
#define _OpenGl_Workspace_Header
|
||||||
|
|
||||||
#include <Graphic3d_BufferType.hxx>
|
#include <Graphic3d_BufferType.hxx>
|
||||||
|
#include <Graphic3d_PresentationAttributes.hxx>
|
||||||
|
|
||||||
#include <OpenGl_Aspects.hxx>
|
#include <OpenGl_Aspects.hxx>
|
||||||
#include <OpenGl_CappingAlgo.hxx>
|
|
||||||
#include <OpenGl_FrameBuffer.hxx>
|
|
||||||
#include <OpenGl_Material.hxx>
|
|
||||||
#include <OpenGl_ShaderObject.hxx>
|
|
||||||
#include <OpenGl_ShaderProgram.hxx>
|
|
||||||
#include <OpenGl_TextureBufferArb.hxx>
|
|
||||||
#include <OpenGl_RenderFilter.hxx>
|
|
||||||
#include <OpenGl_Vec.hxx>
|
#include <OpenGl_Vec.hxx>
|
||||||
#include <OpenGl_Window.hxx>
|
|
||||||
|
|
||||||
|
class OpenGl_FrameBuffer;
|
||||||
|
class OpenGl_Group;
|
||||||
class OpenGl_View;
|
class OpenGl_View;
|
||||||
|
class OpenGl_Window;
|
||||||
class Image_PixMap;
|
class Image_PixMap;
|
||||||
|
|
||||||
class OpenGl_Workspace;
|
class OpenGl_Workspace;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user