Skip to content

Commit

Permalink
Merge branch 'main' of github.com:/NCCA/NGL
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacey committed Jun 21, 2024
2 parents 32512cd + 2b8b5c7 commit fa6c5e8
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

)
Expand Down Expand Up @@ -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"
# )
Expand Down
31 changes: 26 additions & 5 deletions Mac.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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'))") ..
```



Expand Down
82 changes: 82 additions & 0 deletions include/ngl/BufferTextures.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef BUFFER_TEXTURE_H_
#define BUFFER_TEXTURE_H_
/// @file BufferTexture.h
/// @brief BufferTexture storage class
#include "Types.h"
#include <string>
#include <unordered_map>

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
4 changes: 4 additions & 0 deletions include/ngl/ShaderLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions include/ngl/ShaderProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/BufferTextures.cpp
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions src/ShaderLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
20 changes: 20 additions & 0 deletions src/ShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions tests/BufferTextureTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <gtest/gtest.h>
#include <ngl/BufferTextures.h>

TEST(BufferTextures,construct)
{
ngl::BufferTextures::clear();
EXPECT_EQ(ngl::BufferTextures::numBuffers(),0);
}

TEST(BufferTextures,add)
{
ngl::BufferTextures::clear();

}
2 changes: 1 addition & 1 deletion tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fa6c5e8

Please sign in to comment.