|
|
@@ -22,6 +22,7 @@
|
|
|
#include "game/graphics/material.hpp"
|
|
|
#include "game/graphics/shader.hpp"
|
|
|
#include "game/graphics/shader_program.hpp"
|
|
|
+#include "game/graphics/texture.hpp"
|
|
|
#include "game/util/env.hpp"
|
|
|
#include "game/util/files.hpp"
|
|
|
#include "game/util/time.hpp"
|
|
|
@@ -66,73 +67,74 @@ namespace {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-namespace graphics { namespace textures {
|
|
|
- unsigned int init(format color_fmt, math::vec2i dimension,
|
|
|
- void const * data) {
|
|
|
- unsigned int id;
|
|
|
- // Enable texturings
|
|
|
- // glEnable( GL_TEXTURE_2D );
|
|
|
-
|
|
|
- // Tell OpenGL that our pixel data is single-byte aligned
|
|
|
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
|
-
|
|
|
- // Ask OpenGL for an unused texName (ID number) to use for this texture
|
|
|
- glGenTextures(1, &id);
|
|
|
-
|
|
|
- // Tell OpenGL to bind (set) this as the currently active texture
|
|
|
- glBindTexture(GL_TEXTURE_2D, id);
|
|
|
- // Set texture clamp vs. wrap (repeat)
|
|
|
-
|
|
|
- // one of: GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT,
|
|
|
- // GL_MIRROR_CLAMP_TO_EDGE, ...
|
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
-
|
|
|
- // the format our source pixel data is currently in; any of: GL_RGB,
|
|
|
- // GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, ...
|
|
|
- int bufferFormat = glfmt(color_fmt);
|
|
|
-
|
|
|
- // the format we want the texture to me on the card; allows us to translate
|
|
|
- // into a different texture format as we upload to OpenGL
|
|
|
- int internalFormat = bufferFormat;
|
|
|
-
|
|
|
- /* glTexImage2D: Load a 2d texture image
|
|
|
- * target: Creating this as a 2d texture.
|
|
|
- * level: Which mipmap level to use as the "root" (0 = the highest-quality,
|
|
|
- * full-res image), if mipmaps are enabled.
|
|
|
- * internalFormat: Type of texel format we want OpenGL to use for this
|
|
|
- * texture internally on the video card.
|
|
|
- * width: Texel-width of image; for maximum compatibility, use 2^N + 2^B,
|
|
|
- * where N is some integer in the range [3,10], and B is the border
|
|
|
- * thickness [0,1]
|
|
|
- * height: Texel-height of image; for maximum compatibility, use 2^M + 2^B,
|
|
|
- * where M is some integer in the range [3,10], and B is the border
|
|
|
- * thickness [0,1]
|
|
|
- * border: Border size, in texels (must be 0 or 1)
|
|
|
- * format: Pixel format describing the composition of the pixel data in
|
|
|
- * buffer
|
|
|
- * type: Pixel color components are unsigned bytes (one byte per color/alpha
|
|
|
- * channel)
|
|
|
- * pixels: Location of the actual pixel data bytes/buffer
|
|
|
- */
|
|
|
- glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimension.x(), dimension.y(),
|
|
|
- 0, bufferFormat, GL_UNSIGNED_BYTE, data);
|
|
|
-
|
|
|
- glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
-
|
|
|
- // Set magnification (texel > pixel) and minification (texel < pixel)
|
|
|
- // filters one of: GL_NEAREST, GL_LINEAR
|
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
- // one of: GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,
|
|
|
- // GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST,
|
|
|
- // GL_LINEAR_MIPMAP_LINEAR
|
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
|
|
- GL_NEAREST_MIPMAP_LINEAR);
|
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5);
|
|
|
-
|
|
|
- return id;
|
|
|
- }
|
|
|
-}}
|
|
|
+texture opengl_manager::compile(textures::format color, math::vec2i size,
|
|
|
+ void const * buffer) const {
|
|
|
+ // textures::external_data data(env::resource_file(path));
|
|
|
+ // unsigned int init(format color_fmt, math::vec2i dimension,
|
|
|
+ // void const * data) {
|
|
|
+ unsigned int id;
|
|
|
+ // Enable texturings
|
|
|
+ // glEnable( GL_TEXTURE_2D );
|
|
|
+
|
|
|
+ // Tell OpenGL that our pixel data is single-byte aligned
|
|
|
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
|
+
|
|
|
+ // Ask OpenGL for an unused texName (ID number) to use for this texture
|
|
|
+ glGenTextures(1, &id);
|
|
|
+
|
|
|
+ // Tell OpenGL to bind (set) this as the currently active texture
|
|
|
+ glBindTexture(GL_TEXTURE_2D, id);
|
|
|
+ // Set texture clamp vs. wrap (repeat)
|
|
|
+
|
|
|
+ // one of: GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT,
|
|
|
+ // GL_MIRROR_CLAMP_TO_EDGE, ...
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
+
|
|
|
+ // the format our source pixel data is currently in; any of: GL_RGB,
|
|
|
+ // GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, ...
|
|
|
+ int bufferFormat = glfmt(color);
|
|
|
+
|
|
|
+ // the format we want the texture to me on the card; allows us to translate
|
|
|
+ // into a different texture format as we upload to OpenGL
|
|
|
+ int internalFormat = bufferFormat;
|
|
|
+
|
|
|
+ /* glTexImage2D: Load a 2d texture image
|
|
|
+ * target: Creating this as a 2d texture.
|
|
|
+ * level: Which mipmap level to use as the "root" (0 = the highest-quality,
|
|
|
+ * full-res image), if mipmaps are enabled.
|
|
|
+ * internalFormat: Type of texel format we want OpenGL to use for this
|
|
|
+ * texture internally on the video card.
|
|
|
+ * width: Texel-width of image; for maximum compatibility, use 2^N + 2^B,
|
|
|
+ * where N is some integer in the range [3,10], and B is the border
|
|
|
+ * thickness [0,1]
|
|
|
+ * height: Texel-height of image; for maximum compatibility, use 2^M + 2^B,
|
|
|
+ * where M is some integer in the range [3,10], and B is the border
|
|
|
+ * thickness [0,1]
|
|
|
+ * border: Border size, in texels (must be 0 or 1)
|
|
|
+ * format: Pixel format describing the composition of the pixel data in
|
|
|
+ * buffer
|
|
|
+ * type: Pixel color components are unsigned bytes (one byte per color/alpha
|
|
|
+ * channel)
|
|
|
+ * pixels: Location of the actual pixel data bytes/buffer
|
|
|
+ */
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size.x(), size.y(), 0,
|
|
|
+ bufferFormat, GL_UNSIGNED_BYTE, buffer);
|
|
|
+
|
|
|
+ glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
+
|
|
|
+ // Set magnification (texel > pixel) and minification (texel < pixel)
|
|
|
+ // filters one of: GL_NEAREST, GL_LINEAR
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
+ // one of: GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,
|
|
|
+ // GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST,
|
|
|
+ // GL_LINEAR_MIPMAP_LINEAR
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
|
|
+ GL_NEAREST_MIPMAP_LINEAR);
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5);
|
|
|
+
|
|
|
+ return texture{id, size};
|
|
|
+}
|
|
|
|
|
|
shader opengl_manager::compile(shaders::type tp,
|
|
|
std::string const & path) const {
|