16#include "ResourcePool.h"
17#include <AUI/GL/State.h>
20template<
unsigned int TEXTURE_TARGET>
21gl::Texture<TEXTURE_TARGET>::Texture() {
22 mTexture = gl::ResourcePool<gl::ResourceKind::TEXTURE>::get();
23 gl::State::bindTexture(TEXTURE_TARGET, mTexture);
25 setupMirroredRepeat();
28template<
unsigned int TEXTURE_TARGET>
29gl::Texture<TEXTURE_TARGET>::~Texture() {
30 gl::ResourcePool<gl::ResourceKind::TEXTURE>::put(mTexture);
31 gl::State::bindTexture(TEXTURE_TARGET, 0);
34template<
unsigned int TEXTURE_TARGET>
35void gl::Texture<TEXTURE_TARGET>::setupNearest() {
36 if (mFiltering == Filtering::NEAREST) {
40 mFiltering = Filtering::NEAREST;
41 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
42 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
44template<
unsigned int TEXTURE_TARGET>
45void gl::Texture<TEXTURE_TARGET>::setupLinear() {
46 if (mFiltering == Filtering::LINEAR) {
50 mFiltering = Filtering::LINEAR;
51 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
52 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
55template<
unsigned int TEXTURE_TARGET>
56void gl::Texture<TEXTURE_TARGET>::setupRepeat() {
57 if (mWrapping == Wrapping::REPEAT) {
61 mWrapping = Wrapping::REPEAT;
62 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_S, GL_REPEAT);
63 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_T, GL_REPEAT);
66template<
unsigned int TEXTURE_TARGET>
67void gl::Texture<TEXTURE_TARGET>::setupMirroredRepeat() {
68 if (mWrapping == Wrapping::MIRRORED_REPEAT) {
72 mWrapping = Wrapping::MIRRORED_REPEAT;
73 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
74 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
77template<
unsigned int TEXTURE_TARGET>
78void gl::Texture<TEXTURE_TARGET>::setupClampToEdge() {
79 if (mWrapping == Wrapping::CLAMP_TO_EDGE) {
83 mWrapping = Wrapping::CLAMP_TO_EDGE;
84 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
85 glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
88template<
unsigned int TEXTURE_TARGET>
89void gl::Texture<TEXTURE_TARGET>::bind(uint8_t index) {
90 AUI_ASSERTX(getHandle() != 0,
"gl::Texture::bind: mTexture == 0");
91 gl::State::activeTexture(index);
92 gl::State::bindTexture(TEXTURE_TARGET, mTexture);
95template<
unsigned int TEXTURE_TARGET>
96void gl::Texture<TEXTURE_TARGET>::unbind(uint8_t index) {
97 gl::State::activeTexture(index);
98 gl::State::bindTexture(TEXTURE_TARGET, 0);
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition Assert.h:74