Upd8
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m29s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m29s
This commit is contained in:
@@ -1,36 +1,52 @@
|
||||
#include <JGL/Texture.h>
|
||||
#include <iostream>
|
||||
|
||||
JGL::Texture::Texture(const std::string& file, const ReTexture::TextureFlag& flags, TextureFilteringMode filtering_mode) {
|
||||
auto* t = new ReTexture::Texture(file, flags);
|
||||
using namespace ReTexture;
|
||||
|
||||
load(t, {(float) t->getWidth(), (float) t->getHeight()}, t->getTextureFormat(), filtering_mode);
|
||||
JGL::Texture::Texture(const std::string& file, const TextureFlag& flags, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
||||
auto* t = new SoftwareTexture(file, flags);
|
||||
|
||||
load(t, {(float) t->getWidth(), (float) t->getHeight()}, t->getTextureFormat(), filtering_mode, wrapping_mode);
|
||||
texture_flags = flags;
|
||||
|
||||
delete t;
|
||||
}
|
||||
|
||||
JGL::Texture::Texture(const std::string& file, TextureFilteringMode filtering_mode) {
|
||||
auto* t = new ReTexture::Texture(file);
|
||||
JGL::Texture::Texture(const std::string& file, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
||||
auto* t = new SoftwareTexture(file);
|
||||
|
||||
load(t, {(float) t->getWidth(), (float) t->getHeight()}, t->getTextureFormat(), filtering_mode);
|
||||
texture_flags = ReTexture::TextureFlag::NONE;
|
||||
load(t, {(float) t->getWidth(), (float) t->getHeight()}, t->getTextureFormat(), filtering_mode, wrapping_mode);
|
||||
texture_flags = TextureFlag::NONE;
|
||||
|
||||
delete t;
|
||||
}
|
||||
|
||||
void JGL::Texture::load(ReTexture::Texture* software_texture, const Vector2& size, const ReTexture::TextureFormat& format, TextureFilteringMode filtering_mode) {
|
||||
void JGL::Texture::load(SoftwareTexture* software_texture, const Vector2& size, const TextureFormat& format, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
if (format == ReTexture::TextureFormat::RGBA)
|
||||
if (format == TextureFormat::RGBA)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (int) size.x, (int) size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, software_texture->pixelData.data());
|
||||
|
||||
else if (format == ReTexture::TextureFormat::RGB)
|
||||
else if (format == TextureFormat::RGB)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, (int) size.x, (int) size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, software_texture->pixelData.data());
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
if (wrapping_mode == TextureWrappingMode::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);
|
||||
|
||||
else if (wrapping_mode == TextureWrappingMode::REPEAT)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
else if (wrapping_mode == TextureWrappingMode::MIRRORED_REPEAT)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
|
||||
else if (wrapping_mode == TextureWrappingMode::CLAMP_TO_BORDER)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
|
||||
|
||||
if (filtering_mode == TextureFilteringMode::NEAREST)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST),
|
||||
@@ -42,20 +58,20 @@ void JGL::Texture::load(ReTexture::Texture* software_texture, const Vector2& siz
|
||||
|
||||
else if (filtering_mode == TextureFilteringMode::MIPMAP_NEAREST || filtering_mode == TextureFilteringMode::MIPMAP_BILINEAR || filtering_mode == TextureFilteringMode::MIPMAP_TRILINEAR) {
|
||||
//3 mipmap levels.
|
||||
auto* m1 = new ReTexture::Texture(software_texture->downscale(2));
|
||||
auto* m2 = new ReTexture::Texture(software_texture->downscale(4));
|
||||
auto* m3 = new ReTexture::Texture(software_texture->downscale(8));
|
||||
auto* m1 = new SoftwareTexture(software_texture->downscale(2));
|
||||
auto* m2 = new SoftwareTexture(software_texture->downscale(4));
|
||||
auto* m3 = new SoftwareTexture(software_texture->downscale(8));
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
|
||||
|
||||
if (format == ReTexture::TextureFormat::RGBA) {
|
||||
if (format == TextureFormat::RGBA) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, m1->getWidth(), m1->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m1->pixelData.data());
|
||||
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, m2->getWidth(), m2->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m2->pixelData.data());
|
||||
glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA, m3->getWidth(), m3->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m3->pixelData.data());
|
||||
}
|
||||
|
||||
if (format == ReTexture::TextureFormat::RGB) {
|
||||
else if (format == TextureFormat::RGB) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, m1->getWidth(), m1->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, m1->pixelData.data());
|
||||
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, m2->getWidth(), m2->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, m2->pixelData.data());
|
||||
glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB, m3->getWidth(), m3->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, m3->pixelData.data());
|
||||
@@ -88,14 +104,14 @@ std::vector<JGL::Color4> JGL::Texture::getPixelData() {
|
||||
std::vector<JGL::Color4> result((size_t) (texture_size.x * texture_size.y));
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
if (texture_format == ReTexture::TextureFormat::RGBA) {
|
||||
if (texture_format == TextureFormat::RGBA) {
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, result.data());
|
||||
return result;
|
||||
}
|
||||
|
||||
//if RGB
|
||||
std::vector<JGL::Color3> color3((size_t) (texture_size.x * texture_size.y));
|
||||
if (texture_format == ReTexture::TextureFormat::RGB)
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, color3.data());
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, color3.data());
|
||||
|
||||
for (const auto& c : color3)
|
||||
result.emplace_back(c);
|
||||
@@ -116,14 +132,14 @@ Vector2 JGL::Texture::getSize() {
|
||||
return texture_size;
|
||||
}
|
||||
|
||||
ReTexture::TextureFlag JGL::Texture::getFlags() {
|
||||
TextureFlag JGL::Texture::getFlags() {
|
||||
return texture_flags;
|
||||
}
|
||||
|
||||
ReTexture::TextureFormat JGL::Texture::getFormat() {
|
||||
TextureFormat JGL::Texture::getFormat() {
|
||||
return texture_format;
|
||||
}
|
||||
|
||||
JGL::TextureFilteringMode JGL::Texture::getTextureFilteringMode() {
|
||||
JGL::TextureFilteringMode JGL::Texture::getFilteringMode() {
|
||||
return texture_filtering_mode;
|
||||
}
|
||||
|
Reference in New Issue
Block a user