Index

zydeco / a4d3636

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
916 Nov 2023 11:11a4d3636Fractal ViewerJosh Stockin1530G

Blob @ zydeco / src / render / gl / GLTexture.cpp

text/plain1492 bytesdownload raw
1#include "GLTexture.hpp"
2#include "ZydecoCommon.hpp"
3
4
5static Logger LOGGER("GLTexture");
6
7
8// static initialize
9std::map<std::string, GLTexture*> GLTexture::s_textures = {};
10
11
12GLTexture& GLTexture::GetGLTexture(std::string name)
13{
14 if (s_textures.contains(name)) { return *s_textures.at(name); }
15
16 ZydecoFault("GetGLTexture({}): Texture not found", name);
17}
18
19GLTexture::GLTexture(std::string texture_name, void *data_source, uint32_t width, uint32_t height):
20 m_pDataSource(data_source),
21 m_name(texture_name),
22 m_width(width),
23 m_height(height)
24{
25 s_textures.insert({m_name, this});
26
27 glGenTextures(1, &m_glTextureID);
28 Regenerate(width, height);
29}
30
31GLTexture::~GLTexture()
32{
33 s_textures.erase(m_name);
34 glDeleteTextures(1, &m_glTextureID);
35}
36
37void GLTexture::Regenerate(int width, int height)
38{
39 glBindTexture(GL_TEXTURE_2D, m_glTextureID);
40 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
41 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
43 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
44 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, m_pDataSource);
45 glFlush();
46}
47
48void GLTexture::Bind(uint64_t texture_unit)
49{
50 glActiveTexture(GL_TEXTURE0 + texture_unit);
51 //glBindTextureUnit(texture_unit, m_glTextureID);
52 glBindTexture(GL_TEXTURE_2D, m_glTextureID);
53}
54