File: ShaderPreprocessor.h

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (64 lines) | stat: -rw-r--r-- 1,699 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#include <map>
#include <string>
#include <string_view>
#include <unordered_map>

struct PyMOLGlobals;

class ShaderPreprocessor
{
public:
  ShaderPreprocessor(PyMOLGlobals* G,
      std::map<std::string, const char*>* rawShaderCache = nullptr);

  /**
   * Set a preprocessor variable
   * @param key The preprocessor variable name
   * @param value preprocessor value
   */
  void setVar(std::string_view key, bool value);

  /**
   * Gets a preprocessor variable
   * @param key The preprocessor variable name
   * @return preprocessor value
   */
  bool& getVar(std::string_view key);

  /**
   * Get the preprocessed shader source
   * @param filename The shader filename
   * @return The preprocessed shader source
   * @note There must be a single whitespace character between the directive and
   * argument.
   */
  std::string getSource(std::string_view filename);

  /**
   * Sets the preprocessed shader source
   * @param filename The shader filename
   * @param source The preprocessed shader source
   * @note - get() will automatically perform preprocessing. This method
   * is only needed if you want to set the preprocessed shader source
   */
  void setSource(std::string_view filename, std::string_view source);

  /**
   * Invalidate the preprocessed shader source for a given filename
   * @param filename The shader filename
   */
  void invalidate(std::string_view filename);

  /**
   * Deletes the preprocessed shader source cache
   */
  void clear();

private:
  PyMOLGlobals* m_G;
  std::map<std::string, const char*>* m_rawShaderCache{};
  std::unordered_map<std::string, bool> m_vars;
  std::unordered_map<std::string, std::string> m_cache_processed;
};