GteProgramFactory.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
13 #include <stack>
14 
15 namespace gte
16 {
17 
19 {
20 public:
21  // Abstract base class.
22  virtual ~ProgramFactory();
24 
25  // All members are in public scope, because there are no side effects
26  // when the values are modified. The current values are used in the
27  // the Create(...) functions.
29  std::string vsEntry, psEntry, gsEntry, csEntry;
31  unsigned int flags;
32 
33  // The returned value is used as a lookup index into arrays of strings
34  // corresponding to shader programs. Currently, GLSLProgramFactory
35  // returns PF_GLSL and HLSLProgramFactory returns PF_HLSL.
36  enum
37  {
40  PF_NUM_API
41  };
42 
43  virtual int GetAPI() const = 0;
44 
45  // Create a program for GPU display. The files are loaded, converted to
46  // strings, and passed to CreateFromNamedSources. The filenames are
47  // passed as the 'xsName' parameters in case the shader compiler needs
48  // this for #include path searches.
49  std::shared_ptr<VisualProgram> CreateFromFiles(std::string const& vsFile,
50  std::string const& psFile, std::string const& gsFile);
51 
52  std::shared_ptr<VisualProgram> CreateFromSources(
53  std::string const& vsSource, std::string const& psSource,
54  std::string const& gsSource);
55 
56  // Create a program for GPU computing. The file is loaded, converted to
57  // a string, and passed to CreateFromNamedSource. The filename is passed
58  // the 'csName' parameters in case the shader compiler needs this for
59  // #include path searches.
60  std::shared_ptr<ComputeProgram> CreateFromFile(
61  std::string const& csFile);
62 
63  std::shared_ptr<ComputeProgram> CreateFromSource(
64  std::string const& csSource);
65 
66  // In public scope in case an effect needs a source-code string from
67  // a file; for example, OverlayEffect can use this.
68  static std::string GetStringFromFile(std::string const& filename);
69 
70  // Support for passing ProgramFactory objects to a function that
71  // potentially modifies 'defines' or 'flags' but then needs to resstore
72  // the previous state on return. The PushDefines() function saves the
73  // current 'defines' on a stack and then clears 'defines'. The
74  // PushFlags() function saves the current 'flags' on a stack and then
75  // sets 'flags' to zero. If you need to modify subelements of either
76  // member, you will have to manage that on your own.
77  void PushDefines();
78  void PopDefines();
79  void PushFlags();
80  void PopFlags();
81 
82 protected:
83  virtual std::shared_ptr<VisualProgram> CreateFromNamedSources(
84  std::string const& vsName, std::string const& vsSource,
85  std::string const& psName, std::string const& psSource,
86  std::string const& gsName, std::string const& gsSource) = 0;
87 
88  virtual std::shared_ptr<ComputeProgram> CreateFromNamedSource(
89  std::string const& csName, std::string const& csSource) = 0;
90 
91 private:
92  std::stack<ProgramDefines> mDefinesStack;
93  std::stack<unsigned int> mFlagsStack;
94 
95  // Prevent assignment.
96  ProgramFactory& operator=(ProgramFactory const&) { return *this; }
97 };
98 
99 }
ProgramFactory & operator=(ProgramFactory const &)
ProgramDefines defines
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
std::stack< unsigned int > mFlagsStack
std::stack< ProgramDefines > mDefinesStack
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01