1 // Created on: 2013-09-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OSD_File.hxx>
17 #include <OSD_Protection.hxx>
18 #include <Standard_Atomic.hxx>
19 #include <Graphic3d_ShaderObject.hxx>
20 #include <Graphic3d_GraphicDriver.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ShaderObject,Standard_Transient)
26 static volatile Standard_Integer THE_SHADER_OBJECT_COUNTER = 0;
30 // =======================================================================
31 // function : Graphic3d_ShaderObject
32 // purpose : Creates a shader object from specified file
33 // =======================================================================
34 Graphic3d_ShaderObject::Graphic3d_ShaderObject (const Graphic3d_TypeOfShaderObject theType)
37 myID = TCollection_AsciiString ("Graphic3d_ShaderObject_")
38 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_SHADER_OBJECT_COUNTER));
41 // =======================================================================
42 // function : CreatFromFile
43 // purpose : Creates new shader object from specified file
44 // =======================================================================
45 Handle(Graphic3d_ShaderObject) Graphic3d_ShaderObject::CreateFromFile (const Graphic3d_TypeOfShaderObject theType,
46 const TCollection_AsciiString& thePath)
48 Handle(Graphic3d_ShaderObject) aShader = new Graphic3d_ShaderObject (theType);
49 aShader->myPath = thePath;
51 OSD_File aFile (thePath);
57 aFile.Open (OSD_ReadOnly, OSD_Protection());
58 aFile.Read (aShader->mySource, (int)aFile.Size());
64 // =======================================================================
65 // function : CreatFromSource
66 // purpose : Creates new shader object from specified source
67 // =======================================================================
68 Handle(Graphic3d_ShaderObject) Graphic3d_ShaderObject::CreateFromSource (const Graphic3d_TypeOfShaderObject theType,
69 const TCollection_AsciiString& theSource)
71 Handle(Graphic3d_ShaderObject) aShader = new Graphic3d_ShaderObject (theType);
72 aShader->mySource = theSource;
76 // =======================================================================
77 // function : ~Graphic3d_ShaderObject
78 // purpose : Releases resources of shader object
79 // =======================================================================
80 Graphic3d_ShaderObject::~Graphic3d_ShaderObject()
85 // =======================================================================
87 // purpose : Checks if the shader object is valid or not
88 // =======================================================================
89 Standard_Boolean Graphic3d_ShaderObject::IsDone() const
91 return !mySource.IsEmpty();