HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_ShaderRegistry.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: RE_ShaderRegistry.h (RE Library, C++)
7  *
8  * COMMENTS:
9  * RE_ShaderRegistry encapsulates a container for a family of shaders that
10  * can be classified using a number of tags encoded as a bit masks.
11  * In the registry, each shader is associated with the sets of tags that
12  * uniquely identify it and can be looked up using the same set of tags.
13  *
14  * It is essential that the tags are set up and assigned to shaders in a
15  * way that can ensure distinct masks for all registered shaders. When
16  * registering a shader, a warning is printed to stderr and the shader is
17  * dropped if its mask is already in use by another shader in the registry.
18  */
19 
20 
21 #ifndef RE_SHADERREGISTRY_H_
22 #define RE_SHADERREGISTRY_H_
23 
24 #include "RE_API.h"
25 #include <UT/UT_Map.h>
26 #include <iostream>
27 #include "RE_ShaderHandle.h"
28 
29 class re_TagNode;
30 
32 {
33 public:
35  myLastLookupShader(nullptr),
36  myLastLookupTags(0),
37  myLastLookupTagsValid(false)
38  {}
39 
41 
42  int registerShader(const char *program_files,
43  const char *defines,
44  exint tags);
45 
46  int registerShader(RE_ShaderHandle *sh, exint tags);
47  RE_ShaderHandle *lookupShader(exint tags) const;
48 
49  static void dumpShaderInfo(RE_ShaderHandle *sh, std::ostream &os);
50 
51  void setNameBit(const char *name, exint bit);
52 
53  void printTags(exint tags);
54 
55  bool generateProgramAtlas(const char *atlas_filename);
56  void generateProgramAtlas(std::ostream &os);
57 
58 private:
59  void printTagNode(std::ostream &os,
60  re_TagNode *node,
61  int indent, bool single);
62 
63  typedef UT_Map<exint, RE_ShaderHandle *> ShaderMapT;
64 
65  ShaderMapT myShaderMap;
67  mutable RE_ShaderHandle *myLastLookupShader;
68  mutable exint myLastLookupTags;
69  mutable bool myLastLookupTagsValid;
70  class re_TagInfo
71  {
72  public:
73  exint tag;
74  exint mask;
75  UT_StringHolder tagname;
76  };
77  UT_Array<re_TagInfo > myTags;
78 };
79 
80 #endif /* RE_SHADERREGISTRY_H_ */
#define RE_API
Definition: RE_API.h:10
int64 exint
Definition: SYS_Types.h:125
GLint GLuint mask
Definition: glcorearb.h:124
GLuint const GLchar * name
Definition: glcorearb.h:786
Simple interface to building a shader from a .prog file.