IMAGE: added support for writing images
parent
50eb7aa7e7
commit
8c9325963b
|
@ -230,7 +230,7 @@ void Client::destroyMeshData(const video::GLMeshData& meshData) {
|
|||
_world->allowReExtraction(meshData.translation);
|
||||
glDeleteBuffers(1, &meshData.vertexBuffer);
|
||||
glDeleteBuffers(1, &meshData.indexBuffer);
|
||||
glDeleteVertexArrays(1, meshData.vertexArrayObject);
|
||||
glDeleteVertexArrays(1, &meshData.vertexArrayObject);
|
||||
}
|
||||
|
||||
bool Client::isCulled(const glm::ivec2& pos) const {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#include "AbstractTest.h"
|
||||
#include "core/Log.h"
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
void AbstractTest::SetUp() {
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
#include "core/EventBus.h"
|
||||
#include "io/Filesystem.h"
|
||||
|
||||
#include "stb_image_write.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
class AbstractTest: public testing::Test {
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
#include "core/App.h"
|
||||
#include "io/Filesystem.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
#include "stb_image.h"
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
|
||||
namespace video {
|
||||
namespace image {
|
||||
|
||||
Image::Image(const std::string& name) :
|
||||
io::IOResource(), _name(name), _width(-1), _height(-1), _depth(-1), _data(nullptr) {
|
||||
|
@ -39,4 +41,15 @@ void Image::load(uint8_t* buffer, int length) {
|
|||
_state = io::IOSTATE_LOADED;
|
||||
}
|
||||
|
||||
bool Image::writePng(const char *name, const uint8_t* buffer, int width, int height, int depth) {
|
||||
return stbi_write_png(name, width, height, depth, (const void*)buffer, width * depth) != 0;
|
||||
}
|
||||
|
||||
bool Image::writePng() const {
|
||||
if (_state != io::IOSTATE_LOADED) {
|
||||
return false;
|
||||
}
|
||||
return stbi_write_png(_name.c_str(), _width, _height, _depth, (const void*)_data, _width * _depth) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "core/App.h"
|
||||
#include <memory>
|
||||
|
||||
namespace video {
|
||||
namespace image {
|
||||
|
||||
class Image: public io::IOResource {
|
||||
private:
|
||||
|
@ -22,6 +22,9 @@ public:
|
|||
void load(const io::FilePtr& file);
|
||||
void load(uint8_t* buffer, int length);
|
||||
|
||||
static bool writePng(const char *name, const uint8_t *buffer, int width, int height, int depth);
|
||||
bool writePng() const;
|
||||
|
||||
const std::string& name() const {
|
||||
return _name;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -6,4 +6,4 @@ fips_begin_module(noise)
|
|||
fips_end_module()
|
||||
|
||||
gtest_suite_files(tests tests/SimplexNoiseTest.cpp)
|
||||
gtest_suite_deps(tests core noise)
|
||||
gtest_suite_deps(tests core image noise)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "core/tests/AbstractTest.h"
|
||||
#include "noise/SimplexNoise.h"
|
||||
#include "image/Image.h"
|
||||
#include <glm/gtc/noise.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
|
||||
|
@ -12,7 +13,7 @@ protected:
|
|||
const int h = 256;
|
||||
|
||||
bool WriteImage(const char* name, uint8_t* buffer) {
|
||||
return stbi_write_png(name, w, h, components, buffer, w * components) != 0;
|
||||
return image::Image::writePng(name, buffer, w, h, components);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -80,7 +81,7 @@ TEST_F(SimplexNoiseTest, test2DNoiseGray) {
|
|||
const int components = 3;
|
||||
uint8_t buffer[width * height * components];
|
||||
Simplex::Noise2DGray(buffer, width, height, 1, 1.0, 1.0, 1.0);
|
||||
ASSERT_TRUE(stbi_write_png("testNoiseGray.png", width, height, components, buffer, width * components) != 0);
|
||||
ASSERT_TRUE(image::Image::writePng("testNoiseGray.png", buffer, width, height, components));
|
||||
}
|
||||
|
||||
TEST_F(SimplexNoiseTest, test2DNoiseColorMap) {
|
||||
|
@ -89,7 +90,7 @@ TEST_F(SimplexNoiseTest, test2DNoiseColorMap) {
|
|||
const int components = 3;
|
||||
uint8_t buffer[width * height * components];
|
||||
noise::Simplex::SeamlessNoise2DRGB(buffer, width, 3, 0.3f, 0.7f);
|
||||
ASSERT_TRUE(stbi_write_png("testNoiseColorMap.png", width, height, components, buffer, width * components) != 0);
|
||||
ASSERT_TRUE(image::Image::writePng("testNoiseColorMap.png", buffer, width, height, components));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ bool Cubemap::load() {
|
|||
|
||||
for (unsigned int i = 1; i <= 6; i++) {
|
||||
const std::string& filename = core::string::format("%s-cm-%i", _filename.c_str(), i);
|
||||
const ImagePtr& img = loadImage(filename);
|
||||
const image::ImagePtr& img = image::loadImage(filename);
|
||||
const GLenum mode = img->depth() == 4 ? GL_RGBA : GL_RGB;
|
||||
glTexImage2D(types[i - 1], 0, mode, img->width(), img->height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img->data());
|
||||
}
|
||||
|
|
|
@ -94,14 +94,14 @@ bool Mesh::initMesh(const ShaderPtr& shader) {
|
|||
if (_state != io::IOSTATE_LOADING) {
|
||||
return false;
|
||||
}
|
||||
for (const ImagePtr& i : _images) {
|
||||
for (const image::ImagePtr& i : _images) {
|
||||
if (!i->isLoaded())
|
||||
return false;
|
||||
}
|
||||
|
||||
_textures.reserve(_images.size());
|
||||
int materialIndex = 0;
|
||||
for (const ImagePtr& i : _images) {
|
||||
for (const image::ImagePtr& i : _images) {
|
||||
_textures[materialIndex++] = createTextureFromImage(i);
|
||||
}
|
||||
_images.clear();
|
||||
|
@ -173,7 +173,7 @@ void Mesh::loadTextureImages(const aiScene* scene, const std::string& filename)
|
|||
}
|
||||
|
||||
const std::string fullPath = dir + "/" + p;
|
||||
_images[i] = createImage(fullPath);
|
||||
_images[i] = image::createImage(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ private:
|
|||
GLuint _indexBuffer;
|
||||
|
||||
std::vector<GLMeshData> _meshData;
|
||||
std::vector<ImagePtr> _images;
|
||||
std::vector<image::ImagePtr> _images;
|
||||
std::vector<TexturePtr> _textures;
|
||||
|
||||
Vertices _positions;
|
||||
|
|
|
@ -33,7 +33,7 @@ inline TexturePtr createTexture(const std::string& name) {
|
|||
return TexturePtr(new Texture(name));
|
||||
}
|
||||
|
||||
inline TexturePtr createTextureFromImage(const ImagePtr& image) {
|
||||
inline TexturePtr createTextureFromImage(const image::ImagePtr& image) {
|
||||
if (!image) {
|
||||
return TexturePtr();
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ inline TexturePtr createTextureFromImage(const ImagePtr& image) {
|
|||
}
|
||||
|
||||
inline TexturePtr createTextureFromImage(const std::string& filename) {
|
||||
return createTextureFromImage(createImage(filename));
|
||||
return createTextureFromImage(image::createImage(filename));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue