Overte C++ Documentation
GLState.h
1 //
2 // Created by Bradley Austin Davis on 2016/05/15
3 // Copyright 2013-2016 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #ifndef hifi_gpu_gl_GLState_h
9 #define hifi_gpu_gl_GLState_h
10 
11 #include "GLShared.h"
12 
13 #include <gpu/State.h>
14 
15 namespace gpu { namespace gl {
16 
17 class GLBackend;
18 class GLState : public GPUObject {
19 public:
20  static GLState* sync(const State& state);
21 
22  class Command {
23  public:
24  virtual void run(GLBackend* backend) = 0;
25  Command() {}
26  virtual ~Command() {};
27  };
28 
29  template <class T> class Command1 : public Command {
30  public:
31  typedef void (GLBackend::*GLFunction)(T);
32  void run(GLBackend* backend) { (backend->*(_func))(_param); }
33  Command1(GLFunction func, T param) : _func(func), _param(param) {};
34  GLFunction _func;
35  T _param;
36  };
37  template <class T, class U> class Command2 : public Command {
38  public:
39  typedef void (GLBackend::*GLFunction)(T, U);
40  void run(GLBackend* backend) { (backend->*(_func))(_param0, _param1); }
41  Command2(GLFunction func, T param0, U param1) : _func(func), _param0(param0), _param1(param1) {};
42  GLFunction _func;
43  T _param0;
44  U _param1;
45  };
46 
47  template <class T, class U, class V> class Command3 : public Command {
48  public:
49  typedef void (GLBackend::*GLFunction)(T, U, V);
50  void run(GLBackend* backend) { (backend->*(_func))(_param0, _param1, _param2); }
51  Command3(GLFunction func, T param0, U param1, V param2) : _func(func), _param0(param0), _param1(param1), _param2(param2) {};
52  GLFunction _func;
53  T _param0;
54  U _param1;
55  V _param2;
56  };
57 
58  typedef std::shared_ptr< Command > CommandPointer;
59  typedef std::vector< CommandPointer > Commands;
60 
61  Commands _commands;
62  Stamp _stamp;
63  State::Signature _signature;
64 
65  // The state commands to reset to default,
66  static const Commands _resetStateCommands;
67 
68  friend class GLBackend;
69 };
70 
71 } }
72 
73 #endif