12#ifndef FOOLSENGINE_TEXTURE_H
13#define FOOLSENGINE_TEXTURE_H
19#include <nlohmann/json.hpp>
128 const std::string& filepath=
""
152 void bind(GLuint textureUnit)
const;
199 void copyImage(
const Texture& other);
278 inline static std::string getResourceConstructorName() {
return "fromFile"; }
280 std::shared_ptr<IResource>
createResource(
const nlohmann::json& methodParameters)
override;
313 class TextureFromColorBufferDefinition:
public ResourceConstructor<Texture, TextureFromColorBufferDefinition> {
316 inline static std::string getResourceConstructorName() {
return "fromDescription"; }
318 std::shared_ptr<IResource>
createResource(
const nlohmann::json& methodParameters)
override;
332 GLenum internalFormat;
335 internalFormat = GL_R16F;
337 internalFormat = GL_RGBA16F;
339 internalFormat = GL_RED;
343 internalFormat = GL_SRGB_ALPHA;
345 internalFormat = GL_RGBA;
349 throw std::invalid_argument(
"Invalid data type and component count combination provided in texture constructor");
352 return internalFormat;
366 GLenum externalFormat;
369 externalFormat = GL_RED;
371 externalFormat = GL_RGBA;
373 externalFormat = GL_RED;
375 externalFormat = GL_RGBA;
377 throw std::invalid_argument(
"Invalid data type and component count combination provided in texture constructor");
380 return externalFormat;
385 void to_json(nlohmann::json& json,
const ColorBufferDefinition& colorBufferDefinition);
388 void from_json(
const nlohmann::json& json, ColorBufferDefinition& colorBufferDefinition);
390 {ColorBufferDefinition::CubemapLayout::NA,
"na"},
391 {ColorBufferDefinition::CubemapLayout::ROW,
"row"},
ResourceConstructor(int explicitlyInitializeMe)
Definition resource_database.hpp:491
Resource(int explicitlyInitializeMe)
Definition resource_database.hpp:389
std::shared_ptr< IResource > createResource(const nlohmann::json &methodParameters) override
Creates a resource object using the parameters specified in methodParameters.
Definition texture.cpp:268
std::shared_ptr< IResource > createResource(const nlohmann::json &methodParameters) override
Creates a resource object using the parameters specified in methodParameters.
Definition texture.cpp:213
The class representation of textures on this engine, which are a type of Resource used both within an...
Definition texture.hpp:116
void attachToFramebuffer(GLuint attachmentUnit) const
Attaches this texture to a (presumably existing and bound) framebuffer, allowing the user of the fram...
Definition texture.cpp:176
void generateTexture()
Generates a new texture based on the stored color buffer definition.
Definition texture.cpp:186
static std::string getResourceTypeName()
Gets the resource type string associated with this resource.
Definition texture.hpp:189
void destroyResource()
Destroys (OpenGL managed) texture tied to this object.
Definition texture.cpp:161
GLuint mID
The OpenGL ID of this texture.
Definition texture.hpp:206
GLenum internalFormat()
The enum value passed as the "internalFormat" argument of glTexImage2D.
Definition texture.cpp:205
GLuint getTextureID() const
Gets the OpenGL texture ID for this texture.
Definition texture.cpp:101
GLint getHeight() const
Gets the height of this texture (per its color buffer definition).
Definition texture.cpp:108
GLenum externalFormat()
The enum value passed as the "format" argument of glTexImage2D.
Definition texture.cpp:209
Texture(GLuint textureID, const ColorBufferDefinition &colorBufferDefinition, const std::string &filepath="")
Constructs a new texture object which takes ownership of an OpenGL texture handle and engine colorbuf...
Definition texture.cpp:40
void releaseResource()
Removes references to (OpenGL managed) texture tied to this object, so that another object or part of...
Definition texture.cpp:165
std::string mFilepath
The file this texture was loaded from, if any.
Definition texture.hpp:212
ColorBufferDefinition getColorBufferDefinition()
Gets the description of this texture.
Definition texture.hpp:196
GLint getWidth() const
Gets the width of this texture (per its color buffer definition).
Definition texture.cpp:103
ColorBufferDefinition mColorBufferDefinition
The color buffer definition of this texture.
Definition texture.hpp:218
void bind(GLuint textureUnit) const
Binds this texture to a texture unit, making it available for use by a shader.
Definition texture.cpp:170
GLenum deduceExternalFormat(const ColorBufferDefinition &colorBufferDefinition)
A (quite possibly unnecessary) function to fetch the enum corresponding to the "format" argument of g...
Definition texture.hpp:365
GLenum deduceInternalFormat(const ColorBufferDefinition &colorBufferDefinition)
A (quite possibly unnecessary) function to fetch the enum corresponding to the "internalFormat" argum...
Definition texture.hpp:331
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
Headers relating to resources and their management for a given project.
A struct containing the definition of a color buffer, using which similar color buffers can be create...
Definition texture.hpp:30
GLenum mMagFilter
The type of sampling used with the texture when it is zoomed in to.
Definition texture.hpp:68
GLenum mWrapS
Horizontally: for UV coordinates beyond the 0.0-1.0 range, which part of the texture is to be sampled...
Definition texture.hpp:80
GLenum mDataType
The underlying data type representing each channel (also component) of the texture.
Definition texture.hpp:92
CubemapLayout mCubemapLayout
The type of cubemap layout the texture conforms to, if it is a cubemap.
Definition texture.hpp:62
glm::vec2 mDimensions
The dimensions of the 2D texture.
Definition texture.hpp:56
GLbyte mComponentCount
The number of components (or channels) each pixel of the texture contains.
Definition texture.hpp:98
bool mUsesWebColors
Whether the intensity of the color of a component maps linearly or exponentially with the value of th...
Definition texture.hpp:108
GLenum mMinFilter
The type of sampling used with the texture when it is zoomed out from.
Definition texture.hpp:74
Type
The type of texture defined.
Definition texture.hpp:35
CubemapLayout
For a 2D texture - determines the manner in which the Texture should be sampled in order for it to be...
Definition texture.hpp:44
GLenum mWrapT
Vertically: for UV coordinates beyond the 0.0-1.0 range, which part of the texture is to be sampled f...
Definition texture.hpp:86