HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_Light.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GR_Light.h (GR Library, C++)
7  *
8  * COMMENTS:
9  * Light list and base class for all lights.
10  * Specific lights are defined in GR_LightTypes.h.
11  */
12 #ifndef GR_Light_h
13 #define GR_Light_h
14 
15 #include "GR_API.h"
16 #include "GR_Defines.h"
17 #include "GR_SceneItem.h"
18 
19 #include <UT/UT_Array.h>
20 #include <UT/UT_Map.h>
21 #include <UT/UT_Matrix4.h>
22 #include <UT/UT_Set.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_UniquePtr.h>
25 #include <UT/UT_Matrix4.h>
26 
27 class RV_Instance;
28 class RE_LightList;
29 class RV_Render;
30 class RV_ShaderBlock;
31 class RV_ShaderProgram;
34 
35 /// Base class for all light types
37 {
38 public:
39  enum LightType
40  {
45  AREA
46  };
47 
48  LightType type() const { return myType; }
49 
50  bool isHeadlight() const { return myIsHeadlight; }
51  void setHeadlight(bool e) { myIsHeadlight = e; }
52 
53  bool isEnabled() const { return myIsEnabled; }
54  void setEnabled(bool e) { myIsEnabled = e; }
55 
56  void setTransform(const UT_Matrix4D &t) { myTransform=t; }
57  const UT_Matrix4D &transform() const { return myTransform; }
58 
59  void setLightID(exint id) { setID(id); }
60 
61  bool initSceneSetForRender(
62  RV_Render *r,
64  UT_UniquePtr<RV_ShaderBlock> &scene_block,
66  bool initLightSetForRender(RV_Render *r,
68  bool bindSets(RV_Render *r, RV_ShaderProgramBase *shader);
69  virtual bool initBlocks(RV_Render *r) = 0;
70 
71  virtual RV_ShaderProgram *getShader(bool shadows, bool per_sample) = 0;
72 
73  static bool initShaders(RV_Instance *inst);
74  static void cleanupShaders();
75 
76 protected:
77  GR_Light(const UT_StringHolder &name, LightType type);
78  ~GR_Light() override;
79 
81 
82  bool privInitBlocks(RV_Render *r,
83  void *light_block, int light_size,
84  void *shadow_block, int shadow_size);
85  void privBindTexture(RV_Render *r, const UT_StringHolder &map_name,
86  int rel_op_id, RV_TextureRef &map_id,
87  const UT_StringHolder &sampler_name,
88  RV_TextureParms *tex_parms = nullptr,
89  bool is_cube = false);
90 
91  RV_ShaderProgram *privGetShader(exint tags);
92 
93 #ifdef USE_VULKAN
95  UT_UniquePtr<RV_ShaderBlock> myLightBlock;
96  UT_UniquePtr<RV_ShaderBlock> myShadowBlock;
97 #endif
98 
102 
103  enum
104  {
105  GLOBAL_SET = 0,
106  LIGHT_SET = 1
107  };
108 
109 private:
110  UT_Matrix4D myTransform;
111  LightType myType;
112  uint32
113  myIsHeadlight :1,
114  myIsEnabled :1;
115 };
116 
117 static inline void intrusive_ptr_add_ref(GR_Light *gl) { gl->incref(); }
118 static inline void intrusive_ptr_release(GR_Light *gl) { gl->decref(); }
119 
120 // List of lights currently contributing to the scene
122 {
123 public:
124  uint32 getLightMask(const UT_Set<int> &active) const;
125 
126  void setGLLights(RE_LightList *list) { myGLLights = list; }
127  const RE_LightList *glLights() const { return myGLLights; }
128  RE_LightList *glLights() { return myGLLights; }
129 
130  exint entries() const { return myList.entries(); }
131 
132  bool hasLight(int id) const
133  {
134  auto entry = myLightMap.find(id);
135  return (entry != myLightMap.end());
136  }
137 
138  // Fetch by light ID
139  GR_LightPtr getLight(int id) const
140  {
141  auto entry = myLightMap.find(id);
142  if(entry != myLightMap.end())
143  return myList(entry->second);
144  return GR_LightPtr();
145  }
146 
147  // Fetch by order in the light list (for masking)
148  GR_LightPtr getLightByIndex(int index) const { return myList(index); }
149 
150  void add(int id, GR_Light *new_light)
151  {
152  myLightMap.emplace(id, int(myList.entries()));
153  myList.append(new_light);
154  }
155  bool remove(int id)
156  {
157  auto entry = myLightMap.find(id);
158  if(entry != myLightMap.end())
159  {
160  int index = entry->second;
161  myLightMap.clear();
162  myList.removeIndex(index);
163  for(int i=0; i<myList.entries(); i++)
164  myLightMap[myList(i)->id()] = i;
165  return true;
166  }
167  return false;
168  }
169  void removeAllBut(const UT_Set<int> &active_lights);
170 
171 private:
172  RE_LightList *myGLLights = nullptr;
173  UT_Map<int,int> myLightMap;
174  UT_Array<GR_LightPtr> myList;
175 };
176 
177 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
void setLightID(exint id)
Definition: GR_Light.h:59
void setTransform(const UT_Matrix4D &t)
Definition: GR_Light.h:56
Base class for various things that can appear in a scene outside of geometry.
Definition: GR_SceneItem.h:19
bool mySetBound
Definition: GR_Light.h:101
void decref()
Definition: GR_SceneItem.h:33
int64 exint
Definition: SYS_Types.h:125
Opaque reference to a texture stored in the RV_TextureCache.
Definition: RV_Type.h:175
GR_LightPtr getLightByIndex(int index) const
Definition: GR_Light.h:148
bool hasLight(int id) const
Definition: GR_Light.h:132
UT_IntrusivePtr< GR_Light > GR_LightPtr
Definition: GR_Defines.h:386
UT_NON_COPYABLE(GR_SceneItem)
LightType type() const
Definition: GR_Light.h:48
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void add(int id, GR_Light *new_light)
Definition: GR_Light.h:150
void setID(int id)
Definition: GR_SceneItem.h:40
GR_LightPtr getLight(int id) const
Definition: GR_Light.h:139
bool myDirtyFlag
Definition: GR_Light.h:99
Base class for all light types.
Definition: GR_Light.h:36
bool myShadowDirtyFlag
Definition: GR_Light.h:100
#define GR_API
Definition: GR_API.h:10
Wrapper around hboost::intrusive_ptr.
GLuint id
Definition: glcorearb.h:655
bool isEnabled() const
Definition: GR_Light.h:53
GLuint const GLchar * name
Definition: glcorearb.h:786
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:36
GLdouble t
Definition: glad.h:2397
void setEnabled(bool e)
Definition: GR_Light.h:54
GLuint shader
Definition: glcorearb.h:785
void setGLLights(RE_LightList *list)
Definition: GR_Light.h:126
GLuint index
Definition: glcorearb.h:786
unsigned int uint32
Definition: SYS_Types.h:40
void setHeadlight(bool e)
Definition: GR_Light.h:51
exint entries() const
Definition: GR_Light.h:130
GLboolean r
Definition: glcorearb.h:1222
type
Definition: core.h:1059
bool isHeadlight() const
Definition: GR_Light.h:50
void incref()
Definition: GR_SceneItem.h:31
RE_LightList * glLights()
Definition: GR_Light.h:128
const UT_Matrix4D & transform() const
Definition: GR_Light.h:57
const RE_LightList * glLights() const
Definition: GR_Light.h:127