Made a naming choice for will <3.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
@@ -37,7 +37,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME jlog
|
||||
URL https://git.redacted.cc/josh/jlog/Prerelease-16.zip
|
||||
URL https://git.redacted.cc/josh/jlog/Prerelease-17.zip
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace JGL {
|
||||
|
||||
#define stringify(name) # name
|
||||
|
||||
enum class Direction : u8 {
|
||||
None = 0,
|
||||
Vertical = 1,
|
||||
@@ -18,25 +21,12 @@ namespace JGL {
|
||||
}
|
||||
|
||||
static std::string to_string(const JGL::Direction& direction) {
|
||||
switch (direction) {
|
||||
case JGL::Direction::None:
|
||||
return "None";
|
||||
case JGL::Direction::Vertical:
|
||||
return "Vertical";
|
||||
case JGL::Direction::Horizontal:
|
||||
return "Horizontal";
|
||||
case JGL::Direction::Diagonal_NWSE:
|
||||
return "Diagonal_NWSE";
|
||||
case JGL::Direction::Diagonal_SWNE:
|
||||
return "Diagonal_SWNE";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
return stringify(direction);
|
||||
}
|
||||
|
||||
// TODO come up with a cleaner way to type out sample-rates before release.
|
||||
// :shrug:, I'm not very creative. - Redacted.
|
||||
enum class MSAA_SAMPLE_RATE : u8 {
|
||||
/*enum class MSAA_SAMPLE_RATE : u8 {
|
||||
NONE = 0,
|
||||
MSAA_2X = 1,
|
||||
MSAA_4X = 2,
|
||||
@@ -49,6 +39,17 @@ namespace JGL {
|
||||
ANISOTROPY_4X = 4,
|
||||
ANISOTROPY_8X = 8,
|
||||
ANISOTROPY_16X = 16
|
||||
};*/
|
||||
|
||||
/// This enumeration is used by both MSAA and Anisotropic Filtering.
|
||||
/// However, higher rates may not be supported by one, or the other.
|
||||
/// This additionally depends on what your graphics supports.
|
||||
enum class SampleRate : u8 {
|
||||
NONE = 0, X0 = 0,
|
||||
X2 = 2,
|
||||
X4 = 4,
|
||||
X8 = 8,
|
||||
X16 = 16,
|
||||
};
|
||||
|
||||
enum class FilteringMode : u8 {
|
||||
@@ -68,34 +69,13 @@ namespace JGL {
|
||||
CLAMP_TO_BORDER = 3 // Effectively the same as clamp_to_edge
|
||||
};
|
||||
|
||||
|
||||
enum class ColorFormat : bool { RGB = false, RGBA = true };
|
||||
|
||||
static std::string to_string(const JGL::MSAA_SAMPLE_RATE& sample_rate) {
|
||||
switch (sample_rate) {
|
||||
case MSAA_SAMPLE_RATE::NONE:
|
||||
return "No MSAA";
|
||||
case MSAA_SAMPLE_RATE::MSAA_2X:
|
||||
return "MSAA 2x";
|
||||
case MSAA_SAMPLE_RATE::MSAA_4X:
|
||||
return "MSAA 4x";
|
||||
case MSAA_SAMPLE_RATE::MSAA_8X:
|
||||
return "MSAA 8x";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
static int to_int(const JGL::MSAA_SAMPLE_RATE& sample_rate) {
|
||||
switch (sample_rate) {
|
||||
case MSAA_SAMPLE_RATE::NONE:
|
||||
return 0;
|
||||
case MSAA_SAMPLE_RATE::MSAA_2X:
|
||||
return 2;
|
||||
case MSAA_SAMPLE_RATE::MSAA_4X:
|
||||
return 4;
|
||||
case MSAA_SAMPLE_RATE::MSAA_8X:
|
||||
return 8;
|
||||
default:
|
||||
return 0;
|
||||
static std::string to_string(const JGL::SampleRate& sample_rate) {
|
||||
return stringify(sample_rate);
|
||||
}
|
||||
static int to_int(const JGL::SampleRate& sample_rate) {
|
||||
return (int)sample_rate;
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,8 @@ namespace JGL {
|
||||
}
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2i;
|
||||
|
||||
/// A
|
||||
class JGL::RenderTarget {
|
||||
private:
|
||||
Color4 clear_color{0,0,0,0};
|
||||
@@ -21,28 +23,28 @@ private:
|
||||
GLuint framebuffer_object = 0;
|
||||
GLuint depth_buffer = 0;
|
||||
const Texture* texture = nullptr;
|
||||
MSAA_SAMPLE_RATE msaa_sample_rate = MSAA_SAMPLE_RATE::NONE;
|
||||
SampleRate msaa_sample_rate = SampleRate::NONE;
|
||||
GLuint msaa_framebuffer_object = 0;
|
||||
GLuint msaa_depth_buffer = 0;
|
||||
GLuint msaa_render_buffer = 0;
|
||||
void Erase();
|
||||
public:
|
||||
/// @returns The Render Target currently in use by OpenGL.
|
||||
/// @note Zero is the screen.
|
||||
/// @returns A handle to the RenderTarget currently in use by OpenGL.
|
||||
/// @note zero is returned when no RenderTarget is in use.
|
||||
static GLuint GetActiveGLFramebufferHandle();
|
||||
|
||||
/// Changes the Render Target that OpenGL will draw on.
|
||||
/// @param render_target The new Render Target for OpenGL to draw on.
|
||||
/// Changes the RenderTarget that OpenGL will draw on.
|
||||
/// @param render_target The new RenderTarget for OpenGL to draw on.
|
||||
static void SetActiveGLRenderTarget(const RenderTarget& render_target);
|
||||
|
||||
/// Changes the size of the renderable area of this Render Target.
|
||||
/// Changes the size of the render-able area of this RenderTarget.
|
||||
/// @param new_size new width & height in pixels.
|
||||
/// @note The data stored in this Render Target will be lost.
|
||||
void Resize(const Vector2i& new_size);
|
||||
|
||||
/// Sets the MSAA mode for this Render Target.
|
||||
/// @returns false if the mode isn't available, true for success.
|
||||
[[nodiscard]] bool SetMSAAEnabled(MSAA_SAMPLE_RATE sample_rate);
|
||||
[[nodiscard]] bool SetMSAAEnabled(SampleRate sample_rate);
|
||||
|
||||
/// If you're using MSAA and not using J2D || J3D Begin & End you must do this.
|
||||
void MSAABlit() const;
|
||||
@@ -71,7 +73,7 @@ public:
|
||||
[[nodiscard]] Vector2i GetDimensions() const;
|
||||
|
||||
/// @returns The currently selected MSAA Sample Rate.
|
||||
[[nodiscard]] MSAA_SAMPLE_RATE GetMSAASampleRate() const;
|
||||
[[nodiscard]] SampleRate GetMSAASampleRate() const;
|
||||
|
||||
/// @returns Whether or not this Render Target is using MSAA.
|
||||
[[nodiscard]] bool MSAAEnabled() const;
|
||||
@@ -116,7 +118,7 @@ public:
|
||||
/// @param use_depth Whether or not this Render Target will have depth information.
|
||||
/// @param sample_rate The MSAA sample rate this Render Target will use.
|
||||
explicit RenderTarget(const Vector2i& size, const Color4& clear_color = Colors::Transparent, bool use_depth = false,
|
||||
MSAA_SAMPLE_RATE sample_rate = MSAA_SAMPLE_RATE::NONE, FilteringMode filteirng_mode = FilteringMode::NEAREST);
|
||||
SampleRate sample_rate = SampleRate::NONE, FilteringMode filteirng_mode = FilteringMode::NEAREST);
|
||||
|
||||
/// Deletes this Render Target.
|
||||
/** @note If this Render Target was made with a Texture that already existed
|
||||
|
@@ -20,7 +20,7 @@ protected:
|
||||
ColorFormat format = ColorFormat::RGBA;
|
||||
FilteringMode filtering_mode;
|
||||
WrappingMode wrapping_mode;
|
||||
ANISOTROPY_SAMPLE_RATE anisotropy;
|
||||
SampleRate anisotropy;
|
||||
void load(const unsigned char* pixels);
|
||||
std::vector<unsigned char> png(const std::filesystem::path& file);
|
||||
std::vector<unsigned char> bmp(const std::filesystem::path& file);
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
/// @returns The way this texture behaves when used on geometry of different sizes.
|
||||
[[nodiscard]] WrappingMode GetWrappingMode() const;
|
||||
/// @returns The current level of anisotropic filtering for this texture.
|
||||
[[nodiscard]] ANISOTROPY_SAMPLE_RATE GetAnisotropySampleRate() const;
|
||||
[[nodiscard]] SampleRate GetAnisotropySampleRate() const;
|
||||
/// @returns The orientation of this texture in v-ram.
|
||||
/// @note true is right-side-up because OpenGL defaults to upside-down.
|
||||
[[nodiscard]] bool Inverted() const;
|
||||
@@ -46,13 +46,13 @@ public:
|
||||
public:
|
||||
/// Load a texture from a file,
|
||||
explicit Texture(const std::filesystem::path& file, FilteringMode filtering_mode = FilteringMode::BILINEAR,
|
||||
ANISOTROPY_SAMPLE_RATE anisotropy = ANISOTROPY_SAMPLE_RATE::NONE, WrappingMode wrapping_mode = WrappingMode::CLAMP_TO_EDGE, bool invert_y = true);
|
||||
SampleRate anisotropy = SampleRate::NONE, WrappingMode wrapping_mode = WrappingMode::CLAMP_TO_EDGE, bool invert_y = true);
|
||||
/// Load a texture from raw pixels.
|
||||
Texture(const Color4* pixels, const Vector2i& size, FilteringMode filtering_mode = FilteringMode::BILINEAR,
|
||||
ANISOTROPY_SAMPLE_RATE anisotropy = ANISOTROPY_SAMPLE_RATE::NONE, WrappingMode wrapping_mode = WrappingMode::CLAMP_TO_EDGE);
|
||||
SampleRate anisotropy = SampleRate::NONE, WrappingMode wrapping_mode = WrappingMode::CLAMP_TO_EDGE);
|
||||
/// Load a texture from raw pixels.
|
||||
Texture(const Color3* pixels, const Vector2i& size, FilteringMode filtering_mode = FilteringMode::BILINEAR,
|
||||
ANISOTROPY_SAMPLE_RATE anisotropy = ANISOTROPY_SAMPLE_RATE::NONE, WrappingMode wrapping_mode = WrappingMode::CLAMP_TO_EDGE);
|
||||
SampleRate anisotropy = SampleRate::NONE, WrappingMode wrapping_mode = WrappingMode::CLAMP_TO_EDGE);
|
||||
/// Construct a Texture Atlas from many different textures.
|
||||
/// @note THIS IS UNFINISHED.
|
||||
Texture(const Texture* textures, const size_t& texture_count);
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
public:
|
||||
/// @returns True if this system supports anisotropy.
|
||||
// TODO add a similar mechanism for MSAA so the extension isn't required.
|
||||
static ANISOTROPY_SAMPLE_RATE MaxAnisotropySampleRate();
|
||||
static enum SampleRate MaxAnisotropySampleRate();
|
||||
/// @returns The biggest size for a texture on this system.
|
||||
/// @note on modern systems this is *usually* ridiculous.
|
||||
[[nodiscard]] static Vector2i MaxSize();
|
||||
|
4
main.cpp
4
main.cpp
@@ -128,10 +128,10 @@ public:
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
image = new Texture("assets/sprites/Re3D.png", FilteringMode::BILINEAR);
|
||||
image = new Texture("assets/sprites/Re3D.png", FilteringMode::MIPMAP_NEAREST, JGL::SampleRate::X16);
|
||||
image_mask = new Texture("assets/sprites/alpha_mask_2.png");
|
||||
j2d_render_target = new RenderTarget({540, 500}, {0,0,0,0}, false,
|
||||
MSAA_SAMPLE_RATE::NONE, FilteringMode::MIPMAP_TRILINEAR);
|
||||
SampleRate::NONE, FilteringMode::MIPMAP_TRILINEAR);
|
||||
|
||||
//Texture::MultiplyByAlphaMask(*image, *image_mask);
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ void JGL::RenderTarget::Erase() {
|
||||
glDeleteFramebuffers(1, &framebuffer_object);
|
||||
|
||||
if (MSAAEnabled())
|
||||
SetMSAAEnabled(MSAA_SAMPLE_RATE::NONE);
|
||||
SetMSAAEnabled(SampleRate::NONE);
|
||||
}
|
||||
|
||||
Color4 JGL::RenderTarget::GetClearColor() const {
|
||||
@@ -76,7 +76,7 @@ JGL::RenderTarget::RenderTarget(const JGL::Texture* texture, const Color4& clear
|
||||
texture_created_by_us = false;
|
||||
}
|
||||
|
||||
JGL::RenderTarget::RenderTarget(const Vector2i& size, const Color4& clear_color, bool use_depth, MSAA_SAMPLE_RATE sample_rate, FilteringMode filtering_mode) {
|
||||
JGL::RenderTarget::RenderTarget(const Vector2i& size, const Color4& clear_color, bool use_depth, SampleRate sample_rate, FilteringMode filtering_mode) {
|
||||
if (size.x < 1 || size.y < 1)
|
||||
Logger::Fatal("Creating a render target where the color attachment is empty?");
|
||||
|
||||
@@ -116,7 +116,7 @@ JGL::RenderTarget::RenderTarget(const Vector2i& size, const Color4& clear_color,
|
||||
this->size = size;
|
||||
texture_created_by_us = true;
|
||||
|
||||
if (sample_rate != MSAA_SAMPLE_RATE::NONE)
|
||||
if (sample_rate != SampleRate::NONE)
|
||||
SetMSAAEnabled(sample_rate);
|
||||
}
|
||||
|
||||
@@ -161,8 +161,8 @@ void JGL::RenderTarget::Resize(const Vector2i& new_size) {
|
||||
|
||||
//Disable & Re-enable MSAA so the msaa buffer is remade with the correct dimensions.
|
||||
if (MSAAEnabled()) {
|
||||
MSAA_SAMPLE_RATE current_sample_rate = msaa_sample_rate;
|
||||
SetMSAAEnabled(MSAA_SAMPLE_RATE::NONE);
|
||||
SampleRate current_sample_rate = msaa_sample_rate;
|
||||
SetMSAAEnabled(SampleRate::NONE);
|
||||
SetMSAAEnabled(current_sample_rate);
|
||||
}
|
||||
}
|
||||
@@ -177,15 +177,15 @@ bool JGL::RenderTarget::OwnsTexture() const {
|
||||
return texture_created_by_us;
|
||||
}
|
||||
|
||||
JGL::MSAA_SAMPLE_RATE JGL::RenderTarget::GetMSAASampleRate() const {
|
||||
JGL::SampleRate JGL::RenderTarget::GetMSAASampleRate() const {
|
||||
return msaa_sample_rate;
|
||||
}
|
||||
|
||||
bool JGL::RenderTarget::MSAAEnabled() const {
|
||||
return msaa_sample_rate != MSAA_SAMPLE_RATE::NONE;
|
||||
return msaa_sample_rate != SampleRate::NONE;
|
||||
}
|
||||
|
||||
bool JGL::RenderTarget::SetMSAAEnabled(JGL::MSAA_SAMPLE_RATE sample_rate) {
|
||||
bool JGL::RenderTarget::SetMSAAEnabled(JGL::SampleRate sample_rate) {
|
||||
// If we'd be setting the same sample_rate we already have.
|
||||
if (sample_rate == msaa_sample_rate)
|
||||
return false;
|
||||
@@ -195,7 +195,7 @@ bool JGL::RenderTarget::SetMSAAEnabled(JGL::MSAA_SAMPLE_RATE sample_rate) {
|
||||
return false;
|
||||
|
||||
// Remove it if they request no msaa or if what they requested is different than what they already have.
|
||||
if (sample_rate == MSAA_SAMPLE_RATE::NONE || msaa_sample_rate != MSAA_SAMPLE_RATE::NONE) {
|
||||
if (sample_rate == SampleRate::NONE || msaa_sample_rate != SampleRate::NONE) {
|
||||
if(using_depth)
|
||||
glDeleteRenderbuffers(1, &msaa_depth_buffer);
|
||||
|
||||
@@ -205,10 +205,10 @@ bool JGL::RenderTarget::SetMSAAEnabled(JGL::MSAA_SAMPLE_RATE sample_rate) {
|
||||
msaa_framebuffer_object = 0;
|
||||
msaa_depth_buffer = 0;
|
||||
msaa_render_buffer = 0;
|
||||
msaa_sample_rate = MSAA_SAMPLE_RATE::NONE;
|
||||
msaa_sample_rate = SampleRate::NONE;
|
||||
|
||||
// Only return here if they specifically requested no MSAA. else continue to change mode.
|
||||
if (sample_rate == MSAA_SAMPLE_RATE::NONE)
|
||||
if (sample_rate == SampleRate::NONE)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ bool JGL::RenderTarget::SetMSAAEnabled(JGL::MSAA_SAMPLE_RATE sample_rate) {
|
||||
msaa_sample_rate = sample_rate;
|
||||
|
||||
if (failure)
|
||||
SetMSAAEnabled(MSAA_SAMPLE_RATE::NONE);
|
||||
SetMSAAEnabled(SampleRate::NONE);
|
||||
return failure;
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
using namespace JGL;
|
||||
|
||||
Texture::Texture(const std::filesystem::path& file, FilteringMode filtering_mode, ANISOTROPY_SAMPLE_RATE anisotropy, WrappingMode wrapping_mode, bool invert_y) :
|
||||
Texture::Texture(const std::filesystem::path& file, FilteringMode filtering_mode, SampleRate anisotropy, WrappingMode wrapping_mode, bool invert_y) :
|
||||
invert_y(invert_y), filtering_mode(filtering_mode), anisotropy(anisotropy), wrapping_mode(wrapping_mode) {
|
||||
std::vector<unsigned char> pixels{};
|
||||
|
||||
@@ -189,10 +189,10 @@ void Texture::load(const unsigned char* pixels) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
if (anisotropy != ANISOTROPY_SAMPLE_RATE::NONE) {
|
||||
if (anisotropy != SampleRate::NONE) {
|
||||
if (anisotropy > MaxAnisotropySampleRate())
|
||||
Logger::Error("Anisotropy set higher than the maximum value for this system, disabled, use Texture::MaxAnisotropy()."),
|
||||
anisotropy = ANISOTROPY_SAMPLE_RATE::NONE;
|
||||
anisotropy = SampleRate::NONE;
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, (int) anisotropy);
|
||||
}
|
||||
@@ -207,9 +207,9 @@ void Texture::load(const unsigned char* pixels) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
if (anisotropy != ANISOTROPY_SAMPLE_RATE::NONE)
|
||||
if (anisotropy != SampleRate::NONE)
|
||||
Logger::Error("Anisotropy only applies when using mipmaps with a 3D perspective, disabled."),
|
||||
anisotropy = ANISOTROPY_SAMPLE_RATE::NONE;
|
||||
anisotropy = SampleRate::NONE;
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, previous_texture);
|
||||
}
|
||||
@@ -261,12 +261,12 @@ WrappingMode Texture::GetWrappingMode() const {
|
||||
return wrapping_mode;
|
||||
}
|
||||
|
||||
Texture::Texture(const Color4* pixels, const Vector2i& size, FilteringMode filtering_mode, ANISOTROPY_SAMPLE_RATE anisotropy, WrappingMode wrapping_mode) :
|
||||
Texture::Texture(const Color4* pixels, const Vector2i& size, FilteringMode filtering_mode, SampleRate anisotropy, WrappingMode wrapping_mode) :
|
||||
size(size), format(ColorFormat::RGBA), filtering_mode(filtering_mode), anisotropy(anisotropy), wrapping_mode(wrapping_mode) {
|
||||
load((unsigned char*) pixels);
|
||||
}
|
||||
|
||||
Texture::Texture(const Color3* pixels, const Vector2i& size, FilteringMode filtering_mode, ANISOTROPY_SAMPLE_RATE anisotropy, WrappingMode wrapping_mode) :
|
||||
Texture::Texture(const Color3* pixels, const Vector2i& size, FilteringMode filtering_mode, SampleRate anisotropy, WrappingMode wrapping_mode) :
|
||||
size(size), format(ColorFormat::RGB), filtering_mode(filtering_mode), anisotropy(anisotropy), wrapping_mode(wrapping_mode) {
|
||||
load((unsigned char*) pixels);
|
||||
}
|
||||
@@ -326,23 +326,23 @@ Vector2i Texture::MaxSize() {
|
||||
return { max_size, max_size };
|
||||
}
|
||||
|
||||
ANISOTROPY_SAMPLE_RATE Texture::MaxAnisotropySampleRate() {
|
||||
SampleRate Texture::MaxAnisotropySampleRate() {
|
||||
if (!GLAD_GL_ARB_texture_filter_anisotropic)
|
||||
return ANISOTROPY_SAMPLE_RATE::NONE;
|
||||
return SampleRate::NONE;
|
||||
|
||||
float anisotropy;
|
||||
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &anisotropy);
|
||||
|
||||
if (anisotropy == 2)
|
||||
return ANISOTROPY_SAMPLE_RATE::ANISOTROPY_2X;
|
||||
return SampleRate::X2;
|
||||
else if (anisotropy == 4)
|
||||
return ANISOTROPY_SAMPLE_RATE::ANISOTROPY_4X;
|
||||
return SampleRate::X4;
|
||||
else if (anisotropy == 8)
|
||||
return ANISOTROPY_SAMPLE_RATE::ANISOTROPY_8X;
|
||||
return SampleRate::X8;
|
||||
else
|
||||
return ANISOTROPY_SAMPLE_RATE::ANISOTROPY_16X;
|
||||
return SampleRate::X16;
|
||||
}
|
||||
|
||||
ANISOTROPY_SAMPLE_RATE Texture::GetAnisotropySampleRate() const {
|
||||
SampleRate Texture::GetAnisotropySampleRate() const {
|
||||
return anisotropy;
|
||||
}
|
||||
|
Reference in New Issue
Block a user