]> git.cworth.org Git - apitrace/blob - wrappers/gltrace.hpp
retrace: Implement glxCopySubBufferMESA
[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     // Whether it has been bound before
101     bool bound;
102
103     // TODO: This will fail for buffers shared by multiple contexts.
104     std::map <GLuint, Buffer> buffers;
105
106     Context(void) :
107         profile(PROFILE_COMPAT),
108         user_arrays(false),
109         user_arrays_arb(false),
110         user_arrays_nv(false),
111         retain_count(0),
112         bound(false)
113     { }
114
115     inline bool
116     needsShadowBuffers(void)
117     {
118         return profile == PROFILE_ES1 || profile == PROFILE_ES2;
119     }
120 };
121
122 void
123 createContext(uintptr_t context_id);
124
125 void
126 retainContext(uintptr_t context_id);
127
128 bool
129 releaseContext(uintptr_t context_id);
130
131 void
132 setContext(uintptr_t context_id);
133
134 void
135 clearContext(void);
136
137 gltrace::Context *
138 getContext(void);
139
140 const GLubyte *
141 _glGetString_override(GLenum name);
142
143 void
144 _glGetIntegerv_override(GLenum pname, GLint *params);
145
146 const GLubyte *
147 _glGetStringi_override(GLenum name, GLuint index);
148
149
150 } /* namespace gltrace */
151
152
153 #endif /* _GLRETRACE_HPP_ */