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/include/ngl/BufferTextures.h b/include/ngl/BufferTextures.h new file mode 100644 index 00000000..8d7bb0cd --- /dev/null +++ b/include/ngl/BufferTextures.h @@ -0,0 +1,81 @@ +/* +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 + +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; + + 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..bfd3b6ad --- /dev/null +++ b/src/BufferTextures.cpp @@ -0,0 +1,13 @@ +#include "BufferTextures.h" + +namespace ngl +{ + +std::unordered_map< std::string, BufferTexture > BufferTextures::s_texturebuffers; + +size_t BufferTextures::numBuffers() noexcept +{ + return s_texturebuffers.size(); +} + +} \ 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..7784df8f --- /dev/null +++ b/tests/BufferTextureTests.cpp @@ -0,0 +1,8 @@ +#include +#include + +TEST(BufferTextures,construct) +{ + EXPECT_EQ(ngl::BufferTextures::numBuffers(),0); +} + 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();