diff --git a/CMakeLists.txt b/CMakeLists.txt index 574083bc..0388328a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,8 @@ set(CPP_FILES ${CMAKE_SOURCE_DIR}/src/Types.cpp ${CMAKE_SOURCE_DIR}/src/pystring.cpp ${CMAKE_SOURCE_DIR}/src/NGLMessage.cpp + ${CMAKE_SOURCE_DIR}/src/BufferTextures.cpp + ) set(HEADERS @@ -145,6 +147,7 @@ set(HEADERS ${CMAKE_SOURCE_DIR}/include/ngl/Shader.h ${CMAKE_SOURCE_DIR}/include/ngl/ShaderProgram.h ${CMAKE_SOURCE_DIR}/include/ngl/ShaderProgram.inl + ${CMAKE_SOURCE_DIR}/include/ngl/BufferTextures.h ${CMAKE_SOURCE_DIR}/include/ngl/Plane.h ${CMAKE_SOURCE_DIR}/include/ngl/AABB.h ${CMAKE_SOURCE_DIR}/include/ngl/Vec3.h @@ -258,6 +261,7 @@ if(NOT DEFINED PYNGL_ONLY) ${CMAKE_SOURCE_DIR}/tests/MessageTests.cpp ${CMAKE_SOURCE_DIR}/tests/NGLStreamTest.cpp ${CMAKE_SOURCE_DIR}/tests/TextureTests.cpp + ${CMAKE_SOURCE_DIR}/tests/BufferTextureTests.cpp ${CMAKE_SOURCE_DIR}/tests/VAOFactoryTests.cpp ) @@ -326,7 +330,7 @@ if(NOT DEFINED PYNGL_ONLY) # add_custom_target(CopyTestfiles ALL # COMMAND ${CMAKE_COMMAND} -E copy_directory -# ${CMAKE_SOURCE_DIR}/tests/files +# ${CMAKE_SOURCE_DIR}/tests/filesinary # ${CMAKE_BINARY_DIR}/files # COMMENT "Copy Test files to build directory" # ) diff --git a/Mac.md b/Mac.md index fd7f9df2..0d071d6c 100644 --- a/Mac.md +++ b/Mac.md @@ -6,9 +6,9 @@ To install the compilers for MacOSX we can use the xcode app from the app store. and follow the prompts. -## NGL dependancies +## NGL dependencies -NGL has a number of dependancies which can be installed using vcpkg. However before that we need to install some other packages. +NGL has a number of dependencies which can be installed using vcpkg. However before that we need to install some other packages. ## brew @@ -64,8 +64,6 @@ If you wish to install the python binding you can add ``` - - ## Building NGL To build NGL we need to do the following @@ -78,15 +76,38 @@ make make install ``` +## Adding NGL to your path + +To add NGL to your path you can add the following to your ```~/.zprofile``` file this assumes you have installed the vcpgk and NGL in your home directory. + +``` +export CMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake +export CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH:~/NGL/:~/Qt/6.3.0/macos/lib/cmake +export VCPKG_ROOT=~/vcpkg +``` + +To activate this you can either restart your terminal or type + +``` +source ~/.zprofile +``` + ## Python Build with PyBind +typically this is not needed as we don't use the python binding in any courses. However if you wish to build the python binding you can do the following (assuming you have installed pybind11 using vcpkg and are using pyenv to manage your python versions) + +``` cmake -DCMAKE_INSTALL_PREFIX=~/NGL -DBUILD_PYNGL=1 -DPYTHON_EXECUTABLE:FILEPATH=~/.pyenv/shims/python -DPYTHON_INCLUDE_DIRS=/Users/jmacey/.pyenv/versions/3.9.7/include/python3.9 -DPYTHON_LIBRARIES=~/.pyenv/versions/3.9.7/lib .. +``` -cmake -DCMAKE_INSTALL_PREFIX=~/NGL -DBUILD_PYNGL=1 -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") .. +or if you have the python libraries in your path you can use the following +``` +cmake -DCMAKE_INSTALL_PREFIX=~/NGL -DBUILD_PYNGL=1 -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") .. +``` diff --git a/include/ngl/BufferTextures.h b/include/ngl/BufferTextures.h new file mode 100644 index 00000000..1d729a7d --- /dev/null +++ b/include/ngl/BufferTextures.h @@ -0,0 +1,82 @@ +/* +Copyright (C) 2024 Jon Macey + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef BUFFER_TEXTURE_H_ +#define BUFFER_TEXTURE_H_ +/// @file BufferTexture.h +/// @brief BufferTexture storage class +#include "Types.h" +#include +#include + +namespace ngl +{ + +enum class GLTexBufferInternalFormat : GLenum +{ + R8 = GL_R8, + R16 = GL_R16, + R16F = GL_R16F, + R32F = GL_R32F, + R8I = GL_R8I, + R16I = GL_R16I, + R32I = GL_R32I, + R8UI = GL_R8UI, + R16UI = GL_R16UI, + R32UI = GL_R32UI, + RGB = GL_RG8, + RB16 = GL_RG16, + RG16F = GL_RG16F, + RG32F = GL_RG32F, + RG8I = GL_RG8I, + RG16I = GL_RG16I, + RG32I = GL_RG32I, + RG8UI = GL_RG8UI, + RG16UI = GL_RG16UI, + RG32UI = GL_RG32UI, + RGB32F = GL_RGB32F, + RGB32I = GL_RGB32I, + RGB32UI = GL_RGB32UI, + RGBA8 = GL_RGBA8, + RGBA16 = GL_RGBA16, + RGBA16F = GL_RGBA16F, + RGBA32F = GL_RGBA32F, + RGB8I = GL_RGBA8I, + RGBA16I = GL_RGBA16I, + RGBA32I = GL_RGBA32I, + RGBA8UI = GL_RGBA8UI, + RGBA16UI = GL_RGBA16UI, + RGBA32UI = GL_RGBA32UI +}; + +struct BufferTexture +{ + GLuint id; + GLenum target; + GLenum usage; + GLTexBufferInternalFormat internalFormat; + size_t size; +}; + +class BufferTextures +{ + public: + static size_t numBuffers() noexcept; + static void clear() noexcept; + private: + static std::unordered_map< std::string, BufferTexture > s_texturebuffers; +}; +} // end namspace ngl +#endif \ No newline at end of file diff --git a/include/ngl/ShaderLib.h b/include/ngl/ShaderLib.h index 85284446..96e00d35 100644 --- a/include/ngl/ShaderLib.h +++ b/include/ngl/ShaderLib.h @@ -138,6 +138,10 @@ class NGL_DLLEXPORT ShaderLib //---------------------------------------------------------------------------------------------------------------------- static void bindFragDataLocation(std::string_view _programName, GLuint _index, std::string_view _attribName) noexcept; + // bind sampler + static void bindSampler(std::string_view _samplerName, GLuint _index) noexcept; + + //---------------------------------------------------------------------------------------------------------------------- /// @brief method to load shaders /// @param[in] _shaderName the name of the shader to be stored in the Manager diff --git a/include/ngl/ShaderProgram.h b/include/ngl/ShaderProgram.h index 3985bcca..166f21fd 100644 --- a/include/ngl/ShaderProgram.h +++ b/include/ngl/ShaderProgram.h @@ -77,6 +77,14 @@ class NGL_DLLEXPORT ShaderProgram /// @param _attribName the name of the attribute we wish to use //---------------------------------------------------------------------------------------------------------------------- void bindAttribute(GLuint index, std::string_view _attribName) noexcept; + + //---------------------------------------------------------------------------------------------------------------------- + /// @brief bind a sampler in the Program object to _index using attribname + /// @param _index the index number we wish to bind to + /// @param _attribName the name of the attribute we wish to use + //---------------------------------------------------------------------------------------------------------------------- + void bindSampler(std::string_view _name,GLuint index) noexcept; + //---------------------------------------------------------------------------------------------------------------------- /// @brief bind fragment output location in the Program object to _index using attribname /// @param _index the index number we wish to bind to diff --git a/src/BufferTextures.cpp b/src/BufferTextures.cpp new file mode 100644 index 00000000..6929c9f6 --- /dev/null +++ b/src/BufferTextures.cpp @@ -0,0 +1,22 @@ +#include "BufferTextures.h" + +namespace ngl +{ + +std::unordered_map< std::string, BufferTexture > BufferTextures::s_texturebuffers; + +size_t BufferTextures::numBuffers() noexcept +{ + return s_texturebuffers.size(); +} + +void BufferTextures::clear() noexcept +{ + for(auto &t : s_texturebuffers) + { + glDeleteBuffers(1, &t.second.id); + } + s_texturebuffers.clear(); +} + +}// end namespace ngl \ No newline at end of file diff --git a/src/ShaderLib.cpp b/src/ShaderLib.cpp index de6638c6..996038e3 100644 --- a/src/ShaderLib.cpp +++ b/src/ShaderLib.cpp @@ -594,6 +594,27 @@ void ShaderLib::bindAttribute(std::string_view _programName, GLuint _index, std: } } +//---------------------------------------------------------------------------------------------------------------------- +void ShaderLib::bindSampler(std::string_view _samplerName, GLuint _index) noexcept +{ + + + + m_shaderPrograms[m_currentShader]->bindSampler(_samplerName, _index); + // // make sure we have a valid program + // if(auto program = m_shaderPrograms.find(_programName.data()); program != m_shaderPrograms.end()) + // { + // program->second->bindSampler(_index); + // } + // else + // { + // NGLMessage::addWarning(fmt::format("Warning Program not know in bindSampler {0}", _programName.data())); + // } +} + + + + //---------------------------------------------------------------------------------------------------------------------- void ShaderLib::bindFragDataLocation(std::string_view _programName, GLuint _index, std::string_view _attribName) noexcept { diff --git a/src/ShaderProgram.cpp b/src/ShaderProgram.cpp index 8224f644..d03b4ac9 100644 --- a/src/ShaderProgram.cpp +++ b/src/ShaderProgram.cpp @@ -93,6 +93,26 @@ void ShaderProgram::bindAttribute(GLuint _index, std::string_view _attribName) n NGLCheckGLError(__FILE__, __LINE__); } + +void ShaderProgram::bindSampler(std::string_view _name,GLuint _index) noexcept +{ + if(m_linked) + { + NGLMessage::addMessage(fmt::format("binding sampler {0} after link ", _index)); + } + auto uniform = m_registeredUniforms.find(_name.data()); + if(uniform != m_registeredUniforms.end()) + { + glBindSampler(uniform->second.loc, _index); + + } + else + { + NGLMessage::addWarning(fmt::format("Uniform {0} not found in Program {1}", _name, m_programName.data())); + } + NGLCheckGLError(__FILE__, __LINE__); +} + void ShaderProgram::bindFragDataLocation(GLuint _index, std::string_view _attribName) noexcept { if(m_linked) diff --git a/tests/BufferTextureTests.cpp b/tests/BufferTextureTests.cpp new file mode 100644 index 00000000..fcecde8c --- /dev/null +++ b/tests/BufferTextureTests.cpp @@ -0,0 +1,14 @@ +#include +#include + +TEST(BufferTextures,construct) +{ + ngl::BufferTextures::clear(); + EXPECT_EQ(ngl::BufferTextures::numBuffers(),0); +} + +TEST(BufferTextures,add) +{ +ngl::BufferTextures::clear(); + +} \ No newline at end of file diff --git a/tests/main.cpp b/tests/main.cpp index f1670a22..8ded5f90 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -87,7 +87,7 @@ int main(int argc, char **argv) if(useOpenGL == false) { std::cerr << "excluding tests\n"; - ::testing::GTEST_FLAG(filter) = "-ShaderLib.*:Shader*:VAOPrimitives.*:NGLInit*:VAOFactory*"; + ::testing::GTEST_FLAG(filter) = "-ShaderLib.*:Shader*:VAOPrimitives.*:NGLInit*:VAOFactory*:BufferTextures*"; } // should put this on an argument // testing::internal::CaptureStdout();