diff --git a/src/system/src/path.cpp b/src/system/src/path.cpp index 2e186c1..2d50105 100644 --- a/src/system/src/path.cpp +++ b/src/system/src/path.cpp @@ -56,18 +56,15 @@ std::string path::separator() std::string path::executable_path() { std::string result; - + const size_t MAXPATHLEN = 2048; + std::vector buf(MAXPATHLEN); #if defined(__APPLE__) - CFURLRef bundleURL; - CFStringRef pathStr; + CFBundleRef mainBundle = CFBundleGetMainBundle(); - - bundleURL = CFBundleCopyExecutableURL(mainBundle); - pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); - CFStringGetCString(pathStr, path, MAXPATHLEN, kCFStringEncodingASCII); - - result.assign(&path[0]); + CFURLRef bundleURL = CFBundleCopyExecutableURL(mainBundle); + CFStringRef pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); + CFStringGetCString(pathStr, buf.data(), buf.size(), kCFStringEncodingASCII); CFRelease(pathStr); CFRelease(bundleURL); @@ -77,11 +74,10 @@ std::string path::executable_path() DWORD ret = GetModuleFileName( NULL, &lpFname[0], MAXPATHLEN ); result.assign(&lpFname[0]); #elif defined(__USE_POSIX) - const size_t MAXPATHLEN = 2048; - std::vector buf(MAXPATHLEN); readlink("/proc/self/exe", buf.data(), buf.size()); - result.assign(buf.data()); #endif + result.assign(buf.data()); + return result; } diff --git a/src/visual/include/pw/visual/shader.hpp b/src/visual/include/pw/visual/shader.hpp index b1876ea..e522bc1 100644 --- a/src/visual/include/pw/visual/shader.hpp +++ b/src/visual/include/pw/visual/shader.hpp @@ -17,7 +17,7 @@ public: ~shader(); enum code_type { - vertex, //< + vertex, fragment, geometry, compute @@ -36,7 +36,8 @@ public: int uniform_location(std::string const & name) const; - template shader & bind(std::string const & name, T&& value) + template + shader & bind(std::string const & name, T&& value) { int location = uniform_location(name); if (location >= 0) diff --git a/src/visual/include/pw/visual/texture.hpp b/src/visual/include/pw/visual/texture.hpp index 2391b72..bad1efc 100644 --- a/src/visual/include/pw/visual/texture.hpp +++ b/src/visual/include/pw/visual/texture.hpp @@ -49,6 +49,8 @@ class texture { void set_wrap(wrap_mode w); wrap_mode wrap() const { return _wrap; } + void generate_mipmaps(); + protected: shared_ptr _image; diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index c7ec474..eb25bc4 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -14,6 +14,10 @@ namespace pw { class command { +}; + +class mesh_command : command { + // shader // vertexarray @@ -26,9 +30,9 @@ class queue { struct triangle_renderer { - GLuint vbo = 0; - GLuint vao = 0; - GLuint shader_programme = 0; +// GLuint vbo = 0; +// GLuint vao = 0; +// GLuint shader_programme = 0; shader shader_p; mesh amesh; @@ -42,11 +46,12 @@ struct triangle_renderer void setup() { mesh::vertex3array_t vertices = { - { 0.0f, 0.5f, 0.0f} - ,{ 0.5f, -0.5f, 0.0f} - ,{-0.5f, -0.5f, 0.0f} + { 0.0f, 0.5f, 0.0f} // 0 + ,{ 0.5f, -0.5f, 0.0f} // 1 + ,{-0.5f, -0.5f, 0.0f} // 2 }; + // actual indices mesh::indexarray_t indices = { 0, 1, 2}; amesh.set_indices(indices); @@ -109,6 +114,27 @@ struct triangle_renderer frag_colour = input_color; })"; + + + const char* vertex_shader_2 = R"( + #version 400 + in vec3 vertex_p; + in vec3 normal_p; + + void main() { + gl_Position = vec4(vp, 1.0); + } + )"; + + const char *fragment_shader_2 = R"( + #version 400 + uniform vec4 input_color = vec4(1.0, 0.0, 0.0, 1.0); + out vec4 frag_colour; + void main() { + frag_colour = input_color; + })"; + + shader_p.set_source(fragment_shader,shader::fragment); shader_p.set_source(vertex_shader,shader::vertex); diff --git a/src/visual/src/shader.cpp b/src/visual/src/shader.cpp index d412293..5419046 100644 --- a/src/visual/src/shader.cpp +++ b/src/visual/src/shader.cpp @@ -116,7 +116,6 @@ struct shader::impl debug::e() << info_log.get(); - /* Handle the error in an appropriate way such as displaying a message or writing to a log file. */ /* In this simple program, we'll just leave */ diff --git a/src/visual/src/texture.cpp b/src/visual/src/texture.cpp index c562559..2bad5f4 100644 --- a/src/visual/src/texture.cpp +++ b/src/visual/src/texture.cpp @@ -44,6 +44,9 @@ struct texture::impl { glSamplerParameteri(_texture_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); +// glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); +// glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glBindTexture(gl_shape(),0); } @@ -51,6 +54,11 @@ struct texture::impl { { } + + void generate_mipmaps() + { + glGenerateMipmap(gl_shape()); + } }; @@ -92,5 +100,10 @@ void texture::set_wrap(wrap_mode w) _wrap = w; } +void texture::generate_mipmaps() +{ + _impl->generate_mipmaps(); +} + } diff --git a/src/visual/src/vertex_array.cpp b/src/visual/src/vertex_array.cpp index 13cd436..f4befe0 100644 --- a/src/visual/src/vertex_array.cpp +++ b/src/visual/src/vertex_array.cpp @@ -30,6 +30,11 @@ struct vertex_array::impl { void create(const mesh& m) { + // not sure ... + if (ready()) { + destroy(); + } + glGenVertexArrays(1,&_vao); glBindVertexArray(_vao);