Skip to content

Commit

Permalink
Add FrameBuffer::getPixelWidth/Height and ShaderProgram::Context::set…
Browse files Browse the repository at this point in the history
…Uniform(int location, Rgb)
  • Loading branch information
jhasse committed Jan 25, 2025
1 parent c98ceb3 commit d15aa27
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/freetype.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2007-2024 Jan Niklas Hasse <[email protected]>
// Copyright 2007-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt

#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS
#include "freetype.hpp"

#include "ShaderCache.hpp"
#include "helper.hpp"
#include "jngl/Finally.hpp"
#include "jngl/ScaleablePixels.hpp"
#include "jngl/matrix.hpp"
#include "jngl/screen.hpp"
Expand Down
8 changes: 8 additions & 0 deletions src/jngl/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ Vec2 FrameBuffer::getSize() const {
impl->texture.getPreciseHeight() / getScaleFactor() };
}

Pixels FrameBuffer::getPixelWidth() const {
return static_cast<Pixels>(impl->width);
}

Pixels FrameBuffer::getPixelHeight() const {
return static_cast<Pixels>(impl->height);
}

GLuint FrameBuffer::getTextureID() const {
return impl->texture.getID();
}
Expand Down
9 changes: 6 additions & 3 deletions src/jngl/FrameBuffer.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright 2012-2023 Jan Niklas Hasse <[email protected]>
// Copyright 2012-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
/// Contains jngl::FrameBuffer class
/// @file
#pragma once

#include "Color.hpp"
#include "Finally.hpp"
#include "Mat3.hpp"
#include "Pixels.hpp"
#include "Vec2.hpp"
#include "Vertex.hpp"
#include "ShaderProgram.hpp"

#include <functional>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -93,6 +93,9 @@ class FrameBuffer {
/// Returns the size in screen pixels
Vec2 getSize() const;

Pixels getPixelWidth() const;
Pixels getPixelHeight() const;

/// Returns the OpenGL texture ID of the associated image buffer
///
/// While this is an implementation detail, it can be useful if you want to draw the
Expand Down
5 changes: 5 additions & 0 deletions src/jngl/ShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ void ShaderProgram::Context::setUniform(const int location, const float v0, cons
glUniform4f(location, v0, v1, v2, v3);
}

void ShaderProgram::Context::setUniform(const int location, const Rgb color) {
assert(referenceCount >= 0);
glUniform3f(location, color.getRed(), color.getGreen(), color.getBlue());
}

} // namespace jngl
7 changes: 5 additions & 2 deletions src/jngl/ShaderProgram.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2018-2020 Jan Niklas Hasse <[email protected]>
// Copyright 2018-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
/// Contains jngl::ShaderProgram class
/// @file
#pragma once

#include "Finally.hpp"
#include "Rgb.hpp"

#include <memory>
#include <string>
Expand Down Expand Up @@ -39,6 +39,9 @@ class ShaderProgram {
static void setUniform(int location, float v0, float v1);
static void setUniform(int location, float v0, float v1, float v2, float v3);

/// sets a vec3 to the color of the Rgb object
static void setUniform(int location, Rgb);

private:
static int referenceCount;
static const Impl* activeImpl;
Expand Down
3 changes: 2 additions & 1 deletion src/jngl/sprite.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright 2012-2024 Jan Niklas Hasse <[email protected]>
// Copyright 2012-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
/// Contains jngl::Sprite class and related functions
/// \file
#pragma once

#include "Drawable.hpp"
#include "Finally.hpp"
#include "Rgb.hpp"
#include "Rgba.hpp"
#include "ShaderProgram.hpp"
Expand Down

0 comments on commit d15aa27

Please sign in to comment.