mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
0023226: Extend OpenGl_Context to store map of shared GPU resources
OpenGl_Resource was slightly corrected and OpenGl_Element was extended with Release method to manage GPU resources. OpenGl_PrimitiveArray now uses new OpenGl_VertexBuffer class (requires OpenGL 1.5+). Strange workarounds for feedback mode were removed. OpenGl_Context now provides access to shared GPU resources and manages resources queue for delayed release (replaces functionality of removed OpenGl_ResourceCleaner). Loaded GL_ARB_texture_buffer_object and GL_ARB_draw_instanced extensions. Global maps of views, workspaces and structures were moved to OpenGl_GraphicDriver members. UserDrawCallback() function moved to OpenGl_GraphicDriver methods. Aspect_GraphicCallbackStruct now holds handle of OpenGl_Context instead of system-dependent pointers to GL context definition. New classes NCollection_Vec2, NCollection_Vec3 and NCollection_Vec4 implements interface to low-level data (points, vertices, colors) in GLSL-style. Removed EnableVBO argument from vdrawparray Draw Harness command Corrected compilation errors Fixed wrong argument in Index VBO initialization Fixed several cases of incorrect memory management in TKV3d Visual3d_ViewManager::Remove() Destroy structures before last view removed for correct GPU resources management. Graphic3d_Structure::GraphicClear() Remove groups to avoid usage of dead OpenGl_Group pointers. V3d_View::Remove() Fixed mistake in #0000280 patch. Small correction Fixed OCC280 test command Replace removed view within created one in ViewerTest EventManager. ViewerTest, do not create unused 3D view In current design NIS_View always created and used for both - NIS objects and AIS objects.
This commit is contained in:
151
src/OpenGl/OpenGl_TextureBufferArb.cxx
Normal file
151
src/OpenGl/OpenGl_TextureBufferArb.cxx
Normal file
@@ -0,0 +1,151 @@
|
||||
// Created by: Kirill GAVRILOV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#include <OpenGl_TextureBufferArb.hxx>
|
||||
|
||||
#include <OpenGl_Context.hxx>
|
||||
#include <Standard_Assert.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE (OpenGl_TextureBufferArb, OpenGl_VertexBuffer)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_TextureBufferArb, OpenGl_VertexBuffer)
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_TextureBufferArb
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OpenGl_TextureBufferArb::OpenGl_TextureBufferArb()
|
||||
: OpenGl_VertexBuffer(),
|
||||
myTextureId (NO_TEXTURE),
|
||||
myTexFormat (GL_RGBA32F)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~OpenGl_TextureBufferArb
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OpenGl_TextureBufferArb::~OpenGl_TextureBufferArb()
|
||||
{
|
||||
Release (NULL);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetTarget
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
GLenum OpenGl_TextureBufferArb::GetTarget() const
|
||||
{
|
||||
return GL_TEXTURE_BUFFER_ARB; // GL_TEXTURE_BUFFER for OpenGL 3.1+
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Release
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_TextureBufferArb::Release (const OpenGl_Context* theGlCtx)
|
||||
{
|
||||
if (myTextureId != NO_TEXTURE)
|
||||
{
|
||||
// application can not handle this case by exception - this is bug in code
|
||||
Standard_ASSERT_RETURN (theGlCtx != NULL,
|
||||
"OpenGl_TextureBufferExt destroyed without GL context! Possible GPU memory leakage...",);
|
||||
|
||||
glDeleteTextures (1, &myTextureId);
|
||||
myTextureId = NO_TEXTURE;
|
||||
}
|
||||
OpenGl_VertexBuffer::Release (theGlCtx);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool OpenGl_TextureBufferArb::Create (const Handle(OpenGl_Context)& theGlCtx)
|
||||
{
|
||||
if (!OpenGl_VertexBuffer::Create (theGlCtx))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (myTextureId == NO_TEXTURE)
|
||||
{
|
||||
glGenTextures (1, &myTextureId);
|
||||
}
|
||||
return myTextureId != NO_TEXTURE;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx,
|
||||
const GLuint theComponentsNb,
|
||||
const GLsizei theElemsNb,
|
||||
const GLfloat* theData)
|
||||
{
|
||||
if (theComponentsNb != 1
|
||||
&& theComponentsNb != 2
|
||||
&& theComponentsNb != 4)
|
||||
{
|
||||
// unsupported format
|
||||
return false;
|
||||
}
|
||||
else if (!Create (theGlCtx)
|
||||
|| !OpenGl_VertexBuffer::Init (theGlCtx, theComponentsNb, theElemsNb, theData))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (theComponentsNb)
|
||||
{
|
||||
case 1: myTexFormat = GL_R32F; break;
|
||||
case 2: myTexFormat = GL_RG32F; break;
|
||||
//case 3: myTexFormat = GL_RGB32F; break; // GL_ARB_texture_buffer_object_rgb32
|
||||
case 4: myTexFormat = GL_RGBA32F; break;
|
||||
}
|
||||
|
||||
Bind (theGlCtx);
|
||||
BindTexture (theGlCtx);
|
||||
theGlCtx->arbTBO->glTexBufferARB (GetTarget(), myTexFormat, myBufferId);
|
||||
UnbindTexture (theGlCtx);
|
||||
Unbind (theGlCtx);
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : BindTexture
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_TextureBufferArb::BindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
||||
const GLenum theTextureUnit) const
|
||||
{
|
||||
theGlCtx->core20->glActiveTexture (theTextureUnit);
|
||||
glBindTexture (GetTarget(), myTextureId);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : UnbindTexture
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_TextureBufferArb::UnbindTexture (const Handle(OpenGl_Context)& theGlCtx,
|
||||
const GLenum theTextureUnit) const
|
||||
{
|
||||
theGlCtx->core20->glActiveTexture (theTextureUnit);
|
||||
glBindTexture (GetTarget(), NO_TEXTURE);
|
||||
}
|
Reference in New Issue
Block a user