GCC Code Coverage Report


Directory: src/gate/
File: src/gate/graphics/tests/gategraphics_cpp_opengl_test/gategraphics_cpp_opengl_test.cpp
Date: 2026-08-06 22:46:24
Exec Total Coverage
Lines: 67 85 78.8%
Functions: 7 15 46.7%
Branches: 25 44 56.8%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/applications.h"
30
31 #include "gate/gatemain.h"
32 #include "gate/results.h"
33
34 #include "gate/applications.hpp"
35 #include "gate/results.hpp"
36 #include "gate/exceptions.hpp"
37 #include "gate/wrappers.hpp"
38 #include "gate/graphics/gl_apis.hpp"
39
40
41 #if defined(GATE_COMPILER_MSVC) && defined(GATE_LEAK_DETECTION) && defined(GATE_SYS_WIN) && !defined(GATE_SYS_WINCE) && (GATE_ARCH != GATE_ARCH_ARM32) && (GATE_ARCH != GATE_ARCH_ARM64)
42 # include <vld.h>
43 #endif
44
45 static gate_bool_t run_app_tests = false;
46
47 namespace gate
48 {
49 namespace apps
50 {
51
52 class GATE_API_LOCAL GateGraphicsOpenGlTest : public App, protected graph::GlSurfaceEventSink
53 {
54 public:
55 GateGraphicsOpenGlTest();
56 virtual ~GateGraphicsOpenGlTest() noexcept;
57
58 protected:
59 virtual void onRender(graph::GlSurface& surface) override;
60 virtual void onExit(graph::GlSurface& surface) override;
61 virtual void onResize(graph::GlSurface& surface, uint32_t width, uint32_t height) override;
62
63 virtual void onKeyDown(graph::GlSurface& surface, Keyboard::code_t keyCode, Keyboard::states_t keyStates) override;
64 virtual void onKeyUp(graph::GlSurface& surface, Keyboard::code_t keyCode, Keyboard::states_t keyStates) override;
65 virtual void onPointerDown(graph::GlSurface& surface, uint32_t pointerType, real32_t x, real32_t y) override;
66 virtual void onPointerMove(graph::GlSurface& surface, uint32_t pointerType, real32_t x, real32_t y) override;
67 virtual void onPointerUp(graph::GlSurface& surface, uint32_t pointerType, real32_t x, real32_t y) override;
68 virtual void onScroll(graph::GlSurface& surface, int32_t xDirection, int32_t yDirection) override;
69
70 private:
71 virtual void run() override;
72 virtual void onSignal(int appsignal) override;
73 virtual void onInit() override;
74
75 graph::GlSurface surface;
76
77 bool_t exitFlag;
78 bool_t resetFlag;
79 real32_t rotationAngle;
80 size_t loopCounter;
81 };
82
83
84 1 GateGraphicsOpenGlTest::GateGraphicsOpenGlTest()
85 : exitFlag(false),
86 resetFlag(true),
87 rotationAngle(0.0f),
88
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 loopCounter(0)
89 {
90 1 }
91 2 GateGraphicsOpenGlTest::~GateGraphicsOpenGlTest() noexcept
92 {
93 2 }
94
95 void GateGraphicsOpenGlTest::onSignal(int appsignal)
96 {
97
98 }
99 1 void GateGraphicsOpenGlTest::onInit()
100 {
101 1 this->resetFlag = true;
102 1 this->exitFlag = false;
103 1 this->surface.openScreen();
104 1 }
105 1 void GateGraphicsOpenGlTest::run()
106 {
107 1 this->surface.runEventLoop(*this);
108 1 this->surface.close();
109 1 }
110 1 void GateGraphicsOpenGlTest::onResize(graph::GlSurface& surface, uint32_t width, uint32_t height)
111 {
112 1 surface.resize(width, height);
113 1 this->resetFlag = true;
114 1 }
115 21 void GateGraphicsOpenGlTest::onRender(graph::GlSurface& surface)
116 {
117 21 graph::GlApi& gl = surface.getGlApi();
118 21 ++this->loopCounter;
119
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if (run_app_tests)
120 {
121
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (this->loopCounter > 20)
122 {
123 1 this->exitFlag = true;
124 }
125 }
126
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (this->exitFlag)
127 {
128 #if !defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
129 1 gl.disableClientState(graph::GlApi::ClientState_VertexArray);
130 1 gl.disableClientState(graph::GlApi::ClientState_ColorArray);
131 #endif
132 1 gl.disableCapability(graph::GlApi::Capability_DepthTest);
133 1 this->surface.exitEventLoop();
134 1 return;
135 }
136
137
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19 times.
20 if (this->resetFlag)
138 {
139 // render setup
140 1 uint32_t width = 0, height = 0;
141
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 surface.getSize(width, height);
142
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.setViewport(0, 0, width, height);
143
144 #if !defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
145
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.enableCapability(graph::GlApi::Capability_DepthTest);
146
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.setCullFace(graph::GlApi::CullFace_Front);
147
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.setShadeModel(graph::GlApi::ShadeModel_Flat);
148
149 1 real32_t aspect = static_cast<real32_t>(width) / static_cast<real32_t>(height);
150
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.setMatrixMode(graph::GlApi::MatrixMode_Projection);
151
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.loadIdentity();
152
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.setPerspective(60.f, aspect, 0.1f, 100.0f);
153
154
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.setMatrixMode(graph::GlApi::MatrixMode_ModelView);
155
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gl.loadIdentity();
156 #endif
157
158 1 this->resetFlag = false;
159 }
160
161 // data upload
162 static const float cubeVertices[] = {
163 // Front face (Z+)
164 -1,-1, 1, 1,-1, 1, 1, 1, 1, -1, 1, 1,
165 // Back face (Z-)
166 -1,-1,-1, -1, 1,-1, 1, 1,-1, 1,-1,-1,
167 // Left face
168 -1,-1,-1, -1,-1, 1, -1, 1, 1, -1, 1,-1,
169 // Right face
170 1,-1,-1, 1, 1,-1, 1, 1, 1, 1,-1, 1,
171 // Top face
172 -1, 1,-1, -1, 1, 1, 1, 1, 1, 1, 1,-1,
173 // Bottom face
174 -1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1
175 };
176 static const float cubeColors[] = {
177 // Front
178 1,0,0, 1,0,0, 1,0,0, 1,0,0,
179 // Back
180 0,1,0, 0,1,0, 0,1,0, 0,1,0,
181 // Left
182 0,0,1, 0,0,1, 0,0,1, 0,0,1,
183 // Right
184 1,1,0, 1,1,0, 1,1,0, 1,1,0,
185 // Top
186 1,0,1, 1,0,1, 1,0,1, 1,0,1,
187 // Bottom
188 0,1,1, 0,1,1, 0,1,1, 0,1,1
189 };
190
191 #if !defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
192 20 gl.enableClientState(graph::GlApi::ClientState_VertexArray);
193 20 gl.enableClientState(graph::GlApi::ClientState_ColorArray);
194 20 gl.setVertexPointer(3, 0, cubeVertices);
195 20 gl.setColorPointer(3, 0, cubeColors);
196
197 // render output
198 20 gl.setClearColor(0.2f, 0.2f, 0.2f, 1.0f);
199 20 gl.setClearDepth(1.0f);
200 20 gl.clear(graph::GlApi::ClearBit_ColorBuffer | graph::GlApi::ClearBit_DepthBuffer);
201
202 20 gl.loadIdentity();
203 20 gl.translate(0.0f, 0.0f, -5.0f);
204
205 20 gl.rotate(this->rotationAngle, 1.0f, 1.0f, 0.0f);
206
207 // Draw 6 faces, each face has 4 vertices → GL_QUADS
208 20 gl.drawArrays(graph::GlApi::DrawMode_Quads, 0, 24);
209
210 20 gl.flush();
211 20 gl.finish();
212 #endif
213 20 surface.swapBuffers();
214
215 20 this->rotationAngle += 1.0f;
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 while (this->rotationAngle >= 360.0f)
217 {
218 this->rotationAngle -= 360.0f;
219 }
220 }
221 void GateGraphicsOpenGlTest::onExit(graph::GlSurface& surface)
222 {
223 this->exitFlag = true;
224 }
225 void GateGraphicsOpenGlTest::onKeyDown(graph::GlSurface& surface, Keyboard::code_t keyCode, Keyboard::states_t keyStates)
226 {
227 }
228 void GateGraphicsOpenGlTest::onKeyUp(graph::GlSurface& surface, Keyboard::code_t keyCode, Keyboard::states_t keyStates)
229 {
230 }
231 void GateGraphicsOpenGlTest::onPointerDown(graph::GlSurface& surface, uint32_t pointerType, real32_t x, real32_t y)
232 {
233 }
234 void GateGraphicsOpenGlTest::onPointerMove(graph::GlSurface& surface, uint32_t pointerType, real32_t x, real32_t y)
235 {
236 }
237 void GateGraphicsOpenGlTest::onPointerUp(graph::GlSurface& surface, uint32_t pointerType, real32_t x, real32_t y)
238 {
239 }
240 void GateGraphicsOpenGlTest::onScroll(graph::GlSurface& surface, int32_t xDirection, int32_t yDirection)
241 {
242 }
243
244 } // end of namespace apps
245 } // end of namespace gate
246
247 1 int gate_main(char const* program, char const* const* arguments, gate_size_t argcount, gate_uintptr_t apphandle)
248 {
249
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate::apps::GateGraphicsOpenGlTest app;
250
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (argcount > 0)
251 {
252
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 if (0 == gate_str_comp_ic(arguments[0], "--runtests"))
253 {
254 1 run_app_tests = true;
255 }
256 }
257
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 int ret = gate::App::runApp(app, program, arguments, argcount, apphandle);
258 2 return ret;
259 }
260