0027943: Visualization - fix broken shading by positional light for object with local...
[occt.git] / src / OpenGl / OpenGl_AspectFace.hxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef _OpenGl_AspectFace_Header
17#define _OpenGl_AspectFace_Header
18
2166f0fa 19#include <OpenGl_AspectLine.hxx>
4269bd1b 20#include <Graphic3d_AspectFillArea3d.hxx>
494782f6 21#include <Graphic3d_ShaderProgram.hxx>
30f0ad28 22#include <Graphic3d_TextureMap.hxx>
189f85a3 23#include <Graphic3d_BSDF.hxx>
2166f0fa 24
c04c30b3 25class OpenGl_Texture;
26
b6472664 27//! The element holding Graphic3d_AspectFillArea3d.
2166f0fa
SK
28class OpenGl_AspectFace : public OpenGl_Element
29{
2166f0fa 30
bf75be98 31public:
2166f0fa 32
b6472664 33 //! Empty constructor.
595a42a4 34 Standard_EXPORT OpenGl_AspectFace();
2166f0fa 35
b6472664 36 //! Create and assign parameters.
37 Standard_EXPORT OpenGl_AspectFace (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
38
39 //! Return aspect.
40 const Handle(Graphic3d_AspectFillArea3d)& Aspect() const { return myAspect; }
41
42 //! Assign parameters.
595a42a4 43 Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
fd4a6963 44
45 //! Set edge aspect.
b6472664 46 void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) { myAspectEdge = *theAspectEdge; }
fd4a6963 47
48 //! @return edge aspect.
b6472664 49 const OpenGl_AspectLine* AspectEdge() const { return &myAspectEdge; }
fd4a6963 50
b6472664 51 //! Returns true if lighting should be disabled.
52 bool IsNoLighting() const { return myIsNoLighting; }
fd4a6963 53
b6472664 54 //! Set if lighting should be disabled or not.
55 void SetNoLighting (bool theValue) { myIsNoLighting = theValue; }
fd4a6963 56
30f0ad28 57 //! @return texture mapping parameters.
58 const Handle(Graphic3d_TextureParams)& TextureParams() const
59 {
b6472664 60 return myAspect->TextureMap()->GetParams();
30f0ad28 61 }
62
fd4a6963 63 //! @return texture map.
8625ef7e 64 const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Context)& theCtx) const
fd4a6963 65 {
30f0ad28 66 if (!myResources.IsTextureReady())
fd4a6963 67 {
b6472664 68 myResources.BuildTexture (theCtx, myAspect->TextureMap());
30f0ad28 69 myResources.SetTextureReady();
fd4a6963 70 }
71
30f0ad28 72 return myResources.Texture;
fd4a6963 73 }
74
30f0ad28 75 //! Init and return OpenGl shader program resource.
76 //! @return shader program resource.
8625ef7e 77 const Handle(OpenGl_ShaderProgram)& ShaderProgramRes (const Handle(OpenGl_Context)& theCtx) const
fd4a6963 78 {
30f0ad28 79 if (!myResources.IsShaderReady())
80 {
b6472664 81 myResources.BuildShader (theCtx, myAspect->ShaderProgram());
30f0ad28 82 myResources.SetShaderReady();
83 }
84
85 return myResources.ShaderProgram;
fd4a6963 86 }
2166f0fa 87
595a42a4 88 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
10b9c7df 89 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
2166f0fa 90
30f0ad28 91protected:
92
93 //! OpenGl resources
94 mutable struct Resources
95 {
96 public:
97 Resources()
98 : myIsTextureReady (Standard_False),
99 myIsShaderReady (Standard_False) {}
100
101 Standard_Boolean IsTextureReady() const { return myIsTextureReady; }
102 Standard_Boolean IsShaderReady () const { return myIsShaderReady; }
103 void SetTextureReady() { myIsTextureReady = Standard_True; }
104 void SetShaderReady () { myIsShaderReady = Standard_True; }
f85399e5 105 void ResetTextureReadiness() { myIsTextureReady = Standard_False; }
106 void ResetShaderReadiness () { myIsShaderReady = Standard_False; }
30f0ad28 107
8625ef7e 108 Standard_EXPORT void BuildTexture (const Handle(OpenGl_Context)& theCtx,
595a42a4 109 const Handle(Graphic3d_TextureMap)& theTexture);
8625ef7e 110 Standard_EXPORT void BuildShader (const Handle(OpenGl_Context)& theCtx,
595a42a4 111 const Handle(Graphic3d_ShaderProgram)& theShader);
30f0ad28 112
595a42a4 113 Handle(OpenGl_Texture) Texture;
114 TCollection_AsciiString TextureId;
30f0ad28 115 Handle(OpenGl_ShaderProgram) ShaderProgram;
116 TCollection_AsciiString ShaderProgramId;
117
118 private:
bf75be98 119
30f0ad28 120 Standard_Boolean myIsTextureReady;
121 Standard_Boolean myIsShaderReady;
2166f0fa 122
30f0ad28 123 } myResources;
bf75be98 124
b6472664 125 Handle(Graphic3d_AspectFillArea3d) myAspect;
126 OpenGl_AspectLine myAspectEdge;
127 bool myIsNoLighting;
bf75be98 128
129public:
2166f0fa 130
1c35b92f 131 DEFINE_STANDARD_ALLOC
bf75be98 132
2166f0fa
SK
133};
134
135#endif //_OpenGl_AspectFace_Header