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 <RE/RE_RenderContext.h>
20 #include <UT/UT_Array.h>
21 #include <UT/UT_BoundingBox.h>
22 #include <UT/UT_Map.h>
23 #include <UT/UT_Matrix4.h>
24 #include <UT/UT_Set.h>
25 #include <UT/UT_StringHolder.h>
26 #include <UT/UT_UniquePtr.h>
27 #include <UT/UT_Matrix4.h>
28 
29 class RE_LightList;
30 class RV_Instance;
31 class RV_Render;
32 class RV_ShaderBlock;
33 class RV_ShaderProgram;
36 class RV_VKImage;
38 
39 /// Base class for all light types
41 {
42 public:
43  enum LightType
44  {
49  AREA
50  };
51 
52  LightType type() const { return myType; }
53 
54  bool isHeadlight() const { return myIsHeadlight; }
55  void setHeadlight(bool e) { myIsHeadlight = e; }
56 
57  bool isEnabled() const { return myIsEnabled; }
58  void setEnabled(bool e) { myIsEnabled = e; }
59 
60  void setLightID(exint id) { setID(id); }
61 
62  bool initSceneSetForRender(
63  RV_Render *r,
65  UT_UniquePtr<RV_ShaderBlock> &scene_block,
67  bool initLightSetForRender(RV_Render *r,
69  bool bindSets(RV_Render *r, RV_ShaderProgramBase *shader);
70  virtual bool initBlocks(RV_Render *r, const GR_CommonDispOption &opts) = 0;
71 
72  // returns number of required shadow render passes (see DM_RenderVulkan.C)
73  virtual unsigned setupShadowRenders(RE_RenderContext,
74  GR_RenderMode &out_render_mode,
75  bool scene_changed,
76  unsigned shadowmap_size,
77  const GR_DistantShadowMapParms&) = 0;
78  virtual RV_ShaderProgram *getShader(bool shadows, bool per_sample,
79  bool is_antialiased) = 0;
80  static RV_ShaderProgram *getAmbientOcclusionShader();
81  // Returns true if the shadowmap render was started, false otherwise.
82  // Eg. returns false when the shadowmap is already up-to-date.
84  unsigned shadowmap_index) {}
87  virtual bool hasShadowMap() = 0;
89 
90  static bool initShaders(RV_Instance *inst);
91  static void cleanupShaders();
92 
93 protected:
94  GR_Light(const UT_StringHolder &name, LightType type);
95  ~GR_Light() override;
96 
98 
99  bool privInitBlocks(RV_Render *r,
100  void *light_block, int light_size,
101  void *shadow_block, int shadow_size);
102  void privBindTexture(RV_Render *r, const UT_StringHolder &map_name,
103  int rel_op_id, RV_TextureRef &map_id,
104  const UT_StringHolder &sampler_name,
105  const GR_CommonDispOption &opts,
106  RV_TextureParms *tex_parms = nullptr,
107  bool is_cube = false);
108  void initTexParms(RV_Render *r, const GR_CommonDispOption &opts,
109  RV_TextureParms &parms) const;
110 
111  static RV_ShaderProgram *privGetShader(exint tags);
112 
113 #ifdef USE_VULKAN
115  UT_UniquePtr<RV_ShaderBlock> myLightBlock;
116  UT_UniquePtr<RV_ShaderBlock> myShadowBlock;
117 #endif
121 
122  enum
123  {
124  GLOBAL_SET = 0,
125  LIGHT_SET = 1
126  };
127 
128 private:
129  LightType myType;
130  uint32
131  myIsHeadlight :1,
132  myIsEnabled :1;
133 };
134 
135 static inline void intrusive_ptr_add_ref(GR_Light *gl) { gl->incref(); }
136 static inline void intrusive_ptr_release(GR_Light *gl) { gl->decref(); }
137 
138 // List of lights currently contributing to the scene
140 {
141 public:
142  uint32 getLightMask(const UT_Set<int> &active) const;
143 
144  void setGLLights(RE_LightList *list) { myGLLights = list; }
145  const RE_LightList *glLights() const { return myGLLights; }
146  RE_LightList *glLights() { return myGLLights; }
147 
148  exint entries() const { return myList.entries(); }
149 
150  bool hasLight(int id) const
151  {
152  auto entry = myLightMap.find(id);
153  return (entry != myLightMap.end());
154  }
155 
156  // Fetch by light ID
157  GR_LightPtr getLight(int id) const
158  {
159  auto entry = myLightMap.find(id);
160  if(entry != myLightMap.end())
161  return myList(entry->second);
162  return GR_LightPtr();
163  }
164 
165  // Fetch by order in the light list (for masking)
166  GR_LightPtr getLightByIndex(int index) const { return myList(index); }
167 
168  void add(int id, GR_Light *new_light)
169  {
170  myLightMap[id] = int(myList.entries());
171  myList.append(new_light);
172  }
173  bool remove(int id)
174  {
175  auto entry = myLightMap.find(id);
176  if(entry != myLightMap.end())
177  {
178  int index = entry->second;
179  myLightMap.clear();
180  myList.removeIndex(index);
181  for(int i=0; i<myList.entries(); i++)
182  myLightMap[myList(i)->id()] = i;
183  return true;
184  }
185  return false;
186  }
187  void removeAll();
188  void removeAllBut(const UT_Set<int> &active_lights);
189 
190 private:
191  RE_LightList *myGLLights = nullptr;
192  UT_Map<int,int> myLightMap;
193  UT_Array<GR_LightPtr> myList;
194 };
195 
196 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
void setLightID(exint id)
Definition: GR_Light.h:60
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
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:120
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:176
GR_LightPtr getLightByIndex(int index) const
Definition: GR_Light.h:166
bool hasLight(int id) const
Definition: GR_Light.h:150
UT_IntrusivePtr< GR_Light > GR_LightPtr
Definition: GR_Defines.h:399
UT_NON_COPYABLE(GR_SceneItem)
Temporary container for either a RV_Render and an RE_Render.
LightType type() const
Definition: GR_Light.h:52
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:168
virtual void startShadowRender(RE_RenderContext rc, unsigned shadowmap_index)
Definition: GR_Light.h:83
void setID(int id)
Definition: GR_SceneItem.h:40
GR_LightPtr getLight(int id) const
Definition: GR_Light.h:157
GR_RenderMode
Definition: GR_Defines.h:48
bool myDirtyFlag
Definition: GR_Light.h:118
Base class for all light types.
Definition: GR_Light.h:40
bool myShadowDirtyFlag
Definition: GR_Light.h:119
#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:57
GLuint const GLchar * name
Definition: glcorearb.h:786
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:38
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
void setEnabled(bool e)
Definition: GR_Light.h:58
virtual void attachShadowMap(RE_RenderContext)
Definition: GR_Light.h:88
GLuint shader
Definition: glcorearb.h:785
virtual void finishShadowRenders(RE_RenderContext)
Definition: GR_Light.h:86
void setGLLights(RE_LightList *list)
Definition: GR_Light.h:144
GLuint index
Definition: glcorearb.h:786
unsigned int uint32
Definition: SYS_Types.h:40
void setHeadlight(bool e)
Definition: GR_Light.h:55
exint entries() const
Definition: GR_Light.h:148
GLboolean r
Definition: glcorearb.h:1222
virtual void finishShadowRender(RE_RenderContext)
Definition: GR_Light.h:85
type
Definition: core.h:1059
bool isHeadlight() const
Definition: GR_Light.h:54
void incref()
Definition: GR_SceneItem.h:31
RE_LightList * glLights()
Definition: GR_Light.h:146
const RE_LightList * glLights() const
Definition: GR_Light.h:145