]> git.cworth.org Git - apitrace/blob - wrappers/gltrace.hpp
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / wrappers / gltrace.hpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifndef _GLTRACE_HPP_
27 #define _GLTRACE_HPP_
28
29
30 #include <string.h>
31 #include <stdlib.h>
32 #include <map>
33
34 #include "glimports.hpp"
35
36
37 namespace gltrace {
38
39
40 enum Profile {
41     PROFILE_COMPAT,
42     PROFILE_ES1,
43     PROFILE_ES2,
44 };
45
46
47 /**
48  * OpenGL ES buffers cannot be read. This class is used to track index buffer
49  * contents.
50  */
51 class Buffer {
52 public:
53     GLsizeiptr size;
54     GLvoid *data;
55
56     Buffer() :
57         size(0),
58         data(0)
59     {}
60
61     ~Buffer() {
62         free(data);
63     }
64
65     void
66     bufferData(GLsizeiptr new_size, const void *new_data) {
67         if (new_size < 0) {
68             new_size = 0;
69         }
70         size = new_size;
71         data = realloc(data, new_size);
72         if (new_size && new_data) {
73             memcpy(data, new_data, size);
74         }
75     }
76
77     void
78     bufferSubData(GLsizeiptr offset, GLsizeiptr length, const void *new_data) {
79         if (offset >= 0 && offset < size && length > 0 && offset + length <= size && new_data) {
80             memcpy((GLubyte *)data + offset, new_data, length);
81         }
82     }
83
84     void
85     getSubData(GLsizeiptr offset, GLsizeiptr length, void *out_data) {
86         if (offset >= 0 && offset < size && length > 0 && offset + length <= size && out_data) {
87             memcpy(out_data, (GLubyte *)data + offset, length);
88         }
89     }
90 };
91
92 class Context {
93 public:
94     enum Profile profile;
95     bool user_arrays;
96     bool user_arrays_arb;
97     bool user_arrays_nv;
98     unsigned retain_count;
99
100     // TODO: This will fail for buffers shared by multiple contexts.
101     std::map <GLuint, Buffer> buffers;
102
103     Context(void) :
104         profile(PROFILE_COMPAT),
105         user_arrays(false),
106         user_arrays_arb(false),
107         user_arrays_nv(false),
108         retain_count(0)
109     { }
110
111     inline bool
112     needsShadowBuffers(void)
113     {
114         return profile == PROFILE_ES1 || profile == PROFILE_ES2;
115     }
116 };
117
118 void
119 createContext(uintptr_t context_id);
120
121 void
122 retainContext(uintptr_t context_id);
123
124 bool
125 releaseContext(uintptr_t context_id);
126
127 void
128 setContext(uintptr_t context_id);
129
130 void
131 clearContext(void);
132
133 gltrace::Context *
134 getContext(void);
135
136 const GLubyte *
137 _glGetString_override(GLenum name);
138
139 void
140 _glGetIntegerv_override(GLenum pname, GLint *params);
141
142 const GLubyte *
143 _glGetStringi_override(GLenum name, GLuint index);
144
145
146 } /* namespace gltrace */
147
148
149 #endif /* _GLRETRACE_HPP_ */