0030488: Visualization, Ray Tracing - empty error message on GLSL program compilation
[occt.git] / src / OpenGl / OpenGl_ShaderObject.hxx
CommitLineData
30f0ad28 1// Created on: 2013-09-19
2// Created by: Denis BOGOLEPOV
d5f74e42 3// Copyright (c) 2013-2014 OPEN CASCADE SAS
30f0ad28 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
30f0ad28 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
30f0ad28 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
30f0ad28 15
16#ifndef _OpenGl_ShaderObject_Header
17#define _OpenGl_ShaderObject_Header
18
30f0ad28 19#include <Graphic3d_ShaderObject.hxx>
20#include <OpenGl_GlCore20.hxx>
21#include <OpenGl_Resource.hxx>
22
23//! Wrapper for OpenGL shader object.
24class OpenGl_ShaderObject : public OpenGl_Resource
25{
d4e12f61 26 DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderObject, OpenGl_Resource)
27 friend class OpenGl_ShaderProgram;
30f0ad28 28public:
29
30 //! Non-valid shader name.
31 static const GLuint NO_SHADER = 0;
32
33public:
34
3b4c6945 35 //! Structure defining shader uniform or in/out variable.
36 struct ShaderVariable
37 {
38 TCollection_AsciiString Name; //!< variable name
39 Standard_Integer Stages; //!< active stages as Graphic3d_TypeOfShaderObject bits;
40 //! for in/out variables, intermediate stages will be automatically filled
41
42 //! Create new shader variable.
43 ShaderVariable (const TCollection_AsciiString& theVarName, Standard_Integer theShaderStageBits) : Name (theVarName), Stages (theShaderStageBits) {}
44
45 //! Empty constructor.
46 ShaderVariable() : Stages (0) {}
47 };
48
49 //! List of variable of shader program.
50 typedef NCollection_Sequence<ShaderVariable> ShaderVariableList;
51
52 //! This is a preprocessor for Graphic3d_ShaderObject::CreateFromSource() function.
53 //! Creates a new shader object from specified source according to list of uniforms and in/out variables.
54 //! @param theSource shader object source code to modify
55 //! @param theType shader object type to create
56 //! @param theUniforms list of uniform variables
57 //! @param theStageInOuts list of stage in/out variables
58 //! @param theInName name of input variables block;
59 //! can be empty for accessing each variable without block prefix
60 //! (mandatory for stages accessing both inputs and outputs)
61 //! @param theOutName name of output variables block;
62 //! can be empty for accessing each variable without block prefix
63 //! (mandatory for stages accessing both inputs and outputs)
64 //! @param theNbGeomInputVerts number of geometry shader input vertexes
65 Standard_EXPORT static Handle(Graphic3d_ShaderObject) CreateFromSource (TCollection_AsciiString& theSource,
66 Graphic3d_TypeOfShaderObject theType,
67 const ShaderVariableList& theUniforms,
68 const ShaderVariableList& theStageInOuts,
69 const TCollection_AsciiString& theInName = TCollection_AsciiString(),
70 const TCollection_AsciiString& theOutName = TCollection_AsciiString(),
71 Standard_Integer theNbGeomInputVerts = 0);
72
73public:
74
30f0ad28 75 //! Creates uninitialized shader object.
76 Standard_EXPORT OpenGl_ShaderObject (GLenum theType);
77
78 //! Releases resources of shader object.
79 Standard_EXPORT virtual ~OpenGl_ShaderObject();
80
81 //! Loads shader source code.
82 Standard_EXPORT Standard_Boolean LoadSource (const Handle(OpenGl_Context)& theCtx,
83 const TCollection_AsciiString& theSource);
84
85 //! Compiles the shader object.
86 Standard_EXPORT Standard_Boolean Compile (const Handle(OpenGl_Context)& theCtx);
87
2bda8346 88 //! Wrapper for compiling shader object with verbose printing on error.
89 //! @param theCtx bound OpenGL context
90 //! @param theSource source code to load
91 //! @param theIsVerbose flag to print log on error
92 //! @param theToPrintSource flag to print source code on error
93 Standard_EXPORT Standard_Boolean LoadAndCompile (const Handle(OpenGl_Context)& theCtx,
94 const TCollection_AsciiString& theSource,
95 bool theIsVerbose = true,
96 bool theToPrintSource = true);
97
30f0ad28 98 //! Fetches information log of the last compile operation.
99 Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
100 TCollection_AsciiString& theLog);
101
102 //! Creates new empty shader object of specified type.
103 Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx);
104
105 //! Destroys shader object.
79104795 106 Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
30f0ad28 107
15669413 108 //! Returns estimated GPU memory usage - not implemented.
109 virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
110
30f0ad28 111 //! Returns type of shader object.
112 GLenum Type() const { return myType; }
113
114protected:
115
116 GLenum myType; //!< Type of OpenGL shader object
117 GLuint myShaderID; //!< Handle of OpenGL shader object
118
30f0ad28 119};
120
d4e12f61 121DEFINE_STANDARD_HANDLE(OpenGl_ShaderObject, OpenGl_Resource)
122
30f0ad28 123#endif // _OpenGl_ShaderObject_Header