Add a way to query the max texture size.
This commit is contained in:
@@ -91,10 +91,11 @@ public:
|
||||
/// @returns The color that should be used to clear this Render Target.
|
||||
[[nodiscard]] Color4 GetClearColor() const;
|
||||
|
||||
|
||||
/// @returns The color information for this Render Target.
|
||||
/// @note Both the CPU & GPU cannot do anything while this takes place. It's very slow.
|
||||
/// @note The CPU thread this is called from & the GPU cannot do anything while this takes place. It's very slow.
|
||||
[[nodiscard]] std::vector<GLfloat> GetPixels() const;
|
||||
|
||||
[[nodiscard]] static Vector2i MaximimSize();
|
||||
public:
|
||||
/// Create a Render Target from a Render Target that already exists.
|
||||
/** @note Render Targets that are copies of another will copy the Texture.
|
||||
|
@@ -27,7 +27,6 @@ namespace JGL {
|
||||
class Texture;
|
||||
}
|
||||
|
||||
/// TODO handle the case of a texture being loaded that exceeds the max texture size.
|
||||
/// Represents texture data loaded on the GPU. Contains a handle that can be passed to OpenGL draw calls.
|
||||
class JGL::Texture {
|
||||
protected:
|
||||
@@ -40,6 +39,7 @@ protected:
|
||||
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);
|
||||
[[nodiscard]] bool SizeExceedsMaximum(const Vector2i& size);
|
||||
public:
|
||||
/// @returns A handle used to identify this texture.
|
||||
[[nodiscard]] unsigned int GetHandle() const;
|
||||
@@ -56,6 +56,9 @@ public:
|
||||
/// @returns The raw pixels this texture is made up of.
|
||||
/// @note This will read-back from the GPU. Slow.
|
||||
[[nodiscard]] std::vector<Color4> GetPixelData() const;
|
||||
/// @returns The biggest size for a texture on this system.
|
||||
/// @note on modern systems this is *usually* ridiculous.
|
||||
[[nodiscard]] static Vector2i MaximumSize();
|
||||
public:
|
||||
/// Load a texture from a file,
|
||||
explicit Texture(const std::filesystem::path& file, FilteringMode filtering_mode = FilteringMode::BILINEAR, WrappingMode wrapping_mode = WrappingMode::CLAMP_TO_EDGE, bool invert_y = true);
|
||||
|
@@ -381,3 +381,7 @@ JGL::RenderTarget::RenderTarget(const JGL::RenderTarget& rhs) {
|
||||
|
||||
operator delete(this_render_target);
|
||||
}
|
||||
|
||||
Vector2i JGL::RenderTarget::MaximimSize() {
|
||||
return Texture::MaximumSize();
|
||||
}
|
||||
|
@@ -99,6 +99,8 @@ std::vector<unsigned char> Texture::bmp(const std::filesystem::path& file) {
|
||||
}
|
||||
|
||||
Texture::Texture(const Vector2i& size) : invert_y(true), format(ColorFormat::RGBA), size(size), filtering_mode(FilteringMode::NEAREST), wrapping_mode(WrappingMode::CLAMP_TO_EDGE) {
|
||||
if (SizeExceedsMaximum(size))
|
||||
Logger::Error("Creating a texture where the size is bigger than the maximum for this system.");
|
||||
GLuint previous_texture;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*) &previous_texture);
|
||||
|
||||
@@ -116,6 +118,9 @@ Texture::Texture(const Vector2i& size) : invert_y(true), format(ColorFormat::RGB
|
||||
}
|
||||
|
||||
void Texture::load(const unsigned char* pixels) {
|
||||
if (SizeExceedsMaximum(size))
|
||||
Logger::Error("Creating a texture where the size is bigger than the maximum for this system.");
|
||||
|
||||
GLuint previous_texture;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*) &previous_texture);
|
||||
|
||||
@@ -272,3 +277,16 @@ Texture::Texture(const Texture* textures, const size_t& texture_count) {
|
||||
next_x += textures[i].GetDimensions().x;
|
||||
}
|
||||
}
|
||||
|
||||
bool Texture::SizeExceedsMaximum(const Vector2i& s) {
|
||||
|
||||
auto max_size = Texture::MaximumSize();
|
||||
return s.x > max_size.x || s.y > max_size.y;
|
||||
}
|
||||
|
||||
Vector2i Texture::MaximumSize() {
|
||||
GLint max_size;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
|
||||
|
||||
return { max_size, max_size };
|
||||
}
|
||||
|
Reference in New Issue
Block a user