comparison dmrender.h @ 62:baccf2044289

Move the OpenGL rendering, setup etc. into a separate module/class, perhaps facilitating other types of renderers in future .. maybe.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 14 Dec 2019 16:39:20 +0200
parents
children d6ffc59bb84d
comparison
equal deleted inserted replaced
61:7b138613e2fc 62:baccf2044289
1 //
2 // GLDragon - OpenGL PLY model viewer / simple benchmark
3 // -- Basic renderer template
4 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
5 // (C) Copyright 2019 Tecnic Software productions (TNSP)
6 //
7 // See file "COPYING" for license information.
8 //
9 #ifndef DMRENDER_H
10 #define DMRENDER_H 1
11
12 #include "dmscene.h"
13 #include <SDL.h>
14
15
16 struct DMSimpleRenderer
17 {
18 bool useShaders;
19
20 DMSimpleRenderer()
21 {
22 useShaders = false;
23 }
24
25 virtual bool checkErrors(void)
26 {
27 return true;
28 }
29
30 virtual bool initRender1(void)
31 {
32 return false;
33 }
34
35 virtual bool initRender2(SDL_Window *window)
36 {
37 (void) window;
38 return false;
39 }
40
41 virtual bool initRender3(const int width, const int height)
42 {
43 (void) width;
44 (void) height;
45
46 return false;
47 }
48
49 virtual void shutdownRenderer(void)
50 {
51 }
52
53 virtual void drawModel(const DMSimpleScene &scene, const DMModel &model, const float time)
54 {
55 (void) scene;
56 (void) model;
57 (void) time;
58 }
59
60 virtual void drawScene(const DMSimpleScene &scene, const float time)
61 {
62 (void) scene;
63 (void) time;
64 }
65
66 virtual bool compileModelShaders(DMModel &model)
67 {
68 (void) model;
69 return false;
70 }
71
72 virtual bool compileSceneShaders(DMSimpleScene &scene)
73 {
74 if (useShaders)
75 {
76 for (DMModel &model : scene.models)
77 {
78 if (!compileModelShaders(model))
79 return false;
80 }
81 }
82 return true;
83 }
84
85 virtual bool setupLight(const int n, DMLight &light)
86 {
87 (void) n;
88 (void) light;
89 return true;
90 }
91
92 virtual bool setupLights(DMSimpleScene &scene)
93 {
94 for (size_t n = 0; n < scene.lights.size(); n++)
95 {
96 if (!setupLight(n, scene.lights[n]))
97 return false;
98 }
99 return true;
100 }
101
102 virtual bool setupCamera(DMCamera &camera)
103 {
104 (void) camera;
105 return true;
106 }
107
108 virtual bool animate(DMSimpleScene &scene, const float time)
109 {
110 (void) scene;
111 (void) time;
112 return true;
113 }
114 };
115
116 #endif