Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:35

0001 // Created on: 2013-09-19
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OpenGl_ShaderObject_HeaderFile
0017 #define OpenGl_ShaderObject_HeaderFile
0018 
0019 #include <Graphic3d_ShaderObject.hxx>
0020 #include <OpenGl_GlCore20.hxx>
0021 #include <OpenGl_Resource.hxx>
0022 #include <Quantity_Date.hxx>
0023 
0024 //! Wrapper for OpenGL shader object.
0025 class OpenGl_ShaderObject : public OpenGl_Resource
0026 {
0027   DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderObject, OpenGl_Resource)
0028   friend class OpenGl_ShaderProgram;
0029 public:
0030 
0031   //! Non-valid shader name.
0032   static const GLuint NO_SHADER = 0;
0033 
0034 public:
0035 
0036   //! Creates uninitialized shader object.
0037   Standard_EXPORT OpenGl_ShaderObject (GLenum theType);
0038 
0039   //! Releases resources of shader object.
0040   Standard_EXPORT virtual ~OpenGl_ShaderObject();
0041 
0042   //! Loads shader source code.
0043   Standard_EXPORT Standard_Boolean LoadSource (const Handle(OpenGl_Context)&  theCtx,
0044                                                const TCollection_AsciiString& theSource);
0045 
0046   //! Compiles the shader object.
0047   Standard_EXPORT Standard_Boolean Compile (const Handle(OpenGl_Context)& theCtx);
0048 
0049   //! Wrapper for compiling shader object with verbose printing on error.
0050   //! @param theCtx bound OpenGL context
0051   //! @param theId  GLSL program id to define file name
0052   //! @param theSource source code to load
0053   //! @param theIsVerbose flag to print log on error
0054   //! @param theToPrintSource flag to print source code on error
0055   Standard_EXPORT Standard_Boolean LoadAndCompile (const Handle(OpenGl_Context)& theCtx,
0056                                                    const TCollection_AsciiString& theId,
0057                                                    const TCollection_AsciiString& theSource,
0058                                                    bool theIsVerbose = true,
0059                                                    bool theToPrintSource = true);
0060 
0061   //! Print source code of this shader object to messenger.
0062   Standard_EXPORT void DumpSourceCode (const Handle(OpenGl_Context)& theCtx,
0063                                        const TCollection_AsciiString& theId,
0064                                        const TCollection_AsciiString& theSource) const;
0065 
0066   //! Fetches information log of the last compile operation.
0067   Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
0068                                                  TCollection_AsciiString&      theLog);
0069 
0070   //! Creates new empty shader object of specified type.
0071   Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx);
0072 
0073   //! Destroys shader object.
0074   Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
0075 
0076   //! Returns estimated GPU memory usage - not implemented.
0077   virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
0078 
0079   //! Returns type of shader object.
0080   GLenum Type() const { return myType; }
0081 
0082 public:
0083 
0084   //! Update the shader object from external file in the following way:
0085   //! 1) If external file does not exist, then it will be created (current source code will be dumped, no recompilation) and FALSE will be returned.
0086   //! 2) If external file exists and it has the same timestamp as   myDumpDate, nothing will be done      and FALSE will be returned.
0087   //! 3) If external file exists and it has    newer timestamp than myDumpDate, shader  will be recompiled and TRUE will be returned.
0088   //! @param theCtx OpenGL context bound to this working thread
0089   //! @param theId  GLSL program id to define file name
0090   //! @param theFolder folder to store files
0091   //! @param theToBeautify flag improving formatting (add extra newlines)
0092   //! @param theToReset when TRUE, existing dumps will be overridden
0093   Standard_EXPORT Standard_Boolean updateDebugDump (const Handle(OpenGl_Context)& theCtx,
0094                                                     const TCollection_AsciiString& theId,
0095                                                     const TCollection_AsciiString& theFolder,
0096                                                     Standard_Boolean theToBeautify,
0097                                                     Standard_Boolean theToReset);
0098 
0099 protected:
0100 
0101   Quantity_Date myDumpDate; //!< The recent date of the shader dump
0102   GLenum        myType;     //!< Type of OpenGL shader object
0103   GLuint        myShaderID; //!< Handle of OpenGL shader object
0104 
0105 };
0106 
0107 DEFINE_STANDARD_HANDLE(OpenGl_ShaderObject, OpenGl_Resource)
0108 
0109 #endif // _OpenGl_ShaderObject_Header