]> git.cworth.org Git - apitrace/blob - retrace/glretrace_main.cpp
Cleanup glretrace<->glws integration.
[apitrace] / retrace / glretrace_main.cpp
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
27 #include <string.h>
28
29 #include "retrace.hpp"
30 #include "glproc.hpp"
31 #include "glstate.hpp"
32 #include "glretrace.hpp"
33
34
35 namespace glretrace {
36
37 bool insideGlBeginEnd = false;
38
39
40 void
41 checkGlError(trace::Call &call) {
42     GLenum error = glGetError();
43     if (error == GL_NO_ERROR) {
44         return;
45     }
46
47     std::ostream & os = retrace::warning(call);
48
49     os << "glGetError(";
50     os << call.name();
51     os << ") = ";
52
53     switch (error) {
54     case GL_INVALID_ENUM:
55         os << "GL_INVALID_ENUM";
56         break;
57     case GL_INVALID_VALUE:
58         os << "GL_INVALID_VALUE";
59         break;
60     case GL_INVALID_OPERATION:
61         os << "GL_INVALID_OPERATION";
62         break;
63     case GL_STACK_OVERFLOW:
64         os << "GL_STACK_OVERFLOW";
65         break;
66     case GL_STACK_UNDERFLOW:
67         os << "GL_STACK_UNDERFLOW";
68         break;
69     case GL_OUT_OF_MEMORY:
70         os << "GL_OUT_OF_MEMORY";
71         break;
72     case GL_INVALID_FRAMEBUFFER_OPERATION:
73         os << "GL_INVALID_FRAMEBUFFER_OPERATION";
74         break;
75     case GL_TABLE_TOO_LARGE:
76         os << "GL_TABLE_TOO_LARGE";
77         break;
78     default:
79         os << error;
80         break;
81     }
82     os << "\n";
83 }
84
85
86 void frame_complete(trace::Call &call) {
87     retrace::frameComplete(call);
88
89     if (!currentDrawable) {
90         return;
91     }
92
93     if (!currentDrawable->visible) {
94         retrace::warning(call) << "could not infer drawable size (glViewport never called)\n";
95     }
96 }
97
98
99 } /* namespace glretrace */
100
101
102 void
103 retrace::setUp(void) {
104     glws::init();
105 }
106
107
108 void
109 retrace::addCallbacks(retrace::Retracer &retracer)
110 {
111     retracer.addCallbacks(glretrace::gl_callbacks);
112     retracer.addCallbacks(glretrace::glx_callbacks);
113     retracer.addCallbacks(glretrace::wgl_callbacks);
114     retracer.addCallbacks(glretrace::cgl_callbacks);
115     retracer.addCallbacks(glretrace::egl_callbacks);
116 }
117
118
119 image::Image *
120 retrace::getSnapshot(void) {
121     if (!glretrace::currentDrawable) {
122         return NULL;
123     }
124
125     return glstate::getDrawBufferImage();
126 }
127
128
129 bool
130 retrace::dumpState(std::ostream &os)
131 {
132     if (glretrace::insideGlBeginEnd ||
133         !glretrace::currentDrawable ||
134         !glretrace::currentContext) {
135         return false;
136     }
137
138     glstate::dumpCurrentContext(os);
139
140     return true;
141 }
142
143 void
144 retrace::flushRendering(void) {
145     glFlush();
146 }
147
148 void
149 retrace::waitForInput(void) {
150     while (glws::processEvents()) {
151     }
152 }
153
154 void
155 retrace::cleanUp(void) {
156     glws::cleanup();
157 }