Files
video-shader-toys/src/render/runtime/RuntimeTextTextureCache.h
2026-05-22 17:27:29 +10:00

47 lines
1.3 KiB
C++

#pragma once
#include "GLExtensions.h"
#include "RuntimeShaderArtifact.h"
#include <map>
#include <memory>
#include <string>
#include <vector>
class RuntimeTextTextureCache
{
public:
RuntimeTextTextureCache() = default;
RuntimeTextTextureCache(const RuntimeTextTextureCache&) = delete;
RuntimeTextTextureCache& operator=(const RuntimeTextTextureCache&) = delete;
~RuntimeTextTextureCache();
bool Configure(const RuntimeShaderArtifact& artifact, std::string& error);
void UpdateArtifactState(const RuntimeShaderArtifact& artifact);
void RefreshTextTextures(RuntimeShaderArtifact* artifactState = nullptr);
void BindTextTextures(GLuint program);
void ShutdownGl();
static void AssignSamplerUniforms(GLuint program, const RuntimeShaderArtifact& artifact);
private:
struct TextTexture
{
std::string parameterId;
std::string cachedText;
std::shared_ptr<const std::vector<unsigned char>> cachedPixels;
GLuint texture = 0;
unsigned width = 0;
unsigned height = 0;
unsigned liveWidth = 1;
unsigned maxLength = 64;
};
bool EnsureTextTexture(TextTexture& texture);
const RuntimePreparedTextTexture* FindPreparedTexture(const std::string& parameterId) const;
static void DestroyTexture(TextTexture& texture);
RuntimeShaderArtifact mArtifact;
std::vector<TextTexture> mTextTextures;
};