X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=shared%2Fref_counted_texture.cpp;fp=shared%2Fref_counted_texture.cpp;h=d10b0dc7737d8046547e2d1ea540eacdd4879d6c;hp=0000000000000000000000000000000000000000;hb=adc0df09f7a9dc88a3c0dbad47a21a805e728862;hpb=02ea864dc5a6dde7450c497581ff18d784ab832c diff --git a/shared/ref_counted_texture.cpp b/shared/ref_counted_texture.cpp new file mode 100644 index 0000000..d10b0dc --- /dev/null +++ b/shared/ref_counted_texture.cpp @@ -0,0 +1,25 @@ +#include "ref_counted_texture.h" + +#include +#include + +RefCountedTexture create_texture_2d(GLuint width, GLuint height, GLenum internal_format, GLenum format, GLenum type, const GLvoid *pixels) +{ + GLuint tex; + glCreateTextures(GL_TEXTURE_2D, 1, &tex); + check_error(); + glTextureStorage2D(tex, 1, internal_format, width, height); + check_error(); + glTextureSubImage2D(tex, 0, 0, 0, width, height, format, type, pixels); + check_error(); + glTextureParameteri(tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + check_error(); + glTextureParameteri(tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + check_error(); + glTextureParameteri(tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + check_error(); + glTextureParameteri(tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + check_error(); + + return RefCountedTexture(new GLuint(tex), TextureDeleter()); +}