0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / OpenGl / OpenGl_Sampler.hxx
1 // Created on: 2014-10-08
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef OPENGL_SAMPLER_H
17 #define OPENGL_SAMPLER_H
18
19 #include <OpenGl_Context.hxx>
20 #include <Handle_OpenGl_Sampler.hxx>
21
22 //! Class implements OpenGL sampler object resource that
23 //! stores the sampling parameters for a texture access.
24 class OpenGl_Sampler : public OpenGl_Resource
25 {
26 public:
27
28   //! Helpful constant defining invalid sampler identifier
29   static const GLuint NO_SAMPLER = 0;
30
31 public:
32
33   //! Creates new sampler object.
34   Standard_EXPORT OpenGl_Sampler();
35
36   //! Releases resources of sampler object.
37   Standard_EXPORT virtual ~OpenGl_Sampler();
38
39   //! Destroys object - will release GPU memory if any.
40   Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
41
42   //! Initializes sampler object.
43   Standard_EXPORT Standard_Boolean Init (OpenGl_Context& theContext);
44
45   //! Returns true if current object was initialized.
46   Standard_Boolean IsValid() const
47   {
48     return isValidSampler();
49   }
50
51   //! Binds sampler object to the given texture unit.
52   Standard_EXPORT void Bind (OpenGl_Context& theContext, const GLuint theUnit = 0);
53
54   //! Unbinds sampler object from the given texture unit.
55   Standard_EXPORT void Unbind (OpenGl_Context& theContext, const GLuint theUnit = 0);
56
57   //! Sets specific sampler parameter.
58   Standard_EXPORT void SetParameter (OpenGl_Context& theContext, const GLenum theParam, const GLint theValue);
59
60   //! Returns OpenGL sampler ID.
61   GLuint SamplerID() const
62   {
63     return mySamplerID;
64   }
65
66 protected:
67
68   //! Checks if sampler object is valid.
69   Standard_Boolean isValidSampler() const
70   {
71     return mySamplerID != NO_SAMPLER;
72   }
73
74 protected:
75
76   GLuint mySamplerID; //!< OpenGL sampler object ID
77
78 public:
79
80   DEFINE_STANDARD_RTTI(OpenGl_Sampler, OpenGl_Resource)
81
82 };
83
84 #endif // OPENGL_SAMPLER_H