3030
3131#include " ScreenAlignedQuad.h"
3232
33+ // example commons
34+ #include " common/contextinfo.inl"
35+ #include " common/dataPath.inl"
36+
3337
3438using namespace gl ;
35- using namespace globjects ;
3639
3740
3841namespace
3942{
43+ globjects::Texture * g_texture = nullptr ;
44+ globjects::Program * g_computeProgram = nullptr ;
45+ ScreenAlignedQuad * g_quad = nullptr ;
4046
41- // taken from iozeug::FilePath::toPath
42- std::string normalizePath (const std::string & filepath)
43- {
44- auto copy = filepath;
45- std::replace ( copy.begin (), copy.end (), ' \\ ' , ' /' );
46- auto i = copy.find_last_of (' /' );
47- if (i == copy.size ()-1 )
48- {
49- copy = copy.substr (0 , copy.size ()-1 );
50- }
51- return copy;
52- }
53-
54-
55- Texture * g_texture = nullptr ;
56- Program * g_computeProgram = nullptr ;
57- ScreenAlignedQuad * g_quad = nullptr ;
58-
59- auto g_frame = 0u ;
60- auto g_size = glm::ivec2{ };
61-
47+ auto g_frame = 0u ;
48+ auto g_size = glm::ivec2{ };
6249}
6350
6451
6552void initialize ()
6653{
67- cpplocate::ModuleInfo moduleInfo = cpplocate::findModule (" globjects" );
68-
69- // Get data path
70- std::string dataPath = moduleInfo.value (" dataPath" );
71- dataPath = normalizePath (dataPath);
72- if (dataPath.size () > 0 ) dataPath = dataPath + " /" ;
73- else dataPath = " data/" ;
74-
75- // Initialize OpenGL objects
76- g_texture = Texture::createDefault (GL_TEXTURE_2D);
54+ g_texture = globjects::Texture::createDefault (GL_TEXTURE_2D);
7755 g_texture->image2D (0 , GL_R32F, 512 , 512 , 0 , GL_RED, GL_FLOAT, nullptr );
7856 g_texture->bindImageTexture (0 , 0 , GL_FALSE, 0 , GL_WRITE_ONLY, GL_R32F);
7957 g_texture->setParameter (GL_TEXTURE_MIN_FILTER, GL_NEAREST);
8058 g_texture->setParameter (GL_TEXTURE_MAG_FILTER, GL_NEAREST);
8159 g_texture->ref ();
8260
83- g_computeProgram = new Program ();
84- g_computeProgram->attach (Shader::fromFile (GL_COMPUTE_SHADER, dataPath + " computeshader/cstest.comp" ));
61+ g_computeProgram = new globjects::Program ();
62+
63+ const auto dataPath = common::retrieveDataPath (" globjects" , " dataPath" );
64+ g_computeProgram->attach (globjects::Shader::fromFile (GL_COMPUTE_SHADER, dataPath + " computeshader/cstest.comp" ));
8565 g_computeProgram->setUniform (" destTex" , 0 );
8666 g_computeProgram->ref ();
8767
@@ -121,7 +101,7 @@ void draw()
121101
122102void error (int errnum, const char * errmsg)
123103{
124- critical () << errnum << " : " << errmsg << std::endl;
104+ globjects:: critical () << errnum << " : " << errmsg << std::endl;
125105}
126106
127107void framebuffer_size_callback (GLFWwindow * /* window*/ , int width, int height)
@@ -135,33 +115,34 @@ void key_callback(GLFWwindow * window, int key, int /*scancode*/, int action, in
135115 glfwSetWindowShouldClose (window, 1 );
136116
137117 if (key == GLFW_KEY_F5 && action == GLFW_RELEASE)
138- File::reloadAll ();
118+ globjects:: File::reloadAll ();
139119}
140120
141121
142122int main ()
143123{
144124#ifdef SYSTEM_DARWIN
145- critical () << " mac OS does currently not support compute shader (OpenGL 4.3. required)."
125+ critical () << " macOS does currently not support compute shader (OpenGL 4.3. required)."
146126 return 0 ;
147127#endif
148128
129+ // Initialize GLFW
149130 if (!glfwInit ())
150131 return 1 ;
151132
152133 glfwSetErrorCallback (error);
153-
154134 glfwDefaultWindowHints ();
155135
156136 glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, true );
157137 glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4 );
158138 glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3 );
159139 glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
160140
141+ // Create a context and, if valid, make it current
161142 GLFWwindow * window = glfwCreateWindow (640 , 480 , " globjects Computer Shader" , nullptr , nullptr );
162143 if (!window)
163144 {
164- critical () << " Context creation failed. Terminate execution." ;
145+ globjects:: critical () << " Context creation failed. Terminate execution." ;
165146
166147 glfwTerminate ();
167148 return -1 ;
@@ -174,35 +155,32 @@ int main()
174155
175156 // Initialize globjects (internally initializes glbinding, and registers the current context)
176157 globjects::init ();
177- globjects::DebugMessage::enable ( true );
158+ common::printContextInfo ( );
178159
179- // print some gl infos (query)
160+ globjects::DebugMessage::enable ();
180161
181- info () << std::endl
182- << " OpenGL Version: " << glbinding::ContextInfo::version () << std::endl
183- << " OpenGL Vendor: " << glbinding::ContextInfo::vendor () << std::endl
184- << " OpenGL Renderer: " << glbinding::ContextInfo::renderer () << std::endl;
185162
186- if (!hasExtension (GLextension::GL_ARB_compute_shader))
163+ if (!globjects:: hasExtension (GLextension::GL_ARB_compute_shader))
187164 {
188- critical () << " Compute shader not supported. Terminate execution." ;
165+ globjects:: critical () << " Compute shader not supported. Terminate execution." ;
189166
190167 glfwTerminate ();
191168 return -1 ;
192169 }
193170
194- info () << " Press F5 to reload compute shader." << std::endl << std::endl;
171+ globjects::info () << " Press F5 to reload compute shader." << std::endl << std::endl;
172+
195173
196174 initialize ();
197175 glfwGetFramebufferSize (window, &g_size[0 ], &g_size[1 ]);
198176
177+ // Main loop
199178 while (!glfwWindowShouldClose (window))
200179 {
201180 glfwPollEvents ();
202181 draw ();
203182 glfwSwapBuffers (window);
204183 }
205-
206184 deinitialize ();
207185
208186 // Properly shutdown GLFW
0 commit comments