PeriDyno 1.0.0
Loading...
Searching...
No Matches
Texture.cpp
Go to the documentation of this file.
1#include "Texture.h"
2#include <glad/glad.h>
3#include <iostream>
4
5namespace dyno
6{
8 {
9 // default value...
10 this->format = GL_RGBA;
11 this->internalFormat = GL_RGBA32F;
12 this->type = GL_FLOAT;
13 }
14
16 {
17 if (target == -1) {
18 std::cerr << "Failed to create texture, wrong target id: " << target << std::endl;
19 return;
20 }
21 glGenTextures(1, &id);
23 }
24
26 {
27 glDeleteTextures(1, &id);
28 // reset object id
29 id = GL_INVALID_INDEX;
30 }
31
33 {
34 glBindTexture(target, id);
35 }
36
37 void Texture::bind(int slot)
38 {
39 glActiveTexture(slot);
40 glBindTexture(target, id);
42 }
43
45 {
46 glBindTexture(target, 0);
48 }
49
50 void Texture::clear(void* value)
51 {
52 glClearTexImage(id, 0, format, type, value);
54 }
55
57 {
58 this->target = GL_TEXTURE_2D;
59 this->minFilter = GL_LINEAR; //GL_LINEAR_MIPMAP_LINEAR
60 this->maxFilter = GL_LINEAR;
61 }
62
64 {
66
67 glBindTexture(target, id);
68 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter);
69 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, maxFilter);
71 }
72
73 void Texture2D::dump(void* pixels)
74 {
75 glBindTexture(target, id);
76 glPixelStorei(GL_PACK_ALIGNMENT, 1);
77 glGetTexImage(target, 0, internalFormat, type, pixels);
79 }
80
81 void Texture2D::resize(int w, int h)
82 {
83 glBindTexture(target, id);
84 glTexImage2D(target, 0, internalFormat, w, h, 0, format, type, 0);
86 }
87
88
89 void Texture2D::load(int w, int h, void* data)
90 {
91 glBindTexture(target, id);
92 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
93 glTexImage2D(target, 0, internalFormat, w, h, 0, format, type, data);
95 }
96
98 {
99 glBindTexture(target, id);
100 glGenerateMipmap(target);
101 glCheckError();
102 }
103
105 {
106 this->target = GL_TEXTURE_2D_MULTISAMPLE;
107 }
108
109 void Texture2DMultiSample::resize(int w, int h, unsigned int nSamples)
110 {
111 this->samples = nSamples;
112
113 glBindTexture(target, id);
114 glTexImage2DMultisample(target, samples, internalFormat, w, h, GL_TRUE);
115 glCheckError();
116 }
117
119 {
120 this->target = GL_TEXTURE_CUBE_MAP;
121 }
122
123}
124
#define glCheckError()
virtual void create() override
Definition Texture.cpp:63
virtual void resize(int w, int h)
Definition Texture.cpp:81
virtual void dump(void *pixels)
Definition Texture.cpp:73
void genMipmap()
Definition Texture.cpp:97
unsigned int maxFilter
Definition Texture.h:62
unsigned int minFilter
Definition Texture.h:61
virtual void load(int w, int h, void *data)
Definition Texture.cpp:89
virtual void resize(int w, int h, unsigned int nSamples)
Definition Texture.cpp:109
virtual void create() override
Definition Texture.cpp:15
unsigned int internalFormat
Definition Texture.h:40
unsigned int target
Definition Texture.h:38
virtual void release() override
Definition Texture.cpp:25
virtual void clear(void *value)
Definition Texture.cpp:50
unsigned int format
Definition Texture.h:41
virtual void bind()
Definition Texture.cpp:32
unsigned int type
Definition Texture.h:42
virtual void unbind()
Definition Texture.cpp:44
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25