From: isk Date: Mon, 29 Aug 2016 05:38:31 +0000 (+0300) Subject: Add a new OpenGl_BindlessTextureWrapper class. X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=ef92081286be473cf8c552536f5c3f899c8c063b;p=occt-copy.git Add a new OpenGl_BindlessTextureWrapper class. --- diff --git a/src/OpenGl/FILES b/src/OpenGl/FILES index 67af2f8496..4ecb6c8b6e 100755 --- a/src/OpenGl/FILES +++ b/src/OpenGl/FILES @@ -65,6 +65,8 @@ OpenGl_Font.cxx OpenGl_tgl_funcs.hxx OpenGl_BackgroundArray.cxx OpenGl_BackgroundArray.hxx +OpenGl_BindlessTextureWrapper.cxx +OpenGl_BindlessTextureWrapper.hxx OpenGl_BVHClipPrimitiveSet.cxx OpenGl_BVHClipPrimitiveSet.hxx OpenGl_BVHClipPrimitiveTrsfPersSet.cxx diff --git a/src/OpenGl/OpenGl_BindlessTextureWrapper.cxx b/src/OpenGl/OpenGl_BindlessTextureWrapper.cxx new file mode 100644 index 0000000000..9a933eb5fb --- /dev/null +++ b/src/OpenGl/OpenGl_BindlessTextureWrapper.cxx @@ -0,0 +1,84 @@ +// Created on: 2016-08-05 +// Created by: Ilya SEVRIKOV +// Copyright (c) 2016 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 +#include + +IMPLEMENT_STANDARD_RTTIEXT (OpenGl_BindlessTextureWrapper, Standard_Transient) + +// ======================================================================= +// function : GetTextureSamplerHandle +// purpose : +// ======================================================================= +GLuint64 OpenGl_BindlessTextureWrapper::GetTextureSamplerHandle (const GLuint theTextureId, const GLuint theSamplerId) +{ + GLuint64 aHandle = myContext->arbTexBindless->glGetTextureSamplerHandleARB (theTextureId, theSamplerId); + +#ifdef OCCT_DEBUG + GLenum anError = glGetError(); + + if (anError != GL_NO_ERROR) + { + Message::DefaultMessenger()->Send ("Error: Can not get texture sampler handle.", Message_Fail); + } +#endif + + return aHandle; +} + +// ======================================================================= +// function : MakeTextureHandleResident +// purpose : +// ======================================================================= +GLvoid OpenGl_BindlessTextureWrapper::MakeTextureHandleResident (const GLuint64 theHandle) +{ + myContext->arbTexBindless->glMakeTextureHandleResidentARB (theHandle); + +#ifdef OCCT_DEBUG + GLenum anError = glGetError(); + + if (anError != GL_NO_ERROR) + { + Message::DefaultMessenger()->Send ("Error: Can not make texture handle as resident.", Message_Fail); + } +#endif +} + +// ======================================================================= +// function : MakeTextureHandleNonResident +// purpose : +// ======================================================================= +GLvoid OpenGl_BindlessTextureWrapper::MakeTextureHandleNonResident (const GLuint64 theHandle) +{ + myContext->arbTexBindless->glMakeTextureHandleNonResidentARB (theHandle); + +#ifdef OCCT_DEBUG + GLenum anError = glGetError(); + + if (anError != GL_NO_ERROR) + { + Message::DefaultMessenger()->Send("Error: Can not make texture handle as non-resident.", Message_Fail); + } +#endif +} + +// ======================================================================= +// function : IsTextureHandleResident +// purpose : +// ======================================================================= +GLboolean OpenGl_BindlessTextureWrapper::IsTextureHandleResident (const GLuint64 theHandle) +{ + return myContext->arbTexBindless->glIsTextureHandleResidentARB (theHandle); +} diff --git a/src/OpenGl/OpenGl_BindlessTextureWrapper.hxx b/src/OpenGl/OpenGl_BindlessTextureWrapper.hxx new file mode 100644 index 0000000000..91e9b9ed33 --- /dev/null +++ b/src/OpenGl/OpenGl_BindlessTextureWrapper.hxx @@ -0,0 +1,81 @@ +// Created on: 2016-08-05 +// Created by: Ilya SEVRIKOV +// Copyright (c) 2016 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_BindlessTextureWrapper_HeaderFile +#define _OpenGl_BindlessTextureWrapper_HeaderFile + +#include + +//! ARB texture bindless wrapper. +//! +//! To access texture or image resources using handles, the handles must first be made resident. +//! Accessing a texture or image by handle without first making it resident can result in undefined results, +//! including program termination. +class OpenGl_BindlessTextureWrapper : public Standard_Transient +{ +public: + OpenGl_BindlessTextureWrapper (const Handle(OpenGl_Context)& theContext) + : myContext (theContext) + { + // + } + + //! Create a texture handle using the current non-sampler state from the texture named + //! and the sampler state from the sampler object . + //! Returns a 64-bit unsigned integer handle. + //! The error INVALID_VALUE is generated if is zero or is not the name of an existing texture object + //! or if is zero or is not the name of an existing sampler object. + //! The error INVALID_OPERATION is generated if the texture object is not complete (section 3.9.14). + //! If an error occurs, a handle of zero is returned. + //! + //! The error INVALID_OPERATION is generated if the border color (taken from the ) + //! is not one of the following allowed values. If the texture's base internal format is signed + //! or unsigned integer, allowed values are (0,0,0,0), (0,0,0,1), (1,1,1,0), and (1,1,1,1). + //! If the base internal format is not integer, allowed values are (0.0, 0.0, 0.0, 0.0), + //! (0.0, 0.0, 0.0, 1.0), (1.0, 1.0, 1.0, 0.0), and (1.0, 1.0, 1.0, 1.0). + //! + //! The handle for each texture or texture/sampler pair is unique; + //! the same handle will if GetTextureSamplerHandleARB is called multiple times for the same texture/sampler pair. + Standard_EXPORT GLuint64 GetTextureSamplerHandle (const GLuint theTextureId, const GLuint theSamplerId); + + //! Makes a texture handle accessible to shaders for texture mapping operations. + //! + //! While the texture handle is resident, it may be used in texture mapping operations. + //! If a shader attempts to perform a texture mapping operation using a handle that is not resident, + //! the results of that operation are undefined and may lead to application termination. + //! When a texture handle is resident, the texture it references is also considered resident for the + //! purposes of the AreTexturesResident command. The error INVALID_OPERATION is generated + //! if is not a valid texture handle, or if is already resident in the current GL context. + Standard_EXPORT GLvoid MakeTextureHandleResident (const GLuint64 theHandle); + + //! Makes a texture handle inaccessible to shaders for texture mapping operations. + //! + //! The error INVALID_OPERATION is generated if is not a valid + //! texture handle, or if is not resident in the current GL context. + Standard_EXPORT GLvoid MakeTextureHandleNonResident (const GLuint64 theHandle); + + //! + Standard_EXPORT GLboolean IsTextureHandleResident (const GLuint64 theHandle); + +protected: + Handle(OpenGl_Context) myContext; + +public: + DEFINE_STANDARD_RTTIEXT (OpenGl_BindlessTextureWrapper, Standard_Transient) +}; + +DEFINE_STANDARD_HANDLE (OpenGl_BindlessTextureWrapper, Standard_Transient) + +#endif //_OpenGl_BindlessTextureWrapper_HeaderFile