35#include "GLESShader.h"
36#include "GLESGraphicsDevice.h"
37#include <NDEVR/ImageFactory.h>
38#include <NDEVR/Image.h>
39#include <NDEVR/Pointer.h>
40#include <NDEVR/File.h>
41#include <NDEVR/RGBColor.h>
42#include <NDEVR/Dictionary.h>
43#include <NDEVR/Buffer.h>
45typedef uint32_t VkImageUsageFlags;
46typedef uint32_t VkMemoryPropertyFlags;
73 instance->glDeleteTextures(1, &m_gles_image);
74 m_gles_image = Constant<uint04>::Invalid;
82 lib_assert(has_image,
"Invalid GLES image");
85 instance->glGenTextures(1, &m_gles_image);
86 instance->glBindTexture(GL_TEXTURE_2D, m_gles_image);
88 instance->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
89 instance->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
90 instance->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
91 instance->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
98 lib_assert(!img.isNull(),
"Bad image");
102 uint04 max_size = m_size.dimensionalValue<MAX>();
104 m_modified_time = img->modified_time;
105 if (max_size >
cast<uint04>(instance->capabilities().max_texture_size))
107 max_size =
cast<uint04>(instance->capabilities().max_texture_size);
111 instance->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, new_size[X], new_size[Y], 0, GL_RGBA, GL_UNSIGNED_BYTE, resized.begin());
115 instance->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size[X], m_size[Y], 0, GL_RGBA, GL_UNSIGNED_BYTE, img->decompressed_data.begin());
119 instance->glGenerateMipmap(GL_TEXTURE_2D);
120 instance->glBindTexture(GL_TEXTURE_2D, 0);
127 instance->glActiveTexture(GL_TEXTURE0 + bind_position);
128 instance->glBindTexture(GL_TEXTURE_2D, m_gles_image);
145 GLuint m_gles_image = Constant<uint04>::Invalid;
147 bool m_has_alpha =
false;
173 bool updated =
false;
176 if (iter.second->needsUpdate())
190 if (iter.second->needsUpdate())
204 if (image->size().magnitudeSquared() > 0 &&
IsValid(image->size()))
The equivelent of std::vector but with a bit more control.
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
A hash-based key-value store, useful for quick associative lookups.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
A pointer to an Image and functions relating to that image within the GLES logic space.
void update(const DynamicPointer< GLESGraphicsDevice > &instance)
Reloads and re-uploads the image texture to GPU.
void destroy(const DynamicPointer< GLESGraphicsDevice > &instance)
Deletes the GPU texture resource.
bool needsUpdate() const
Checks whether the source image has been modified since last upload.
bool hasAlpha() const
Checks whether the image has an alpha channel.
GLESImageData(const DynamicPointer< GLESGraphicsDevice > &device, const StringView &image_id)
Constructs a GLESImageData and uploads the image to GPU.
void setUniformVariables(uint04 bind_position, const DynamicPointer< GLESGraphicsDevice > &instance) const
Binds this texture to the given texture unit for shader use.
bool needsImageUpdate() const
Checks whether any managed image needs re-uploading.
Dictionary< String, DynamicPointer< GLESImageData > > m_file_map
Map of image IDs to GPU image data.
ConstPointer< GLESImageData > getImage(const StringView &id)
Retrieves or creates a GPU-backed image by identifier.
bool updateImages()
Re-uploads any images whose source data has changed.
GLESImageManager(const DynamicPointer< GLESGraphicsDevice > &instance)
Constructs a GLESImageManager for the given device.
~GLESImageManager()
Destroys all managed GPU textures.
DynamicPointer< GLESGraphicsDevice > m_device
The OpenGL graphics device.
The core class for reading/writing and storing images in an optimized way.
ImageReadPointer getUncompressed(const StringView &id, bool ensure_valid_transparancy=false)
Retrieves the uncompressed (raw ARGB) pixel data for the cached image.
bool hasImage(const StringView &id) const
Checks whether an image with the given identifier exists in the cache.
static void Resize(const Buffer< uint01 > &input, const Vector< 2, uint04 > &in_size, const Vector< 2, uint04 > &out_size, Buffer< uint01 > &output)
Resizes raw pixel data from one resolution to another using bilinear or nearest-neighbor sampling.
Time modifiedTime(const StringView &id) const
Returns the last modification time of the cached image.
static ImageFactory & DefaultFactory()
Returns the singleton default ImageFactory instance.
A root class that stores an an array of pixel data that can be displayed as an Image.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
Represents a timestamp with utilities for manipulation and conversion.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
A GPU buffer managed through the Vulkan API, used for vertex, index, and uniform data.
The connection between the NDEVR API and the Vulkan library.
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
A read-only smart pointer to ImageCacheData that acquires a read lock on construction.