1 #pragma once 2 3 #include "OpenGLESDispatch/GLESv2Dispatch.h" 4 5 #include <map> 6 #include <string> 7 #include <vector> 8 9 #include <inttypes.h> 10 11 #include <GLES2/gl2.h> 12 13 namespace gfxstream { 14 namespace gl { 15 namespace snapshot { 16 17 struct GLValue { 18 std::vector<GLenum> enums; 19 std::vector<unsigned char> bytes; 20 std::vector<uint16_t> shorts; 21 std::vector<uint32_t> ints; 22 std::vector<float> floats; 23 std::vector<uint64_t> int64s; 24 }; 25 26 typedef std::map<GLenum, GLValue> GlobalStateMap; 27 typedef std::map<GLenum, bool> GlobalEnables; 28 29 struct GLShaderState { 30 GLenum type; 31 std::string source; 32 bool compileStatus; 33 }; 34 35 struct GLProgramState { 36 std::map<GLenum, GLuint> linkage; 37 bool linkStatus; 38 }; 39 40 class GLSnapshotState { 41 public: 42 GLSnapshotState(const GLESv2Dispatch* gl); 43 void save(); 44 void restore(); 45 46 // Shaders 47 GLuint createShader(GLuint shader, GLenum shaderType); 48 GLuint createProgram(GLuint program); 49 void shaderString(GLuint shader, const GLchar* string); 50 void genBuffers(GLsizei n, GLuint* buffers); 51 GLuint getProgramName(GLuint name); 52 53 private: 54 void getGlobalStateEnum(GLenum name, int size); 55 void getGlobalStateByte(GLenum name, int size); 56 void getGlobalStateInt(GLenum name, int size); 57 void getGlobalStateFloat(GLenum name, int size); 58 void getGlobalStateInt64(GLenum name, int size); 59 60 void getGlobalStateEnable(GLenum name); 61 62 const GLESv2Dispatch* mGL; 63 GlobalStateMap mGlobals; 64 GlobalEnables mEnables; 65 66 GLuint mProgramCounter = 1; 67 68 std::map<GLuint, GLuint> mProgramNames; 69 std::map<GLuint, GLuint> mProgramNamesBack; 70 std::map<GLuint, GLShaderState> mShaderState; 71 std::map<GLuint, GLProgramState> mShaderProgramState; 72 73 }; 74 75 } // namespace snapshot 76 } // namespace gl 77 } // namespace gfxstream