mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0024192: Adding support for shaders to OCCT visualization toolkit
This commit is contained in:
@@ -31,6 +31,17 @@ Graphic3d_Group_2.cxx
|
||||
Graphic3d_Group_8.cxx
|
||||
Graphic3d_Group_10.cxx
|
||||
Graphic3d_Structure.pxx
|
||||
Graphic3d_ShaderObject.hxx
|
||||
Graphic3d_ShaderObject.cxx
|
||||
Graphic3d_ShaderProgram.hxx
|
||||
Graphic3d_ShaderProgram.cxx
|
||||
Graphic3d_ShaderVariable.hxx
|
||||
Graphic3d_ShaderVariable.cxx
|
||||
Graphic3d_ShaderVariable.lxx
|
||||
Graphic3d_ShaderObject_Handle.hxx
|
||||
Graphic3d_ShaderProgram_Handle.hxx
|
||||
Graphic3d_ShaderVariable_Handle.hxx
|
||||
Graphic3d_TypeOfShaderObject.hxx
|
||||
Graphic3d_DataStructure.pxx
|
||||
Graphic3d_StructureManager.pxx
|
||||
Graphic3d.edl
|
||||
@@ -57,4 +68,4 @@ Graphic3d_ClipPlane.hxx
|
||||
Graphic3d_ClipPlane.cxx
|
||||
Graphic3d_ClipPlane_Handle.hxx
|
||||
Graphic3d_SetOfHClipPlane.hxx
|
||||
Graphic3d_SetOfHClipPlane_Handle.hxx
|
||||
Graphic3d_SetOfHClipPlane_Handle.hxx
|
||||
|
@@ -584,6 +584,9 @@ is
|
||||
imported NListOfHAsciiString;
|
||||
---Category: Instantiated classes
|
||||
|
||||
imported ShaderProgram_Handle;
|
||||
---Category: Instantiated classes
|
||||
|
||||
imported SetOfHClipPlane;
|
||||
---Category: Instantiated classes
|
||||
-- Set of handles on clip planes
|
||||
|
@@ -42,14 +42,16 @@ class AspectFillArea3d from Graphic3d inherits AspectFillArea from Aspect
|
||||
|
||||
uses
|
||||
|
||||
Color from Quantity,
|
||||
Ratio from Quantity,
|
||||
Color from Quantity,
|
||||
Ratio from Quantity,
|
||||
|
||||
TypeOfLine from Aspect,
|
||||
InteriorStyle from Aspect,
|
||||
TypeOfLine from Aspect,
|
||||
InteriorStyle from Aspect,
|
||||
|
||||
MaterialAspect from Graphic3d,
|
||||
TextureMap from Graphic3d
|
||||
MaterialAspect from Graphic3d,
|
||||
TextureMap from Graphic3d,
|
||||
|
||||
ShaderProgram_Handle from Graphic3d
|
||||
|
||||
is
|
||||
|
||||
@@ -189,6 +191,12 @@ is
|
||||
-- Consult OpenGL reference for details (glPolygonOffset function description).
|
||||
---Category: Methods to modify the class definition
|
||||
|
||||
SetShaderProgram ( me : mutable;
|
||||
theProgram : ShaderProgram_Handle from Graphic3d );
|
||||
---Level: Public
|
||||
---Purpose: Sets up OpenGL/GLSL shader program.
|
||||
---Category: Methods to modify the class definition
|
||||
|
||||
----------------------------
|
||||
-- Category: Inquire methods
|
||||
----------------------------
|
||||
@@ -244,9 +252,12 @@ is
|
||||
aUnits : out ShortReal from Standard );
|
||||
---Level: Public
|
||||
---Purpose: Returns current polygon offsets settings.
|
||||
---Category: Inquire methods
|
||||
|
||||
|
||||
---Category: Inquire methods
|
||||
|
||||
ShaderProgram ( me )
|
||||
returns ShaderProgram_Handle from Graphic3d;
|
||||
---C++: return const &
|
||||
|
||||
--
|
||||
|
||||
fields
|
||||
@@ -290,4 +301,6 @@ fields
|
||||
MyPolygonOffsetFactor : ShortReal from Standard;
|
||||
MyPolygonOffsetUnits : ShortReal from Standard;
|
||||
|
||||
MyShaderProgram : ShaderProgram_Handle from Graphic3d;
|
||||
|
||||
end AspectFillArea3d;
|
||||
|
@@ -180,3 +180,13 @@ void Graphic3d_AspectFillArea3d::PolygonOffsets(Standard_Integer& aMode,
|
||||
aFactor = MyPolygonOffsetFactor;
|
||||
aUnits = MyPolygonOffsetUnits;
|
||||
}
|
||||
|
||||
void Graphic3d_AspectFillArea3d::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram)
|
||||
{
|
||||
MyShaderProgram = theProgram;
|
||||
}
|
||||
|
||||
const Handle(Graphic3d_ShaderProgram)& Graphic3d_AspectFillArea3d::ShaderProgram() const
|
||||
{
|
||||
return MyShaderProgram;
|
||||
}
|
||||
|
@@ -29,9 +29,9 @@ class AspectLine3d from Graphic3d inherits AspectLine from Aspect
|
||||
|
||||
uses
|
||||
|
||||
Color from Quantity,
|
||||
|
||||
TypeOfLine from Aspect
|
||||
Color from Quantity,
|
||||
TypeOfLine from Aspect,
|
||||
ShaderProgram_Handle from Graphic3d
|
||||
|
||||
is
|
||||
|
||||
@@ -58,9 +58,16 @@ is
|
||||
-- factor to this nominal line width.
|
||||
-- The supported linewidths vary by 1-pixel units.
|
||||
|
||||
--
|
||||
SetShaderProgram ( me : mutable;
|
||||
theProgram : ShaderProgram_Handle from Graphic3d );
|
||||
---Level: Public
|
||||
---Purpose: Sets up OpenGL/GLSL shader program.
|
||||
|
||||
-- fields
|
||||
ShaderProgram ( me )
|
||||
returns ShaderProgram_Handle from Graphic3d;
|
||||
---C++: return const &
|
||||
|
||||
fields
|
||||
|
||||
--
|
||||
-- Class : Graphic3d_AspectLine3d
|
||||
@@ -75,4 +82,6 @@ is
|
||||
-- defined by AspectLine.
|
||||
--
|
||||
|
||||
MyShaderProgram : ShaderProgram_Handle from Graphic3d;
|
||||
|
||||
end AspectLine3d;
|
||||
|
@@ -58,3 +58,13 @@ Graphic3d_AspectLine3d::Graphic3d_AspectLine3d () {
|
||||
// initialisation of AspectLine with AColor, AType, AWidth.
|
||||
|
||||
Graphic3d_AspectLine3d::Graphic3d_AspectLine3d (const Quantity_Color& AColor, const Aspect_TypeOfLine AType, const Standard_Real AWidth):Aspect_AspectLine (AColor, AType, AWidth) {}
|
||||
|
||||
void Graphic3d_AspectLine3d::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram)
|
||||
{
|
||||
MyShaderProgram = theProgram;
|
||||
}
|
||||
|
||||
const Handle(Graphic3d_ShaderProgram)& Graphic3d_AspectLine3d::ShaderProgram() const
|
||||
{
|
||||
return MyShaderProgram;
|
||||
}
|
||||
|
@@ -32,11 +32,12 @@ class AspectMarker3d from Graphic3d inherits AspectMarker from Aspect
|
||||
|
||||
uses
|
||||
|
||||
Color from Quantity,
|
||||
TypeOfMarker from Aspect,
|
||||
HArray1OfByte from TColStd,
|
||||
PixMap_Handle from Image,
|
||||
MarkerImage_Handle from Graphic3d
|
||||
Color from Quantity,
|
||||
TypeOfMarker from Aspect,
|
||||
HArray1OfByte from TColStd,
|
||||
PixMap_Handle from Image,
|
||||
MarkerImage_Handle from Graphic3d,
|
||||
ShaderProgram_Handle from Graphic3d
|
||||
|
||||
is
|
||||
|
||||
@@ -89,6 +90,15 @@ is
|
||||
theHeight : Integer from Standard;
|
||||
theTexture: HArray1OfByte from TColStd ) is static;
|
||||
|
||||
SetShaderProgram ( me : mutable;
|
||||
theProgram : ShaderProgram_Handle from Graphic3d );
|
||||
---Level: Public
|
||||
---Purpose: Sets up OpenGL/GLSL shader program.
|
||||
|
||||
ShaderProgram ( me )
|
||||
returns ShaderProgram_Handle from Graphic3d;
|
||||
---C++: return const &
|
||||
|
||||
fields
|
||||
|
||||
--
|
||||
@@ -105,4 +115,6 @@ fields
|
||||
|
||||
myMarkerImage : MarkerImage_Handle from Graphic3d is protected;
|
||||
|
||||
MyShaderProgram : ShaderProgram_Handle from Graphic3d;
|
||||
|
||||
end AspectMarker3d;
|
||||
|
@@ -99,3 +99,21 @@ void Graphic3d_AspectMarker3d::SetBitMap (const Standard_Integer theWidth,
|
||||
myMarkerImage.Nullify();
|
||||
myMarkerImage = new Graphic3d_MarkerImage (theTextureBitMap, theWidth, theHeight);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetShaderProgram
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Graphic3d_AspectMarker3d::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram)
|
||||
{
|
||||
MyShaderProgram = theProgram;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ShaderProgram
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const Handle(Graphic3d_ShaderProgram)& Graphic3d_AspectMarker3d::ShaderProgram() const
|
||||
{
|
||||
return MyShaderProgram;
|
||||
}
|
||||
|
@@ -36,11 +36,12 @@ class AspectText3d from Graphic3d inherits TShared
|
||||
|
||||
uses
|
||||
|
||||
Color from Quantity,
|
||||
TypeOfStyleText from Aspect,
|
||||
TypeOfDisplayText from Aspect,
|
||||
AsciiString from TCollection,
|
||||
FontAspect from Font
|
||||
Color from Quantity,
|
||||
TypeOfStyleText from Aspect,
|
||||
TypeOfDisplayText from Aspect,
|
||||
AsciiString from TCollection,
|
||||
FontAspect from Font,
|
||||
ShaderProgram_Handle from Graphic3d
|
||||
|
||||
raises
|
||||
|
||||
@@ -178,11 +179,10 @@ is
|
||||
---Level: Public
|
||||
---Purpose: Returns text FontAspect
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SetShaderProgram ( me : mutable;
|
||||
theProgram : ShaderProgram_Handle from Graphic3d );
|
||||
---Level: Public
|
||||
---Purpose: Sets up OpenGL/GLSL shader program.
|
||||
|
||||
----------------------------
|
||||
-- Category: Inquire methods
|
||||
@@ -245,7 +245,11 @@ is
|
||||
---Purpose: Returns the current values of the group <me>.
|
||||
---Category: Inquire methods
|
||||
|
||||
--
|
||||
ShaderProgram ( me )
|
||||
returns ShaderProgram_Handle from Graphic3d;
|
||||
---C++: return const &
|
||||
|
||||
--
|
||||
|
||||
fields
|
||||
|
||||
@@ -292,4 +296,6 @@ fields
|
||||
-- the variable turning FontAspect of the text
|
||||
MyTextFontAspect : FontAspect from Font;
|
||||
|
||||
MyShaderProgram : ShaderProgram_Handle from Graphic3d;
|
||||
|
||||
end AspectText3d;
|
||||
|
@@ -253,5 +253,12 @@ void Graphic3d_AspectText3d::Values ( Quantity_Color& AColor,
|
||||
|
||||
}
|
||||
|
||||
void Graphic3d_AspectText3d::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram)
|
||||
{
|
||||
MyShaderProgram = theProgram;
|
||||
}
|
||||
|
||||
|
||||
const Handle(Graphic3d_ShaderProgram)& Graphic3d_AspectText3d::ShaderProgram() const
|
||||
{
|
||||
return MyShaderProgram;
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include <InterfaceGraphic_Visual3d.hxx>
|
||||
#include <Graphic3d_CTexture.hxx>
|
||||
#include <Graphic3d_MarkerImage_Handle.hxx>
|
||||
#include <Graphic3d_ShaderProgram_Handle.hxx>
|
||||
|
||||
class Graphic3d_CStructure;
|
||||
|
||||
@@ -80,6 +81,8 @@ public:
|
||||
float PolygonOffsetFactor;
|
||||
float PolygonOffsetUnits;
|
||||
|
||||
Handle(Graphic3d_ShaderProgram) ShaderProgram;
|
||||
|
||||
};
|
||||
|
||||
class CALL_DEF_CONTEXTMARKER
|
||||
@@ -104,6 +107,7 @@ public:
|
||||
Aspect_TypeOfMarker MarkerType;
|
||||
Standard_ShortReal Scale;
|
||||
Handle(Graphic3d_MarkerImage) MarkerImage;
|
||||
Handle(Graphic3d_ShaderProgram) ShaderProgram;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -46,6 +46,7 @@
|
||||
#include <Graphic3d_Group.jxx>
|
||||
#include <Graphic3d_Group.pxx>
|
||||
#include <Graphic3d_TextureMap.hxx>
|
||||
#include <Graphic3d_ShaderProgram.hxx>
|
||||
|
||||
//-Methods, in order
|
||||
|
||||
@@ -68,13 +69,14 @@ void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLin
|
||||
MyCGroup.ContextLine.Width = float (AWidth);
|
||||
MyCGroup.ContextLine.IsDef = 1;
|
||||
|
||||
MyCGroup.ContextLine.ShaderProgram = CTX->ShaderProgram();
|
||||
|
||||
int noinsert = 1;
|
||||
MyGraphicDriver->LineContextGroup (MyCGroup, noinsert);
|
||||
|
||||
MyCGroup.ContextLine.IsSet = 1;
|
||||
|
||||
Update ();
|
||||
|
||||
}
|
||||
|
||||
void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
|
||||
@@ -277,13 +279,14 @@ void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFil
|
||||
MyCGroup.ContextFillArea.PolygonOffsetUnits = aPolyUnits;
|
||||
// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
|
||||
|
||||
MyCGroup.ContextFillArea.ShaderProgram = CTX->ShaderProgram();
|
||||
|
||||
int noinsert = 1;
|
||||
MyGraphicDriver->FaceContextGroup (MyCGroup, noinsert);
|
||||
|
||||
MyCGroup.ContextFillArea.IsSet = 1;
|
||||
|
||||
Update ();
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theCtx)
|
||||
@@ -306,6 +309,8 @@ void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMar
|
||||
MyCGroup.ContextMarker.Scale = Standard_ShortReal (aScale);
|
||||
MyCGroup.ContextMarker.MarkerImage = theCtx->GetMarkerImage();
|
||||
|
||||
MyCGroup.ContextMarker.ShaderProgram = theCtx->ShaderProgram();
|
||||
|
||||
int noinsert = 1;
|
||||
MyGraphicDriver->MarkerContextGroup (MyCGroup, noinsert);
|
||||
|
||||
@@ -350,6 +355,8 @@ void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectTex
|
||||
MyCGroup.ContextText.TextAngle = float (ATextAngle);
|
||||
MyCGroup.ContextText.TextFontAspect = (int)ATextFontAspect;
|
||||
|
||||
MyCGroup.ContextText.ShaderProgram = CTX->ShaderProgram();
|
||||
|
||||
MyCGroup.ContextText.IsDef = 1;
|
||||
|
||||
int noinsert = 1;
|
||||
@@ -358,7 +365,6 @@ void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectTex
|
||||
MyCGroup.ContextText.IsSet = 1;
|
||||
|
||||
Update ();
|
||||
|
||||
}
|
||||
|
||||
void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
|
||||
@@ -380,13 +386,14 @@ void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)&
|
||||
MyCGroup.ContextLine.Width = float (AWidth);
|
||||
MyCGroup.ContextLine.IsDef = 1;
|
||||
|
||||
MyCGroup.ContextLine.ShaderProgram = CTX->ShaderProgram();
|
||||
|
||||
int noinsert = 0;
|
||||
MyGraphicDriver->LineContextGroup (MyCGroup, noinsert);
|
||||
|
||||
MyCGroup.ContextLine.IsSet = 1;
|
||||
|
||||
Update ();
|
||||
|
||||
}
|
||||
|
||||
void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
|
||||
@@ -584,13 +591,14 @@ void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea
|
||||
MyCGroup.ContextFillArea.PolygonOffsetUnits = (Standard_ShortReal)aPolyUnits;
|
||||
// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
|
||||
|
||||
MyCGroup.ContextFillArea.ShaderProgram = CTX->ShaderProgram();
|
||||
|
||||
int noinsert = 0;
|
||||
MyGraphicDriver->FaceContextGroup (MyCGroup, noinsert);
|
||||
|
||||
MyCGroup.ContextFillArea.IsSet = 1;
|
||||
|
||||
Update ();
|
||||
|
||||
}
|
||||
|
||||
void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& thCtx)
|
||||
@@ -613,6 +621,8 @@ void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d
|
||||
MyCGroup.ContextMarker.Scale = Standard_ShortReal (aScale);
|
||||
MyCGroup.ContextMarker.MarkerImage = thCtx->GetMarkerImage();
|
||||
|
||||
MyCGroup.ContextMarker.ShaderProgram = thCtx->ShaderProgram();
|
||||
|
||||
int noinsert = 0;
|
||||
MyGraphicDriver->MarkerContextGroup (MyCGroup, noinsert);
|
||||
|
||||
@@ -658,13 +668,14 @@ void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)&
|
||||
MyCGroup.ContextText.TextFontAspect = (int)ATextFontAspect;
|
||||
MyCGroup.ContextText.IsDef = 1;
|
||||
|
||||
MyCGroup.ContextText.ShaderProgram = CTX->ShaderProgram();
|
||||
|
||||
int noinsert = 0;
|
||||
MyGraphicDriver->TextContextGroup (MyCGroup, noinsert);
|
||||
|
||||
MyCGroup.ContextText.IsSet = 1;
|
||||
|
||||
Update ();
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
Standard_Boolean Graphic3d_Group::IsGroupPrimitivesAspectSet (const Graphic3d_GroupAspect theAspect) const {
|
||||
|
96
src/Graphic3d/Graphic3d_ShaderObject.cxx
Normal file
96
src/Graphic3d/Graphic3d_ShaderObject.cxx
Normal file
@@ -0,0 +1,96 @@
|
||||
// Created on: 2013-09-20
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#include <OSD_File.hxx>
|
||||
#include <OSD_Protection.hxx>
|
||||
#include <Standard_Atomic.hxx>
|
||||
#include <Graphic3d_ShaderObject.hxx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
|
||||
namespace
|
||||
{
|
||||
static volatile Standard_Integer THE_SHADER_OBJECT_COUNTER = 0;
|
||||
};
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE (Graphic3d_ShaderObject, Standard_Transient)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ShaderObject, Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
// function : Graphic3d_ShaderObject
|
||||
// purpose : Creates a shader object from specified file
|
||||
// =======================================================================
|
||||
Graphic3d_ShaderObject::Graphic3d_ShaderObject (const Graphic3d_TypeOfShaderObject theType)
|
||||
: myType (theType)
|
||||
{
|
||||
myID = TCollection_AsciiString ("Graphic3d_ShaderObject_")
|
||||
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_SHADER_OBJECT_COUNTER));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : CreatFromFile
|
||||
// purpose : Creates new shader object from specified file
|
||||
// =======================================================================
|
||||
Handle(Graphic3d_ShaderObject) Graphic3d_ShaderObject::CreateFromFile (const Graphic3d_TypeOfShaderObject theType,
|
||||
const TCollection_AsciiString& thePath)
|
||||
{
|
||||
Handle(Graphic3d_ShaderObject) aShader = new Graphic3d_ShaderObject (theType);
|
||||
aShader->myPath = thePath;
|
||||
|
||||
OSD_File aFile (thePath);
|
||||
if (!aFile.Exists())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
aFile.Open (OSD_ReadOnly, OSD_Protection());
|
||||
aFile.Read (aShader->mySource, aFile.Size());
|
||||
aFile.Close();
|
||||
|
||||
return aShader;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : CreatFromSource
|
||||
// purpose : Creates new shader object from specified source
|
||||
// =======================================================================
|
||||
Handle(Graphic3d_ShaderObject) Graphic3d_ShaderObject::CreateFromSource (const Graphic3d_TypeOfShaderObject theType,
|
||||
const TCollection_AsciiString& theSource)
|
||||
{
|
||||
Handle(Graphic3d_ShaderObject) aShader = new Graphic3d_ShaderObject (theType);
|
||||
aShader->mySource = theSource;
|
||||
return aShader;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Graphic3d_ShaderObject
|
||||
// purpose : Releases resources of shader object
|
||||
// =======================================================================
|
||||
Graphic3d_ShaderObject::~Graphic3d_ShaderObject()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : IsDone
|
||||
// purpose : Checks if the shader object is valid or not
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_ShaderObject::IsDone() const
|
||||
{
|
||||
return !mySource.IsEmpty();
|
||||
}
|
80
src/Graphic3d/Graphic3d_ShaderObject.hxx
Normal file
80
src/Graphic3d/Graphic3d_ShaderObject.hxx
Normal file
@@ -0,0 +1,80 @@
|
||||
// Created on: 2013-09-20
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _Graphic3d_ShaderObject_HeaderFile
|
||||
#define _Graphic3d_ShaderObject_HeaderFile
|
||||
|
||||
#include <OSD_Path.hxx>
|
||||
|
||||
#include <Graphic3d_TypeOfShaderObject.hxx>
|
||||
#include <Graphic3d_ShaderObject_Handle.hxx>
|
||||
|
||||
//! This class is responsible for managing shader objects.
|
||||
class Graphic3d_ShaderObject : public Standard_Transient
|
||||
{
|
||||
private:
|
||||
|
||||
//! Creates new shader object of specified type.
|
||||
Standard_EXPORT Graphic3d_ShaderObject (const Graphic3d_TypeOfShaderObject theType);
|
||||
|
||||
public:
|
||||
|
||||
//! Releases resources of shader object.
|
||||
Standard_EXPORT virtual ~Graphic3d_ShaderObject();
|
||||
|
||||
//! Checks if the shader object is valid or not.
|
||||
Standard_EXPORT virtual Standard_Boolean IsDone() const;
|
||||
|
||||
//! Returns the full path to the shader source.
|
||||
const OSD_Path& Path() const { return myPath; }
|
||||
|
||||
//! Returns the source code of the shader object.
|
||||
const TCollection_AsciiString& Source() const { return mySource; }
|
||||
|
||||
//! Returns type of the shader object.
|
||||
Graphic3d_TypeOfShaderObject Type() const { return myType; }
|
||||
|
||||
//! Returns unique ID used to manage resource in graphic driver.
|
||||
const TCollection_AsciiString& GetId() const { return myID; }
|
||||
|
||||
//! Creates new shader object from specified file.
|
||||
Standard_EXPORT static Handle(Graphic3d_ShaderObject) CreateFromFile (const Graphic3d_TypeOfShaderObject theType,
|
||||
const TCollection_AsciiString& thePath);
|
||||
|
||||
//! Creates new shader object from specified source.
|
||||
Standard_EXPORT static Handle(Graphic3d_ShaderObject) CreateFromSource (const Graphic3d_TypeOfShaderObject theType,
|
||||
const TCollection_AsciiString& theSource);
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTI (Graphic3d_ShaderObject)
|
||||
|
||||
protected:
|
||||
|
||||
TCollection_AsciiString myID; //!< the ID of shader object
|
||||
TCollection_AsciiString mySource; //!< the source code of shader object
|
||||
OSD_Path myPath; //!< the path to shader source (may be empty)
|
||||
|
||||
private:
|
||||
|
||||
//! The type of shader object.
|
||||
Graphic3d_TypeOfShaderObject myType;
|
||||
};
|
||||
|
||||
#endif
|
30
src/Graphic3d/Graphic3d_ShaderObject_Handle.hxx
Normal file
30
src/Graphic3d/Graphic3d_ShaderObject_Handle.hxx
Normal file
@@ -0,0 +1,30 @@
|
||||
// Created on: 2013-09-20
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _Handle_Graphic3d_ShaderObject_HeaderFile
|
||||
#define _Handle_Graphic3d_ShaderObject_HeaderFile
|
||||
|
||||
#include <Standard_Transient.hxx>
|
||||
|
||||
class Graphic3d_ShaderObject;
|
||||
DEFINE_STANDARD_HANDLE (Graphic3d_ShaderObject, Standard_Transient)
|
||||
|
||||
typedef Handle(Graphic3d_ShaderObject) Graphic3d_ShaderObject_Handle;
|
||||
|
||||
#endif
|
132
src/Graphic3d/Graphic3d_ShaderProgram.cxx
Normal file
132
src/Graphic3d/Graphic3d_ShaderProgram.cxx
Normal file
@@ -0,0 +1,132 @@
|
||||
// Created on: 2013-09-20
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#include <Standard_Atomic.hxx>
|
||||
#include <Standard_Assert.hxx>
|
||||
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
#include <Graphic3d_ShaderObject.hxx>
|
||||
#include <Graphic3d_ShaderProgram.hxx>
|
||||
|
||||
namespace
|
||||
{
|
||||
static volatile Standard_Integer THE_PROGRAM_OBJECT_COUNTER = 0;
|
||||
};
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE (Graphic3d_ShaderProgram, Standard_Transient)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ShaderProgram, Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
// function : Graphic3d_ShaderProgram
|
||||
// purpose : Creates new empty program object
|
||||
// =======================================================================
|
||||
Graphic3d_ShaderProgram::Graphic3d_ShaderProgram()
|
||||
{
|
||||
myID = TCollection_AsciiString ("Graphic3d_ShaderProgram_")
|
||||
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_PROGRAM_OBJECT_COUNTER));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Graphic3d_ShaderProgram
|
||||
// purpose : Releases resources of program object
|
||||
// =======================================================================
|
||||
Graphic3d_ShaderProgram::~Graphic3d_ShaderProgram()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Destroy
|
||||
// purpose : Releases resources of program object
|
||||
// =======================================================================
|
||||
void Graphic3d_ShaderProgram::Destroy() const
|
||||
{ }
|
||||
|
||||
// =======================================================================
|
||||
// function : IsDone
|
||||
// purpose : Checks if the program object is valid or not
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_ShaderProgram::IsDone() const
|
||||
{
|
||||
if (myShaderObjects.IsEmpty())
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
for (Graphic3d_ShaderObjectList::Iterator anIt (myShaderObjects); anIt.More(); anIt.Next())
|
||||
{
|
||||
if (!anIt.Value()->IsDone())
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AttachShader
|
||||
// purpose : Attaches shader object to the program object
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_ShaderProgram::AttachShader (const Handle(Graphic3d_ShaderObject)& theShader)
|
||||
{
|
||||
if (theShader.IsNull())
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
for (Graphic3d_ShaderObjectList::Iterator anIt (myShaderObjects); anIt.More(); anIt.Next())
|
||||
{
|
||||
if (anIt.Value() == theShader)
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
myShaderObjects.Append (theShader);
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : DetachShader
|
||||
// purpose : Detaches shader object from the program object
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_ShaderProgram::DetachShader (const Handle(Graphic3d_ShaderObject)& theShader)
|
||||
{
|
||||
if (theShader.IsNull())
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
for (Graphic3d_ShaderObjectList::Iterator anIt (myShaderObjects); anIt.More(); anIt.Next())
|
||||
{
|
||||
if (anIt.Value() == theShader)
|
||||
{
|
||||
myShaderObjects.Remove (anIt);
|
||||
return Standard_True;
|
||||
}
|
||||
}
|
||||
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ClearVariables
|
||||
// purpose : Removes all custom uniform variables from the program
|
||||
// =======================================================================
|
||||
void Graphic3d_ShaderProgram::ClearVariables()
|
||||
{
|
||||
myVariables.Clear();
|
||||
}
|
104
src/Graphic3d/Graphic3d_ShaderProgram.hxx
Normal file
104
src/Graphic3d/Graphic3d_ShaderProgram.hxx
Normal file
@@ -0,0 +1,104 @@
|
||||
// Created on: 2013-09-20
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _Graphic3d_ShaderProgram_HeaderFile
|
||||
#define _Graphic3d_ShaderProgram_HeaderFile
|
||||
|
||||
#include <Graphic3d_ShaderObject_Handle.hxx>
|
||||
#include <Graphic3d_ShaderProgram_Handle.hxx>
|
||||
#include <Graphic3d_ShaderVariable.hxx>
|
||||
#include <NCollection_Sequence.hxx>
|
||||
|
||||
//! List of shader objects.
|
||||
typedef NCollection_Sequence<Handle(Graphic3d_ShaderObject)> Graphic3d_ShaderObjectList;
|
||||
|
||||
//! List of custom uniform shader variables.
|
||||
typedef NCollection_Sequence<Handle(Graphic3d_ShaderVariable)> Graphic3d_ShaderVariableList;
|
||||
|
||||
//! This class is responsible for managing shader programs.
|
||||
class Graphic3d_ShaderProgram : public Standard_Transient
|
||||
{
|
||||
public:
|
||||
|
||||
//! Creates new empty program object.
|
||||
Standard_EXPORT Graphic3d_ShaderProgram();
|
||||
|
||||
//! Releases resources of program object.
|
||||
Standard_EXPORT virtual ~Graphic3d_ShaderProgram();
|
||||
|
||||
//! Releases resources of program object.
|
||||
Standard_EXPORT void Destroy() const;
|
||||
|
||||
//! Checks if the program object is valid or not.
|
||||
Standard_EXPORT virtual Standard_Boolean IsDone() const;
|
||||
|
||||
//! Returns unique ID used to manage resource in graphic driver.
|
||||
const TCollection_AsciiString& GetId() const { return myID; }
|
||||
|
||||
//! Attaches shader object to the program object.
|
||||
Standard_EXPORT Standard_Boolean AttachShader (const Handle(Graphic3d_ShaderObject)& theShader);
|
||||
|
||||
//! Detaches shader object from the program object.
|
||||
Standard_EXPORT Standard_Boolean DetachShader (const Handle(Graphic3d_ShaderObject)& theShader);
|
||||
|
||||
//! Returns list of attached shader objects.
|
||||
const Graphic3d_ShaderObjectList& ShaderObjects() const { return myShaderObjects; }
|
||||
|
||||
//! Returns list of custom uniform variables.
|
||||
const Graphic3d_ShaderVariableList& Variables() const { return myVariables; }
|
||||
|
||||
//! Pushes custom uniform variable to the program.
|
||||
template<class T>
|
||||
Standard_Boolean PushVariable (const TCollection_AsciiString& theName,
|
||||
const T& theValue);
|
||||
|
||||
//! Removes all custom uniform variables from the program.
|
||||
Standard_EXPORT void ClearVariables();
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTI (Graphic3d_ShaderProgram)
|
||||
|
||||
private:
|
||||
|
||||
TCollection_AsciiString myID; //!< The unique identifier of program object.
|
||||
Graphic3d_ShaderObjectList myShaderObjects; //!< the list of attached shader objects.
|
||||
Graphic3d_ShaderVariableList myVariables; //!< the list of custom uniform variables.
|
||||
|
||||
};
|
||||
|
||||
// =======================================================================
|
||||
// function : PushVariable
|
||||
// purpose : Pushes custom uniform variable to the program
|
||||
// =======================================================================
|
||||
template<class T> inline
|
||||
Standard_Boolean Graphic3d_ShaderProgram::PushVariable (const TCollection_AsciiString& theName,
|
||||
const T& theValue)
|
||||
{
|
||||
Handle(Graphic3d_ShaderVariable) aVariable = Graphic3d_ShaderVariable::Create (theName, theValue);
|
||||
if (aVariable.IsNull() || !aVariable->IsDone())
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
myVariables.Append (aVariable);
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
#endif
|
30
src/Graphic3d/Graphic3d_ShaderProgram_Handle.hxx
Normal file
30
src/Graphic3d/Graphic3d_ShaderProgram_Handle.hxx
Normal file
@@ -0,0 +1,30 @@
|
||||
// Created on: 2013-09-20
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _Handle_Graphic3d_ShaderProgram_HeaderFile
|
||||
#define _Handle_Graphic3d_ShaderProgram_HeaderFile
|
||||
|
||||
#include <Standard_Transient.hxx>
|
||||
|
||||
class Graphic3d_ShaderProgram;
|
||||
DEFINE_STANDARD_HANDLE (Graphic3d_ShaderProgram, Standard_Transient)
|
||||
|
||||
typedef Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderProgram_Handle;
|
||||
|
||||
#endif
|
93
src/Graphic3d/Graphic3d_ShaderVariable.cxx
Normal file
93
src/Graphic3d/Graphic3d_ShaderVariable.cxx
Normal file
@@ -0,0 +1,93 @@
|
||||
// Created on: 2013-09-25
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#include <Standard_Atomic.hxx>
|
||||
|
||||
#include <Graphic3d_ShaderVariable.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE (Graphic3d_ShaderVariable, Standard_Transient)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ShaderVariable, Standard_Transient)
|
||||
|
||||
//
|
||||
// Specific instantiations of struct templates to avoid compilation warnings
|
||||
//
|
||||
template struct Graphic3d_UniformValue<int>;
|
||||
template struct Graphic3d_UniformValue<float>;
|
||||
template struct Graphic3d_UniformValue<OpenGl_Vec2>;
|
||||
template struct Graphic3d_UniformValue<OpenGl_Vec3>;
|
||||
template struct Graphic3d_UniformValue<OpenGl_Vec4>;
|
||||
template struct Graphic3d_UniformValue<OpenGl_Vec2i>;
|
||||
template struct Graphic3d_UniformValue<OpenGl_Vec3i>;
|
||||
template struct Graphic3d_UniformValue<OpenGl_Vec4i>;
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Graphic3d_ValueInterface
|
||||
// purpose : Releases memory resources of variable value
|
||||
// =======================================================================
|
||||
Graphic3d_ValueInterface::~Graphic3d_ValueInterface()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Graphic3d_ShaderVariable
|
||||
// purpose : Creates new abstract shader variable
|
||||
// =======================================================================
|
||||
Graphic3d_ShaderVariable::Graphic3d_ShaderVariable (const TCollection_AsciiString& theName)
|
||||
: myName (theName),
|
||||
myValue (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Graphic3d_ShaderVariableBase
|
||||
// purpose : Releases resources of shader variable
|
||||
// =======================================================================
|
||||
Graphic3d_ShaderVariable::~Graphic3d_ShaderVariable()
|
||||
{
|
||||
delete myValue;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : IsDone
|
||||
// purpose : Checks if the shader variable is valid or not
|
||||
// =======================================================================
|
||||
Standard_Boolean Graphic3d_ShaderVariable::IsDone() const
|
||||
{
|
||||
return !myName.IsEmpty() && (myValue != NULL);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Name
|
||||
// purpose : Returns name of shader variable
|
||||
// =======================================================================
|
||||
const TCollection_AsciiString& Graphic3d_ShaderVariable::Name() const
|
||||
{
|
||||
return myName;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Value
|
||||
// purpose : Returns interface of shader variable value
|
||||
// =======================================================================
|
||||
Graphic3d_ValueInterface* Graphic3d_ShaderVariable::Value()
|
||||
{
|
||||
return myValue;
|
||||
}
|
171
src/Graphic3d/Graphic3d_ShaderVariable.hxx
Normal file
171
src/Graphic3d/Graphic3d_ShaderVariable.hxx
Normal file
@@ -0,0 +1,171 @@
|
||||
// Created on: 2013-09-25
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _Graphic3d_ShaderVariable_HeaderFile
|
||||
#define _Graphic3d_ShaderVariable_HeaderFile
|
||||
|
||||
#include <OpenGl_Vec.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
#include <Graphic3d_ShaderVariable_Handle.hxx>
|
||||
|
||||
//! Interface for generic variable value.
|
||||
struct Graphic3d_ValueInterface
|
||||
{
|
||||
//! Releases memory resources of variable value.
|
||||
Standard_EXPORT virtual ~Graphic3d_ValueInterface();
|
||||
|
||||
//! Returns unique identifier of value type.
|
||||
virtual Standard_Size TypeID() const = 0;
|
||||
|
||||
//! Returns variable value casted to specified type.
|
||||
template <class T> T& As();
|
||||
|
||||
//! Returns variable value casted to specified type.
|
||||
template <class T> const T& As() const;
|
||||
};
|
||||
|
||||
//! Generates unique type identifier for variable value.
|
||||
template<class T>
|
||||
struct Graphic3d_UniformValueTypeID {
|
||||
/* Not implemented */
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<int> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<float> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<OpenGl_Vec2> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<OpenGl_Vec3> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<OpenGl_Vec4> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<OpenGl_Vec2i> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<OpenGl_Vec3i> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Graphic3d_UniformValueTypeID<OpenGl_Vec4i> {
|
||||
static const Standard_Size ID = __LINE__;
|
||||
};
|
||||
|
||||
//! Describes specific value of custom uniform variable.
|
||||
template <class T>
|
||||
struct Graphic3d_UniformValue : public Graphic3d_ValueInterface
|
||||
{
|
||||
//! Creates new variable value.
|
||||
Graphic3d_UniformValue (const T& theValue) : Value (theValue) { }
|
||||
|
||||
//! Returns unique identifier of value type.
|
||||
virtual Standard_Size TypeID() const;
|
||||
|
||||
//! Value of custom uniform variable.
|
||||
T Value;
|
||||
};
|
||||
|
||||
//! Integer uniform value.
|
||||
typedef Graphic3d_UniformValue<int> Graphic3d_UniformInt;
|
||||
|
||||
//! Integer uniform 2D vector.
|
||||
typedef Graphic3d_UniformValue<OpenGl_Vec2i> Graphic3d_UniformVec2i;
|
||||
|
||||
//! Integer uniform 3D vector.
|
||||
typedef Graphic3d_UniformValue<OpenGl_Vec3i> Graphic3d_UniformVec3i;
|
||||
|
||||
//! Integer uniform 4D vector.
|
||||
typedef Graphic3d_UniformValue<OpenGl_Vec4i> Graphic3d_UniformVec4i;
|
||||
|
||||
//! Floating-point uniform value.
|
||||
typedef Graphic3d_UniformValue<float> Graphic3d_UniformFloat;
|
||||
|
||||
//! Floating-point uniform 2D vector.
|
||||
typedef Graphic3d_UniformValue<OpenGl_Vec2> Graphic3d_UniformVec2;
|
||||
|
||||
//! Floating-point uniform 3D vector.
|
||||
typedef Graphic3d_UniformValue<OpenGl_Vec3> Graphic3d_UniformVec3;
|
||||
|
||||
//! Floating-point uniform 4D vector.
|
||||
typedef Graphic3d_UniformValue<OpenGl_Vec4> Graphic3d_UniformVec4;
|
||||
|
||||
//! Describes custom uniform shader variable.
|
||||
class Graphic3d_ShaderVariable : public Standard_Transient
|
||||
{
|
||||
public:
|
||||
|
||||
//! Releases resources of shader variable.
|
||||
Standard_EXPORT virtual ~Graphic3d_ShaderVariable();
|
||||
|
||||
//! Returns name of shader variable.
|
||||
Standard_EXPORT const TCollection_AsciiString& Name() const;
|
||||
|
||||
//! Checks if the shader variable is valid or not.
|
||||
Standard_EXPORT Standard_Boolean IsDone() const;
|
||||
|
||||
//! Returns interface of shader variable value.
|
||||
Standard_EXPORT Graphic3d_ValueInterface* Value();
|
||||
|
||||
//! Creates new initialized shader variable.
|
||||
template<class T>
|
||||
static Graphic3d_ShaderVariable* Create (const TCollection_AsciiString& theName,
|
||||
const T& theValue);
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTI (Graphic3d_ShaderVariable)
|
||||
|
||||
protected:
|
||||
|
||||
//! Creates new uninitialized shader variable.
|
||||
Standard_EXPORT Graphic3d_ShaderVariable (const TCollection_AsciiString& theName);
|
||||
|
||||
protected:
|
||||
|
||||
//! The name of uniform shader variable.
|
||||
TCollection_AsciiString myName;
|
||||
|
||||
//! The generic value of shader variable.
|
||||
Graphic3d_ValueInterface* myValue;
|
||||
};
|
||||
|
||||
#include <Graphic3d_ShaderVariable.lxx>
|
||||
|
||||
#endif // _Graphic3d_ShaderVariable_HeaderFile
|
63
src/Graphic3d/Graphic3d_ShaderVariable.lxx
Normal file
63
src/Graphic3d/Graphic3d_ShaderVariable.lxx
Normal file
@@ -0,0 +1,63 @@
|
||||
// Created on: 2013-09-25
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
// =======================================================================
|
||||
// function : As
|
||||
// purpose : Returns variable value casted to specified type
|
||||
// =======================================================================
|
||||
template <class T> inline
|
||||
T& Graphic3d_ValueInterface::As()
|
||||
{
|
||||
Graphic3d_UniformValue<T>* aPtr = dynamic_cast<Graphic3d_UniformValue<T>*> (this);
|
||||
return aPtr->Value;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : As
|
||||
// purpose : Returns variable value casted to specified type
|
||||
// =======================================================================
|
||||
template <class T> inline
|
||||
const T& Graphic3d_ValueInterface::As() const
|
||||
{
|
||||
const Graphic3d_UniformValue<T>* aPtr = dynamic_cast<const Graphic3d_UniformValue<T>*> (this);
|
||||
return aPtr->Value;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : TypeID
|
||||
// purpose : Returns unique identifier of value type
|
||||
// =======================================================================
|
||||
template <class T> inline
|
||||
Standard_Size Graphic3d_UniformValue<T>::TypeID() const
|
||||
{
|
||||
return Graphic3d_UniformValueTypeID<T>::ID;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose : Creates initialized shader variable
|
||||
// =======================================================================
|
||||
template<class T> inline
|
||||
Graphic3d_ShaderVariable* Graphic3d_ShaderVariable::Create (const TCollection_AsciiString& theName,
|
||||
const T& theValue)
|
||||
{
|
||||
Graphic3d_ShaderVariable* theVariable = new Graphic3d_ShaderVariable (theName);
|
||||
theVariable->myValue = new Graphic3d_UniformValue<T> (theValue);
|
||||
return theVariable;
|
||||
}
|
28
src/Graphic3d/Graphic3d_ShaderVariable_Handle.hxx
Normal file
28
src/Graphic3d/Graphic3d_ShaderVariable_Handle.hxx
Normal file
@@ -0,0 +1,28 @@
|
||||
// Created on: 2013-09-25
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _Handle_Graphic3d_ShaderVariable_HeaderFile
|
||||
#define _Handle_Graphic3d_ShaderVariable_HeaderFile
|
||||
|
||||
#include <Standard_Transient.hxx>
|
||||
|
||||
class Graphic3d_ShaderVariable;
|
||||
DEFINE_STANDARD_HANDLE (Graphic3d_ShaderVariable, Standard_Transient)
|
||||
|
||||
#endif
|
30
src/Graphic3d/Graphic3d_TypeOfShaderObject.hxx
Normal file
30
src/Graphic3d/Graphic3d_TypeOfShaderObject.hxx
Normal file
@@ -0,0 +1,30 @@
|
||||
// Created on: 2013-09-20
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _Graphic3d_TypeOfShaderObject_HeaderFile
|
||||
#define _Graphic3d_TypeOfShaderObject_HeaderFile
|
||||
|
||||
//! Type of the shader object (may be extended).
|
||||
enum Graphic3d_TypeOfShaderObject
|
||||
{
|
||||
Graphic3d_TOS_VERTEX,
|
||||
Graphic3d_TOS_FRAGMENT
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user