0030635: Visualization - move OpenGl_Layer to Graphic3d_Layer
[occt.git] / src / Graphic3d / Graphic3d_ShaderObject.cxx
CommitLineData
30f0ad28 1// Created on: 2013-09-20
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#include <OSD_File.hxx>
17#include <OSD_Protection.hxx>
18#include <Standard_Atomic.hxx>
19#include <Graphic3d_ShaderObject.hxx>
20#include <Graphic3d_GraphicDriver.hxx>
21
92efcf78 22IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ShaderObject,Standard_Transient)
23
30f0ad28 24namespace
25{
26 static volatile Standard_Integer THE_SHADER_OBJECT_COUNTER = 0;
a3f6f591 27}
30f0ad28 28
30f0ad28 29
30// =======================================================================
31// function : Graphic3d_ShaderObject
32// purpose : Creates a shader object from specified file
33// =======================================================================
34Graphic3d_ShaderObject::Graphic3d_ShaderObject (const Graphic3d_TypeOfShaderObject theType)
35: myType (theType)
36{
37 myID = TCollection_AsciiString ("Graphic3d_ShaderObject_")
38 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_SHADER_OBJECT_COUNTER));
39}
40
41// =======================================================================
42// function : CreatFromFile
43// purpose : Creates new shader object from specified file
44// =======================================================================
45Handle(Graphic3d_ShaderObject) Graphic3d_ShaderObject::CreateFromFile (const Graphic3d_TypeOfShaderObject theType,
46 const TCollection_AsciiString& thePath)
47{
48 Handle(Graphic3d_ShaderObject) aShader = new Graphic3d_ShaderObject (theType);
49 aShader->myPath = thePath;
50
51 OSD_File aFile (thePath);
52 if (!aFile.Exists())
53 {
54 return NULL;
55 }
56
57 aFile.Open (OSD_ReadOnly, OSD_Protection());
bd0b3e60 58 aFile.Read (aShader->mySource, (int)aFile.Size());
30f0ad28 59 aFile.Close();
60
61 return aShader;
62}
63
64// =======================================================================
65// function : CreatFromSource
66// purpose : Creates new shader object from specified source
67// =======================================================================
68Handle(Graphic3d_ShaderObject) Graphic3d_ShaderObject::CreateFromSource (const Graphic3d_TypeOfShaderObject theType,
69 const TCollection_AsciiString& theSource)
70{
71 Handle(Graphic3d_ShaderObject) aShader = new Graphic3d_ShaderObject (theType);
72 aShader->mySource = theSource;
73 return aShader;
74}
75
76// =======================================================================
77// function : ~Graphic3d_ShaderObject
78// purpose : Releases resources of shader object
79// =======================================================================
80Graphic3d_ShaderObject::~Graphic3d_ShaderObject()
81{
82 //
83}
84
85// =======================================================================
86// function : IsDone
87// purpose : Checks if the shader object is valid or not
88// =======================================================================
89Standard_Boolean Graphic3d_ShaderObject::IsDone() const
90{
91 return !mySource.IsEmpty();
92}