diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt index 60e015befb..63b11c2c81 100644 --- a/src/libprojectM/CMakeLists.txt +++ b/src/libprojectM/CMakeLists.txt @@ -36,7 +36,7 @@ target_link_libraries(projectM_main MilkdropPreset Renderer hlslparser - SOIL2 + stb_image libprojectM::API ${PROJECTM_FILESYSTEM_LIBRARY} ) @@ -67,7 +67,7 @@ add_library(projectM $ $ $ - $ + $ $ $ ) diff --git a/src/libprojectM/Renderer/CMakeLists.txt b/src/libprojectM/Renderer/CMakeLists.txt index 15e75b3b04..db89393c7e 100644 --- a/src/libprojectM/Renderer/CMakeLists.txt +++ b/src/libprojectM/Renderer/CMakeLists.txt @@ -75,7 +75,8 @@ target_link_libraries(Renderer PUBLIC GLM::GLM hlslparser - SOIL2 + stb_image + ${PROJECTM_OPENGL_LIBRARIES} ) set_target_properties(Renderer PROPERTIES diff --git a/src/libprojectM/Renderer/MilkdropNoise.cpp b/src/libprojectM/Renderer/MilkdropNoise.cpp index f76d042297..20d5f0bd62 100644 --- a/src/libprojectM/Renderer/MilkdropNoise.cpp +++ b/src/libprojectM/Renderer/MilkdropNoise.cpp @@ -1,8 +1,10 @@ #include "Renderer/MilkdropNoise.hpp" #include "Renderer/OpenGL.h" +#include "Renderer/Texture.hpp" #include +#include #include namespace libprojectM { @@ -10,89 +12,32 @@ namespace Renderer { auto MilkdropNoise::LowQuality() -> std::shared_ptr { - GLuint texture{}; - { - auto textureData = generate2D(256, 1); - - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data()); - } - return std::make_shared("noise_lq", texture, GL_TEXTURE_2D, 256, 256, false); + return std::make_shared("noise_lq", generate2D(256, 1).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false); } auto MilkdropNoise::LowQualityLite() -> std::shared_ptr { - GLuint texture{}; - - { - auto textureData = generate2D(32, 1); - - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data()); - } - - return std::make_shared("noise_lq_lite", texture, GL_TEXTURE_2D, 32, 32, false); + return std::make_shared("noise_lq_lite", generate2D(32, 1).data(), GL_TEXTURE_2D, 32, 32, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false); } auto MilkdropNoise::MediumQuality() -> std::shared_ptr { - GLuint texture{}; - - { - auto textureData = generate2D(256, 4); - - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data()); - } - return std::make_shared("noise_mq", texture, GL_TEXTURE_2D, 256, 256, false); + return std::make_shared("noise_mq", generate2D(256, 4).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false); } auto MilkdropNoise::HighQuality() -> std::shared_ptr { - GLuint texture{}; - - { - auto textureData = generate2D(256, 8); - - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data()); - } - - return std::make_shared("noise_hq", texture, GL_TEXTURE_2D, 256, 256, false); + return std::make_shared("noise_hq", generate2D(256, 8).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false); } auto MilkdropNoise::LowQualityVolume() -> std::shared_ptr { - GLuint texture{}; - - { - auto textureData = generate3D(32, 1); - - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_3D, texture); - glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data()); - } - - return std::make_shared("noisevol_lq", texture, GL_TEXTURE_3D, 32, 32, false); + return std::make_shared("noisevol_lq", generate3D(32, 1).data(), GL_TEXTURE_3D, 32, 32, 32, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false); } auto MilkdropNoise::HighQualityVolume() -> std::shared_ptr { - GLuint texture{}; - - { - auto textureData = generate3D(32, 4); - - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_3D, texture); - glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data()); - } - - return std::make_shared("noisevol_hq", texture, GL_TEXTURE_3D, 32, 32, false); + return std::make_shared("noisevol_hq", generate3D(32, 4).data(), GL_TEXTURE_3D, 32, 32, 32, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false); } auto MilkdropNoise::GetPreferredInternalFormat() -> int diff --git a/src/libprojectM/Renderer/Texture.cpp b/src/libprojectM/Renderer/Texture.cpp index db0effa74c..dd16121e21 100644 --- a/src/libprojectM/Renderer/Texture.cpp +++ b/src/libprojectM/Renderer/Texture.cpp @@ -18,12 +18,13 @@ Texture::Texture(std::string name, const int width, const int height, const bool CreateNewTexture(); } -Texture::Texture(std::string name, int width, int height, +Texture::Texture(std::string name, GLenum target, int width, int height, int depth, GLint internalFormat, GLenum format, GLenum type, bool isUserTexture) - : m_target(GL_TEXTURE_2D) + : m_target(target) , m_name(std::move(name)) , m_width(width) , m_height(height) + , m_depth(depth) , m_isUserTexture(isUserTexture) , m_internalFormat(internalFormat) , m_format(format) @@ -43,6 +44,21 @@ Texture::Texture(std::string name, const GLuint texID, const GLenum target, { } +Texture::Texture(std::string name, const void* data, GLenum target, int width, int height, int depth, GLint internalFormat, GLenum format, GLenum type, bool isUserTexture) + : m_target(target) + , m_name(std::move(name)) + , m_width(width) + , m_height(height) + , m_depth(depth) + , m_isUserTexture(isUserTexture) + , m_internalFormat(internalFormat) + , m_format(format) + , m_type(type) +{ + glGenTextures(1, &m_textureId); + Update(data); +} + Texture::~Texture() { if (m_textureId > 0) @@ -94,6 +110,11 @@ auto Texture::Height() const -> int return m_height; } +auto Texture::Depth() const -> int +{ + return m_depth; +} + auto Texture::IsUserTexture() const -> bool { return m_isUserTexture; @@ -104,11 +125,40 @@ auto Texture::Empty() const -> bool return m_textureId == 0; } +void Texture::Update(const void* data) const +{ + glBindTexture(m_target, m_textureId); + switch (m_target) + { + case GL_TEXTURE_2D: + glTexImage2D(m_target, 0, m_internalFormat, m_width, m_height, 0, m_format, m_type, data); + break; + case GL_TEXTURE_3D: + glTexImage3D(m_target, 0, m_internalFormat, m_width, m_height, m_depth, 0, m_format, m_type, data); + break; + default: + // Unsupported, do nothing. + break; + } + glBindTexture(m_target, 0); +} + void Texture::CreateNewTexture() { glGenTextures(1, &m_textureId); glBindTexture(m_target, m_textureId); - glTexImage2D(m_target, 0, m_internalFormat, m_width, m_height, 0, m_format, m_type, nullptr); + switch (m_target) + { + case GL_TEXTURE_2D: + glTexImage2D(m_target, 0, m_internalFormat, m_width, m_height, 0, m_format, m_type, nullptr); + break; + case GL_TEXTURE_3D: + glTexImage3D(m_target, 0, m_internalFormat, m_width, m_height, m_depth, 0, m_format, m_type, nullptr); + break; + default: + // Unsupported, do nothing. + break; + } glBindTexture(m_target, 0); } diff --git a/src/libprojectM/Renderer/Texture.hpp b/src/libprojectM/Renderer/Texture.hpp index 75fce1164c..8c483d00fa 100644 --- a/src/libprojectM/Renderer/Texture.hpp +++ b/src/libprojectM/Renderer/Texture.hpp @@ -39,11 +39,16 @@ class Texture /** * @brief Constructor. Allocates a new, empty texture with the given size and format. * @param name Optional name of the texture for referencing in Milkdrop shaders. + * @param target The texture target, either TEXTURE_2D or TEXTURE_3D. * @param width Width in pixels. * @param height Height in pixels. + * @param depth Depth in pixels (for 3D textures). + * @param internalFormat OpenGL internal texture format. + * @param format OpenGL texture format. + * @param type Storage type for each color channel. * @param isUserTexture true if the texture is an externally-loaded image, false if it's an internal texture. */ - explicit Texture(std::string name, int width, int height, + explicit Texture(std::string name, GLenum target, int width, int height, int depth, GLint internalFormat, GLenum format, GLenum type, bool isUserTexture); /** @@ -60,6 +65,22 @@ class Texture int width, int height, bool isUserTexture); + /** + * @brief Constructor. Creates a new texture from image data with the given size and format. + * @param name Optional name of the texture for referencing in Milkdrop shaders. + * @param data The texture data to upload. + * @param target The texture target, either TEXTURE_2D or TEXTURE_3D. + * @param width Width in pixels. + * @param height Height in pixels. + * @param depth Depth in pixels (for 3D textures). + * @param internalFormat OpenGL internal texture format. + * @param format OpenGL texture format. + * @param type Storage type for each color channel. + * @param isUserTexture true if the texture is an externally-loaded image, false if it's an internal texture. + */ + explicit Texture(std::string name, const void* data, GLenum target, int width, int height, int depth, + GLint internalFormat, GLenum format, GLenum type, bool isUserTexture); + Texture(Texture&& other) = default; auto operator=(Texture&& other) -> Texture& = default; @@ -109,6 +130,12 @@ class Texture */ auto Height() const -> int; + /** + * @brief Returns the depth of the texture image in pixels. + * @return The depth of the texture image in pixels. + */ + auto Depth() const -> int; + /** * @brief Returns if the texture is user-defined, e.g. loaded from an image. * @return true if the texture is a user texture, false if it's an internally generated texture. @@ -121,6 +148,13 @@ class Texture */ auto Empty() const -> bool; + /** + * @brief Uploads new image data for the texture. + * @note Automatically binds and unbinds the texture. + * @param data The new texture image data. Must match the size and format used to create the texture. + */ + void Update(const void* data) const; + private: /** * @brief Creates a new, blank texture with the given size. @@ -133,6 +167,7 @@ class Texture std::string m_name; //!< The texture name for identifying it in shaders. int m_width{0}; //!< Texture width in pixels. int m_height{0}; //!< Texture height in pixels. + int m_depth{0}; //!< Texture depth in pixels. Only used for 3D textures. bool m_isUserTexture{false}; //!< true if it's a user texture, false if an internal one. GLint m_internalFormat{}; //!< OpenGL internal format, e.g. GL_RGBA8 diff --git a/src/libprojectM/Renderer/TextureManager.cpp b/src/libprojectM/Renderer/TextureManager.cpp index a8dc2893d2..9dde631bc3 100644 --- a/src/libprojectM/Renderer/TextureManager.cpp +++ b/src/libprojectM/Renderer/TextureManager.cpp @@ -5,12 +5,13 @@ #include "Renderer/MilkdropNoise.hpp" #include "Renderer/Texture.hpp" +#include #include -#include -#include +#include #include +#include #include #include #include @@ -70,24 +71,27 @@ void TextureManager::Preload() int width{}; int height{}; + int channels{}; - unsigned int tex = SOIL_load_OGL_texture_from_memory( - M_data, - M_bytes, - SOIL_LOAD_AUTO, - SOIL_CREATE_NEW_ID, - SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MULTIPLY_ALPHA); + { + std::unique_ptr const imageData(stbi_load_from_memory(M_data, M_bytes, &width, &height, &channels, 0), free); - m_textures["idlem"] = std::make_shared("idlem", tex, GL_TEXTURE_2D, width, height, false);; + if (imageData.get() != nullptr) + { + auto format = TextureFormatFromChannels(channels); + m_textures["idlem"] = std::make_shared("idlem", reinterpret_cast(imageData.get()), GL_TEXTURE_2D, width, height, 0, format, format, GL_UNSIGNED_BYTE, false); + } + } - tex = SOIL_load_OGL_texture_from_memory( - headphones_data, - headphones_bytes, - SOIL_LOAD_AUTO, - SOIL_CREATE_NEW_ID, - SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MULTIPLY_ALPHA); + { + std::unique_ptr const imageData(stbi_load_from_memory(headphones_data, headphones_bytes, &width, &height, &channels, 0), free); - m_textures["idleheadphones"] = std::make_shared("idleheadphones", tex, GL_TEXTURE_2D, width, height, false);; + if (imageData.get() != nullptr) + { + auto format = TextureFormatFromChannels(channels); + m_textures["idleheadphones"] = std::make_shared("idleheadphones", reinterpret_cast(imageData.get()), GL_TEXTURE_2D, width, height, 0, format, format, GL_UNSIGNED_BYTE, false); + } + } // Noise textures m_textures["noise_lq_lite"] = MilkdropNoise::LowQualityLite(); @@ -184,7 +188,7 @@ auto TextureManager::TryLoadingTexture(const std::string& name) -> TextureSample if (texture) { LOG_DEBUG("[TextureManager] Loaded texture \"" + unqualifiedName + "\" from file: " + file.filePath); - return {texture, m_samplers.at({wrapMode, filterMode}), name, unqualifiedName};; + return {texture, m_samplers.at({wrapMode, filterMode}), name, unqualifiedName}; } } @@ -196,8 +200,6 @@ auto TextureManager::TryLoadingTexture(const std::string& name) -> TextureSample auto TextureManager::LoadTexture(const ScannedFile& file) -> std::shared_ptr { - std::string unqualifiedName; - if (m_textures.find(file.lowerCaseBaseName) != m_textures.end()) { return m_textures.at(file.lowerCaseBaseName); @@ -205,32 +207,21 @@ auto TextureManager::LoadTexture(const ScannedFile& file) -> std::shared_ptr imageData(SOIL_load_image(file.filePath.c_str(), &width, &height, &channels, SOIL_LOAD_RGBA), SOIL_free_image_data); + std::unique_ptr imageData(stbi_load(file.filePath.c_str(), &width, &height, nullptr, 4), free); - if (imageData == nullptr) + if (imageData.get() == nullptr) { LOG_DEBUG("[TextureManager] Failed to decode image data."); return {}; } - unsigned int const tex = SOIL_create_OGL_texture( - imageData.get(), - &width, &height, SOIL_LOAD_RGBA, - SOIL_CREATE_NEW_ID, - SOIL_FLAG_MULTIPLY_ALPHA); + auto format = TextureFormatFromChannels(4); + auto newTexture = std::make_shared(file.lowerCaseBaseName, reinterpret_cast(imageData.get()), GL_TEXTURE_2D, width, height, 0, format, format, GL_UNSIGNED_BYTE, true); imageData.reset(); - if (tex == 0) - { - LOG_DEBUG("[TextureManager] Failed to create GPU texture from image data."); - return {}; - } - - uint32_t memoryBytes = width * height * 4; // RGBA, unsigned byte color channels. - auto newTexture = std::make_shared(unqualifiedName, tex, GL_TEXTURE_2D, width, height, true); + uint32_t const memoryBytes = width * height * 4; // RGBA, unsigned byte color channels. m_textures[file.lowerCaseBaseName] = newTexture; m_textureStats.insert({file.lowerCaseBaseName, {memoryBytes}}); @@ -369,5 +360,22 @@ void TextureManager::ScanTextures() } } +uint32_t TextureManager::TextureFormatFromChannels(int channels) +{ + switch (channels) + { + case 1: + return GL_RED; + case 2: + return GL_RG; + case 3: + return GL_RGB; + case 4: + return GL_RGBA; + default: + return 0; + } +} + } // namespace Renderer } // namespace libprojectM diff --git a/src/libprojectM/Renderer/TextureManager.hpp b/src/libprojectM/Renderer/TextureManager.hpp index 388f722ac3..9c1c87a875 100644 --- a/src/libprojectM/Renderer/TextureManager.hpp +++ b/src/libprojectM/Renderer/TextureManager.hpp @@ -90,6 +90,8 @@ class TextureManager void ScanTextures(); + static uint32_t TextureFormatFromChannels(int channels); + std::vector m_textureSearchPaths; //!< Search paths to scan for textures. std::string m_currentPresetDir; //!< Path of the current preset to add to the search list. std::vector m_scannedTextureFiles; //!< The cached list with scanned texture files. diff --git a/tests/libprojectM/CMakeLists.txt b/tests/libprojectM/CMakeLists.txt index 70f7e88f1c..9893fdc012 100644 --- a/tests/libprojectM/CMakeLists.txt +++ b/tests/libprojectM/CMakeLists.txt @@ -37,7 +37,7 @@ add_executable(projectM-unittest $ $ $ - $ + $ $ ) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 74d7a6f756..5c357680c2 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -5,4 +5,4 @@ add_subdirectory(hlslparser) if(NOT TARGET projectM::Eval) add_subdirectory(projectm-eval) endif() -add_subdirectory(SOIL2) +add_subdirectory(stb_image) diff --git a/vendor/SOIL2/CMakeLists.txt b/vendor/SOIL2/CMakeLists.txt deleted file mode 100644 index f26642eab9..0000000000 --- a/vendor/SOIL2/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -add_library(SOIL2 OBJECT - ${CMAKE_CURRENT_SOURCE_DIR}/src/common/common.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/common/common.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_DXT.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_DXT.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_helper.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_helper.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/pkm_helper.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/pvr_helper.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stb_image.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stb_image_write.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_DDS.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_DDS_c.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_ext.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_ext_c.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pkm.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pkm_c.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pvr.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pvr_c.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_qoi.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_qoi_c.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_qoi_write.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/wfETC.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/wfETC.h - ) - -target_include_directories(SOIL2 - PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/src" - ) - -target_link_libraries(SOIL2 - PUBLIC - ${PROJECTM_OPENGL_LIBRARIES} - ) - -if(USE_GLES) - target_compile_definitions(SOIL2 - PRIVATE - SOIL_GLES2 - ) - target_link_libraries(SOIL2 - PUBLIC - ${CMAKE_DL_LIBS} - ) -endif() - -if(NOT TARGET OpenGL::EGL) - target_compile_definitions(SOIL2 - PRIVATE - SOIL_NO_EGL - ) -endif() - -set_target_properties(SOIL2 PROPERTIES - FOLDER vendor/SOIL2 - ) diff --git a/vendor/SOIL2/src/SOIL2/SOIL2.c b/vendor/SOIL2/src/SOIL2/SOIL2.c deleted file mode 100644 index f45d7bfb71..0000000000 --- a/vendor/SOIL2/src/SOIL2/SOIL2.c +++ /dev/null @@ -1,3433 +0,0 @@ -/* - Fork by Martin Lucas Golini - - Original author - Jonathan Dummer - 2007-07-26-10.36 - - Simple OpenGL Image Library 2 - - Public Domain - using Sean Barret's stb_image as a base - - Thanks to: - * Sean Barret - for the awesome stb_image - * Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts - * everybody at gamedev.net -*/ - -#define SOIL_CHECK_FOR_GL_ERRORS 0 - -#if defined( __APPLE_CC__ ) || defined ( __APPLE__ ) - #include - - #if defined( __IPHONE__ ) || ( defined( TARGET_OS_IPHONE ) && TARGET_OS_IPHONE ) || ( defined( TARGET_IPHONE_SIMULATOR ) && TARGET_IPHONE_SIMULATOR ) - #define SOIL_PLATFORM_IOS - #include - #else - #define SOIL_PLATFORM_OSX - #endif -#elif defined( __ANDROID__ ) || defined( ANDROID ) - #define SOIL_PLATFORM_ANDROID -#elif ( defined ( linux ) || defined( __linux__ ) || defined( __FreeBSD__ ) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined( __DragonFly__ ) || defined( __SVR4 ) ) - #define SOIL_X11_PLATFORM -#endif - -#if ( defined( SOIL_PLATFORM_IOS ) || defined( SOIL_PLATFORM_ANDROID ) ) && ( !defined( SOIL_GLES1 ) && !defined( SOIL_GLES2 ) ) - #define SOIL_GLES2 -#endif - -#if ( defined( SOIL_GLES2 ) || defined( SOIL_GLES1 ) ) && !defined( SOIL_NO_EGL ) && !defined( SOIL_PLATFORM_IOS ) - #include -#endif - -#if defined( SOIL_GLES2 ) - #ifdef SOIL_PLATFORM_IOS - #include - #include - #else - #include - #include - #endif - - #define APIENTRY GL_APIENTRY -#elif defined( SOIL_GLES1 ) - #ifndef GL_GLEXT_PROTOTYPES - #define GL_GLEXT_PROTOTYPES - #endif - #ifdef SOIL_PLATFORM_IOS - #include - #include - #else - #include - #include - #endif - - #define APIENTRY GL_APIENTRY -#else - -#if defined( __WIN32__ ) || defined( _WIN32 ) || defined( WIN32 ) - #define SOIL_PLATFORM_WIN32 - #define WIN32_LEAN_AND_MEAN - #include - #include - #include -#elif defined(__APPLE__) || defined(__APPLE_CC__) - /* I can't test this Apple stuff! */ - #include - #include - #define APIENTRY -#elif defined( SOIL_X11_PLATFORM ) - #include - #include -#else - #include -#endif - -#endif - -#ifndef GL_BGRA -#define GL_BGRA 0x80E1 -#endif - -#ifndef GL_RG -#define GL_RG 0x8227 -#endif - -#ifndef GL_UNSIGNED_SHORT_4_4_4_4 -#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 -#endif -#ifndef GL_UNSIGNED_SHORT_5_5_5_1 -#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 -#endif -#ifndef GL_UNSIGNED_SHORT_5_6_5 -#define GL_UNSIGNED_SHORT_5_6_5 0x8363 -#endif - -#ifndef GL_UNSIGNED_BYTE_3_3_2 -#define GL_UNSIGNED_BYTE_3_3_2 0x8032 -#endif - -#include "SOIL2.h" -#define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" -#define STB_IMAGE_WRITE_IMPLEMENTATION -#include "stb_image_write.h" -#include "image_helper.h" -#include "image_DXT.h" -#include "pvr_helper.h" -#include "pkm_helper.h" - -#include -#include - -unsigned long SOIL_version() { return SOIL_COMPILED_VERSION; } - -/* error reporting */ -const char *result_string_pointer = "SOIL initialized"; - -/* for loading cube maps */ -enum{ - SOIL_CAPABILITY_UNKNOWN = -1, - SOIL_CAPABILITY_NONE = 0, - SOIL_CAPABILITY_PRESENT = 1 -}; -static int has_cubemap_capability = SOIL_CAPABILITY_UNKNOWN; -int query_cubemap_capability( void ); -#define SOIL_TEXTURE_WRAP_R 0x8072 -#define SOIL_CLAMP_TO_EDGE 0x812F -#define SOIL_NORMAL_MAP 0x8511 -#define SOIL_REFLECTION_MAP 0x8512 -#define SOIL_TEXTURE_CUBE_MAP 0x8513 -#define SOIL_TEXTURE_BINDING_CUBE_MAP 0x8514 -#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 -#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 -#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 -#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 -#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 -#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A -#define SOIL_PROXY_TEXTURE_CUBE_MAP 0x851B -#define SOIL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C -/* for non-power-of-two texture */ -#define SOIL_IS_POW2( v ) ( ( v & ( v - 1 ) ) == 0 ) -static int has_NPOT_capability = SOIL_CAPABILITY_UNKNOWN; -int query_NPOT_capability( void ); -/* for texture rectangles */ -static int has_tex_rectangle_capability = SOIL_CAPABILITY_UNKNOWN; -int query_tex_rectangle_capability( void ); -#define SOIL_TEXTURE_RECTANGLE_ARB 0x84F5 -#define SOIL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 -/* for using DXT compression */ -static int has_DXT_capability = SOIL_CAPABILITY_UNKNOWN; -int query_DXT_capability( void ); -static int has_3Dc_capability = SOIL_CAPABILITY_UNKNOWN; -int query_3Dc_capability( void ); -#define SOIL_GL_SRGB 0x8C40 -#define SOIL_GL_SRGB_ALPHA 0x8C42 -#define SOIL_RGB_S3TC_DXT1 0x83F0 -#define SOIL_RGBA_S3TC_DXT1 0x83F1 -#define SOIL_RGBA_S3TC_DXT3 0x83F2 -#define SOIL_RGBA_S3TC_DXT5 0x83F3 -#define SOIL_COMPRESSED_RG_RGTC2 0x8DBD -#define SOIL_GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C -#define SOIL_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F -static int has_sRGB_capability = SOIL_CAPABILITY_UNKNOWN; -int query_sRGB_capability( void ); -typedef void (APIENTRY * P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data); -static P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC soilGlCompressedTexImage2D = NULL; - -typedef void (APIENTRY *P_SOIL_GLGENERATEMIPMAPPROC)(GLenum target); -static P_SOIL_GLGENERATEMIPMAPPROC soilGlGenerateMipmap = NULL; - -static int has_gen_mipmap_capability = SOIL_CAPABILITY_UNKNOWN; -static int query_gen_mipmap_capability( void ); - -static int has_PVR_capability = SOIL_CAPABILITY_UNKNOWN; -int query_PVR_capability( void ); -static int has_BGRA8888_capability = SOIL_CAPABILITY_UNKNOWN; -int query_BGRA8888_capability( void ); -static int has_ETC1_capability = SOIL_CAPABILITY_UNKNOWN; -int query_ETC1_capability( void ); - -/* GL_IMG_texture_compression_pvrtc */ -#define SOIL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 -#define SOIL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 -#define SOIL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 -#define SOIL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 -#define SOIL_GL_ETC1_RGB8_OES 0x8D64 - -#if defined( SOIL_X11_PLATFORM ) || defined( SOIL_PLATFORM_WIN32 ) || defined( SOIL_PLATFORM_OSX ) || defined(__HAIKU__) -typedef const GLubyte *(APIENTRY * P_SOIL_glGetStringiFunc) (GLenum, GLuint); -static P_SOIL_glGetStringiFunc soilGlGetStringiFunc = NULL; - -static int isAtLeastGL3() -{ - static int is_gl3 = SOIL_CAPABILITY_UNKNOWN; - - if ( SOIL_CAPABILITY_UNKNOWN == is_gl3 ) - { - const char * verstr = (const char *) glGetString( GL_VERSION ); - is_gl3 = ( verstr && ( atoi(verstr) >= 3 ) && - strstr( verstr, " ES " ) == NULL ); - } - - return is_gl3; -} -#else -static int isAtLeastGL3() -{ - return SOIL_CAPABILITY_NONE; -} -#endif - -#ifdef SOIL_PLATFORM_WIN32 -static HMODULE openglModule = NULL; -static int soilTestWinProcPointer(const PROC pTest) -{ - ptrdiff_t iTest; - if(!pTest) return 0; - iTest = (ptrdiff_t)pTest; - if(iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1) return 0; - return 1; -} -#endif - -#if defined(__sgi) || defined (__sun) || defined(__HAIKU__) -#include - -void* dlGetProcAddress (const char* name) -{ - static void* h = NULL; - static void* gpa; - - if (h == NULL) - { - if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL; - gpa = dlsym(h, "glXGetProcAddress"); - } - - if (gpa != NULL) - return ((void*(*)(const GLubyte*))gpa)((const GLubyte*)name); - else - return dlsym(h, (const char*)name); -} -#endif - -void * SOIL_GL_GetProcAddress(const char *proc) -{ - void *func = NULL; - -#if defined( SOIL_PLATFORM_IOS ) - func = dlsym( RTLD_DEFAULT, proc ); -#elif defined( SOIL_GLES2 ) || defined( SOIL_GLES1 ) - #ifndef SOIL_NO_EGL - func = eglGetProcAddress( proc ); - #else - func = NULL; - #endif -#elif defined( SOIL_PLATFORM_WIN32 ) - if ( NULL == openglModule ) - openglModule = LoadLibraryA("opengl32.dll"); - - func = (void*)wglGetProcAddress(proc); - - if (!soilTestWinProcPointer((const PROC)func)) { - func = (void *)GetProcAddress(openglModule, proc); - } - -#elif defined( SOIL_PLATFORM_OSX ) - /* I can't test this Apple stuff! */ - CFBundleRef bundle; - CFURLRef bundleURL = - CFURLCreateWithFileSystemPath( - kCFAllocatorDefault, - CFSTR("/System/Library/Frameworks/OpenGL.framework"), - kCFURLPOSIXPathStyle, - true ); - CFStringRef extensionName = - CFStringCreateWithCString( - kCFAllocatorDefault, - proc, - kCFStringEncodingASCII ); - bundle = CFBundleCreate( kCFAllocatorDefault, bundleURL ); - assert( bundle != NULL ); - - func = CFBundleGetFunctionPointerForName( bundle, extensionName ); - - CFRelease( bundleURL ); - CFRelease( extensionName ); - CFRelease( bundle ); -#elif defined( SOIL_X11_PLATFORM ) - func = -#if !defined(GLX_VERSION_1_4) - glXGetProcAddressARB -#else - glXGetProcAddress -#endif - ( (const GLubyte *)proc ); -#elif defined(__sgi) || defined (__sun) || defined(__HAIKU__) - func = dlGetProcAddress(proc); -#endif - - return func; -} - -/* Based on the SDL2 implementation */ -int SOIL_GL_ExtensionSupported(const char *extension) -{ - const char *extensions; - const char *start; - const char *where, *terminator; - - /* Extension names should not have spaces. */ - where = strchr(extension, ' '); - - if (where || *extension == '\0') - { - return 0; - } - - #if defined( SOIL_X11_PLATFORM ) || defined( SOIL_PLATFORM_WIN32 ) || defined( SOIL_PLATFORM_OSX ) || defined(__HAIKU__) - /* Lookup the available extensions */ - if ( isAtLeastGL3() ) - { - GLint num_exts = 0; - GLint i; - - if ( NULL == soilGlGetStringiFunc ) - { - soilGlGetStringiFunc = (P_SOIL_glGetStringiFunc)SOIL_GL_GetProcAddress("glGetStringi"); - - if ( NULL == soilGlGetStringiFunc ) - { - return 0; - } - } - - #ifndef GL_NUM_EXTENSIONS - #define GL_NUM_EXTENSIONS 0x821D - #endif - glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts); - for (i = 0; i < num_exts; i++) - { - const char *thisext = (const char *) soilGlGetStringiFunc(GL_EXTENSIONS, i); - - if (strcmp(thisext, extension) == 0) - { - return 1; - } - } - - return 0; - } - #endif - - /* Try the old way with glGetString(GL_EXTENSIONS) ... */ - extensions = (const char *) glGetString(GL_EXTENSIONS); - - if (!extensions) - { - return 0; - } - - /* - * It takes a bit of care to be fool-proof about parsing the OpenGL - * extensions string. Don't be fooled by sub-strings, etc. - */ - start = extensions; - - for (;;) { - where = strstr(start, extension); - - if (!where) - break; - - terminator = where + strlen(extension); - - if (where == start || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') - return 1; - - start = terminator; - } - - return 0; -} - -/* other functions */ -unsigned int - SOIL_internal_create_OGL_texture - ( - const unsigned char *const data, - int *width, int *height, int channels, - unsigned int reuse_texture_ID, - unsigned int flags, - unsigned int opengl_texture_type, - unsigned int opengl_texture_target, - unsigned int texture_check_size_enum - ); - -/* and the code magic begins here [8^) */ -unsigned int - SOIL_load_OGL_texture - ( - const char *filename, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* img; - int width, height, channels; - unsigned int tex_id; - /* does the user want direct uploading of the image as a DDS file? */ - if( flags & SOIL_FLAG_DDS_LOAD_DIRECT ) - { - /* 1st try direct loading of the image as a DDS file - note: direct uploading will only load what is in the - DDS file, no MIPmaps will be generated, the image will - not be flipped, etc. */ - tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 0 ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if( flags & SOIL_FLAG_PVR_LOAD_DIRECT ) - { - tex_id = SOIL_direct_load_PVR( filename, reuse_texture_ID, flags, 0 ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if( flags & SOIL_FLAG_ETC1_LOAD_DIRECT ) - { - tex_id = SOIL_direct_load_ETC1( filename, reuse_texture_ID, flags ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - /* try to load the image */ - img = SOIL_load_image( filename, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* OK, make it a texture! */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - reuse_texture_ID, flags, - GL_TEXTURE_2D, GL_TEXTURE_2D, - GL_MAX_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - /* and return the handle, such as it is */ - return tex_id; -} - -unsigned int - SOIL_load_OGL_HDR_texture - ( - const char *filename, - int fake_HDR_format, - int rescale_to_max, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* img = NULL; - int width, height, channels; - unsigned int tex_id; - /* no direct uploading of the image as a DDS file */ - /* error check */ - if( (fake_HDR_format != SOIL_HDR_RGBE) && - (fake_HDR_format != SOIL_HDR_RGBdivA) && - (fake_HDR_format != SOIL_HDR_RGBdivA2) ) - { - result_string_pointer = "Invalid fake HDR format specified"; - return 0; - } - - /* check if the image is HDR */ - if ( stbi_is_hdr( filename ) ) - { - /* try to load the image (only the HDR type) */ - img = stbi_load( filename, &width, &height, &channels, 4 ); - } - - /* channels holds the original number of channels, which may have been forced */ - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* the load worked, do I need to convert it? */ - if( fake_HDR_format == SOIL_HDR_RGBdivA ) - { - RGBE_to_RGBdivA( img, width, height, rescale_to_max ); - } else if( fake_HDR_format == SOIL_HDR_RGBdivA2 ) - { - RGBE_to_RGBdivA2( img, width, height, rescale_to_max ); - } - /* OK, make it a texture! */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - reuse_texture_ID, flags, - GL_TEXTURE_2D, GL_TEXTURE_2D, - GL_MAX_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - /* and return the handle, such as it is */ - return tex_id; -} - -unsigned int - SOIL_load_OGL_texture_from_memory - ( - const unsigned char *const buffer, - int buffer_length, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* img; - int width, height, channels; - unsigned int tex_id; - /* does the user want direct uploading of the image as a DDS file? */ - if( flags & SOIL_FLAG_DDS_LOAD_DIRECT ) - { - /* 1st try direct loading of the image as a DDS file - note: direct uploading will only load what is in the - DDS file, no MIPmaps will be generated, the image will - not be flipped, etc. */ - tex_id = SOIL_direct_load_DDS_from_memory( - buffer, buffer_length, - reuse_texture_ID, flags, 0 ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if( flags & SOIL_FLAG_PVR_LOAD_DIRECT ) - { - tex_id = SOIL_direct_load_PVR_from_memory( - buffer, buffer_length, - reuse_texture_ID, flags, 0 ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if( flags & SOIL_FLAG_ETC1_LOAD_DIRECT ) - { - tex_id = SOIL_direct_load_ETC1_from_memory( - buffer, buffer_length, - reuse_texture_ID, flags ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - /* try to load the image */ - img = SOIL_load_image_from_memory( - buffer, buffer_length, - &width, &height, &channels, - force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* OK, make it a texture! */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - reuse_texture_ID, flags, - GL_TEXTURE_2D, GL_TEXTURE_2D, - GL_MAX_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - /* and return the handle, such as it is */ - return tex_id; -} - -unsigned int - SOIL_load_OGL_cubemap - ( - const char *x_pos_file, - const char *x_neg_file, - const char *y_pos_file, - const char *y_neg_file, - const char *z_pos_file, - const char *z_neg_file, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* img; - int width, height, channels; - unsigned int tex_id; - /* error checking */ - if( (x_pos_file == NULL) || - (x_neg_file == NULL) || - (y_pos_file == NULL) || - (y_neg_file == NULL) || - (z_pos_file == NULL) || - (z_neg_file == NULL) ) - { - result_string_pointer = "Invalid cube map files list"; - return 0; - } - /* capability checking */ - if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT ) - { - result_string_pointer = "No cube map capability present"; - return 0; - } - /* 1st face: try to load the image */ - img = SOIL_load_image( x_pos_file, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, and create a texture ID if necessary */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - reuse_texture_ID, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image( x_neg_file, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image( y_pos_file, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image( y_neg_file, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image( z_pos_file, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image( z_neg_file, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* and return the handle, such as it is */ - return tex_id; -} - -unsigned int - SOIL_load_OGL_cubemap_from_memory - ( - const unsigned char *const x_pos_buffer, - int x_pos_buffer_length, - const unsigned char *const x_neg_buffer, - int x_neg_buffer_length, - const unsigned char *const y_pos_buffer, - int y_pos_buffer_length, - const unsigned char *const y_neg_buffer, - int y_neg_buffer_length, - const unsigned char *const z_pos_buffer, - int z_pos_buffer_length, - const unsigned char *const z_neg_buffer, - int z_neg_buffer_length, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* img; - int width, height, channels; - unsigned int tex_id; - /* error checking */ - if( (x_pos_buffer == NULL) || - (x_neg_buffer == NULL) || - (y_pos_buffer == NULL) || - (y_neg_buffer == NULL) || - (z_pos_buffer == NULL) || - (z_neg_buffer == NULL) ) - { - result_string_pointer = "Invalid cube map buffers list"; - return 0; - } - /* capability checking */ - if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT ) - { - result_string_pointer = "No cube map capability present"; - return 0; - } - /* 1st face: try to load the image */ - img = SOIL_load_image_from_memory( - x_pos_buffer, x_pos_buffer_length, - &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, and create a texture ID if necessary */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - reuse_texture_ID, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image_from_memory( - x_neg_buffer, x_neg_buffer_length, - &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image_from_memory( - y_pos_buffer, y_pos_buffer_length, - &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image_from_memory( - y_neg_buffer, y_neg_buffer_length, - &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image_from_memory( - z_pos_buffer, z_pos_buffer_length, - &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* continue? */ - if( tex_id != 0 ) - { - /* 1st face: try to load the image */ - img = SOIL_load_image_from_memory( - z_neg_buffer, z_neg_buffer_length, - &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* upload the texture, but reuse the assigned texture ID */ - tex_id = SOIL_internal_create_OGL_texture( - img, &width, &height, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - /* and nuke the image data */ - SOIL_free_image_data( img ); - } - /* and return the handle, such as it is */ - return tex_id; -} - -unsigned int - SOIL_load_OGL_single_cubemap - ( - const char *filename, - const char face_order[6], - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* img; - int width, height, channels, i; - unsigned int tex_id = 0; - /* error checking */ - if( filename == NULL ) - { - result_string_pointer = "Invalid single cube map file name"; - return 0; - } - /* does the user want direct uploading of the image as a DDS file? */ - if( flags & SOIL_FLAG_DDS_LOAD_DIRECT ) - { - /* 1st try direct loading of the image as a DDS file - note: direct uploading will only load what is in the - DDS file, no MIPmaps will be generated, the image will - not be flipped, etc. */ - tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 1 ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if ( flags & SOIL_FLAG_PVR_LOAD_DIRECT ) - { - tex_id = SOIL_direct_load_PVR( filename, reuse_texture_ID, flags, 1 ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if ( flags & SOIL_FLAG_ETC1_LOAD_DIRECT ) - { - return 0; - } - - /* face order checking */ - for( i = 0; i < 6; ++i ) - { - if( (face_order[i] != 'N') && - (face_order[i] != 'S') && - (face_order[i] != 'W') && - (face_order[i] != 'E') && - (face_order[i] != 'U') && - (face_order[i] != 'D') ) - { - result_string_pointer = "Invalid single cube map face order"; - return 0; - }; - } - /* capability checking */ - if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT ) - { - result_string_pointer = "No cube map capability present"; - return 0; - } - /* 1st off, try to load the full image */ - img = SOIL_load_image( filename, &width, &height, &channels, force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* now, does this image have the right dimensions? */ - if( (width != 6*height) && - (6*width != height) ) - { - SOIL_free_image_data( img ); - result_string_pointer = "Single cubemap image must have a 6:1 ratio"; - return 0; - } - /* try the image split and create */ - tex_id = SOIL_create_OGL_single_cubemap( - img, width, height, channels, - face_order, reuse_texture_ID, flags - ); - /* nuke the temporary image data and return the texture handle */ - SOIL_free_image_data( img ); - return tex_id; -} - -unsigned int - SOIL_load_OGL_single_cubemap_from_memory - ( - const unsigned char *const buffer, - int buffer_length, - const char face_order[6], - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* img; - int width, height, channels, i; - unsigned int tex_id = 0; - /* error checking */ - if( buffer == NULL ) - { - result_string_pointer = "Invalid single cube map buffer"; - return 0; - } - /* does the user want direct uploading of the image as a DDS file? */ - if( flags & SOIL_FLAG_DDS_LOAD_DIRECT ) - { - /* 1st try direct loading of the image as a DDS file - note: direct uploading will only load what is in the - DDS file, no MIPmaps will be generated, the image will - not be flipped, etc. */ - tex_id = SOIL_direct_load_DDS_from_memory( - buffer, buffer_length, - reuse_texture_ID, flags, 1 ); - if( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if ( flags & SOIL_FLAG_PVR_LOAD_DIRECT ) - { - tex_id = SOIL_direct_load_PVR_from_memory( - buffer, buffer_length, - reuse_texture_ID, flags, 1 ); - if ( tex_id ) - { - /* hey, it worked!! */ - return tex_id; - } - } - - if ( flags & SOIL_FLAG_ETC1_LOAD_DIRECT ) - { - return 0; - } - - /* face order checking */ - for( i = 0; i < 6; ++i ) - { - if( (face_order[i] != 'N') && - (face_order[i] != 'S') && - (face_order[i] != 'W') && - (face_order[i] != 'E') && - (face_order[i] != 'U') && - (face_order[i] != 'D') ) - { - result_string_pointer = "Invalid single cube map face order"; - return 0; - }; - } - /* capability checking */ - if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT ) - { - result_string_pointer = "No cube map capability present"; - return 0; - } - /* 1st off, try to load the full image */ - img = SOIL_load_image_from_memory( - buffer, buffer_length, - &width, &height, &channels, - force_channels ); - /* channels holds the original number of channels, which may have been forced */ - if( (force_channels >= 1) && (force_channels <= 4) ) - { - channels = force_channels; - } - if( NULL == img ) - { - /* image loading failed */ - result_string_pointer = stbi_failure_reason(); - return 0; - } - /* now, does this image have the right dimensions? */ - if( (width != 6*height) && - (6*width != height) ) - { - SOIL_free_image_data( img ); - result_string_pointer = "Single cubemap image must have a 6:1 ratio"; - return 0; - } - /* try the image split and create */ - tex_id = SOIL_create_OGL_single_cubemap( - img, width, height, channels, - face_order, reuse_texture_ID, flags - ); - /* nuke the temporary image data and return the texture handle */ - SOIL_free_image_data( img ); - return tex_id; -} - -unsigned int - SOIL_create_OGL_single_cubemap - ( - const unsigned char *const data, - int width, int height, int channels, - const char face_order[6], - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* variables */ - unsigned char* sub_img; - int dw, dh, sz, i; - unsigned int tex_id; - /* error checking */ - if( data == NULL ) - { - result_string_pointer = "Invalid single cube map image data"; - return 0; - } - /* face order checking */ - for( i = 0; i < 6; ++i ) - { - if( (face_order[i] != 'N') && - (face_order[i] != 'S') && - (face_order[i] != 'W') && - (face_order[i] != 'E') && - (face_order[i] != 'U') && - (face_order[i] != 'D') ) - { - result_string_pointer = "Invalid single cube map face order"; - return 0; - }; - } - /* capability checking */ - if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT ) - { - result_string_pointer = "No cube map capability present"; - return 0; - } - /* now, does this image have the right dimensions? */ - if( (width != 6*height) && - (6*width != height) ) - { - result_string_pointer = "Single cubemap image must have a 6:1 ratio"; - return 0; - } - /* which way am I stepping? */ - if( width > height ) - { - dw = height; - dh = 0; - } else - { - dw = 0; - dh = width; - } - sz = dw+dh; - sub_img = (unsigned char *)malloc( sz*sz*channels ); - /* do the splitting and uploading */ - tex_id = reuse_texture_ID; - for( i = 0; i < 6; ++i ) - { - int x, y, idx = 0; - unsigned int cubemap_target = 0; - /* copy in the sub-image */ - for( y = i*dh; y < i*dh+sz; ++y ) - { - for( x = i*dw*channels; x < (i*dw+sz)*channels; ++x ) - { - sub_img[idx++] = data[y*width*channels+x]; - } - } - /* what is my texture target? - remember, this coordinate system is - LHS if viewed from inside the cube! */ - switch( face_order[i] ) - { - case 'N': - cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z; - break; - case 'S': - cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z; - break; - case 'W': - cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X; - break; - case 'E': - cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_X; - break; - case 'U': - cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y; - break; - case 'D': - cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y; - break; - } - /* upload it as a texture */ - tex_id = SOIL_internal_create_OGL_texture( - sub_img, &sz, &sz, channels, - tex_id, flags, - SOIL_TEXTURE_CUBE_MAP, - cubemap_target, - SOIL_MAX_CUBE_MAP_TEXTURE_SIZE ); - } - /* and nuke the image and sub-image data */ - SOIL_free_image_data( sub_img ); - /* and return the handle, such as it is */ - return tex_id; -} - -unsigned int - SOIL_create_OGL_texture - ( - const unsigned char *const data, - int *width, int *height, int channels, - unsigned int reuse_texture_ID, - unsigned int flags - ) -{ - /* wrapper function for 2D textures */ - return SOIL_internal_create_OGL_texture( - data, width, height, channels, - reuse_texture_ID, flags, - GL_TEXTURE_2D, GL_TEXTURE_2D, - GL_MAX_TEXTURE_SIZE ); -} - -#if SOIL_CHECK_FOR_GL_ERRORS -void check_for_GL_errors( const char *calling_location ) -{ - /* check for errors */ - GLenum err_code = glGetError(); - while( GL_NO_ERROR != err_code ) - { - printf( "OpenGL Error @ %s: %i", calling_location, err_code ); - err_code = glGetError(); - } -} -#else -void check_for_GL_errors( const char *calling_location ) -{ - /* no check for errors */ -} -#endif - -static void createMipmaps(const unsigned char *const img, - int width, int height, int channels, - unsigned int flags, - unsigned int opengl_texture_target, - unsigned int internal_texture_format, - unsigned int original_texture_format, - int DXT_mode) -{ - if ( ( flags & SOIL_FLAG_GL_MIPMAPS ) && query_gen_mipmap_capability() == SOIL_CAPABILITY_PRESENT ) - { - soilGlGenerateMipmap(opengl_texture_target); - } - else - { - int MIPlevel = 1; - int MIPwidth = (width+1) / 2; - int MIPheight = (height+1) / 2; - unsigned char *resampled = (unsigned char*)malloc( channels*MIPwidth*MIPheight ); - - while( ((1< 0; --i ) - { - unsigned char temp = img[index1]; - img[index1] = img[index2]; - img[index2] = temp; - ++index1; - ++index2; - } - } - } - /* does the user want me to scale the colors into the NTSC safe RGB range? */ - if( flags & SOIL_FLAG_NTSC_SAFE_RGB ) - { - scale_image_RGB_to_NTSC_safe( img, iwidth, iheight, channels ); - } - /* does the user want me to convert from straight to pre-multiplied alpha? - (and do we even _have_ alpha?) */ - if( flags & SOIL_FLAG_MULTIPLY_ALPHA ) - { - int i; - switch( channels ) - { - case 2: - for( i = 0; i < 2*iwidth*iheight; i += 2 ) - { - img[i] = (img[i] * img[i+1] + 128) >> 8; - } - break; - case 4: - for( i = 0; i < 4*iwidth*iheight; i += 4 ) - { - img[i+0] = (img[i+0] * img[i+3] + 128) >> 8; - img[i+1] = (img[i+1] * img[i+3] + 128) >> 8; - img[i+2] = (img[i+2] * img[i+3] + 128) >> 8; - } - break; - default: - /* no other number of channels contains alpha data */ - break; - } - } - - /* do I need to make it a power of 2? */ - if( - ( ( flags & SOIL_FLAG_POWER_OF_TWO) && ( !SOIL_IS_POW2(iwidth) || !SOIL_IS_POW2(iheight) ) ) || /* user asked for it and the texture is not power of 2 */ - ( (flags & SOIL_FLAG_MIPMAPS)&& !( ( flags & SOIL_FLAG_GL_MIPMAPS ) && - query_gen_mipmap_capability() == SOIL_CAPABILITY_PRESENT && - query_NPOT_capability() == SOIL_CAPABILITY_PRESENT ) ) || /* need it for the MIP-maps when mipmaps required - and not GL mipmaps required and supported */ - (iwidth > max_supported_size) || /* it's too big, (make sure it's */ - (iheight > max_supported_size) ) /* 2^n for later down-sampling) */ - { - int new_width = 1; - int new_height = 1; - while( new_width < iwidth ) - { - new_width *= 2; - } - while( new_height < iheight ) - { - new_height *= 2; - } - /* still? */ - if( (new_width != iwidth) || (new_height != iheight) ) - { - /* yep, resize */ - unsigned char *resampled = (unsigned char*)malloc( channels*new_width*new_height ); - up_scale_image( - NULL != img ? img : data, iwidth, iheight, channels, - resampled, new_width, new_height ); - - /* nuke the old guy ( if a copy exists ), then point it at the new guy */ - SOIL_free_image_data( img ); - img = resampled; - *width = new_width; - *height = new_height; - iwidth = new_width; - iheight = new_height; - } - } - /* now, if it is too large... */ - if( (iwidth > max_supported_size) || (iheight > max_supported_size) ) - { - /* I've already made it a power of two, so simply use the MIPmapping - code to reduce its size to the allowable maximum. */ - unsigned char *resampled; - int reduce_block_x = 1, reduce_block_y = 1; - int new_width, new_height; - if( iwidth > max_supported_size ) - { - reduce_block_x = iwidth / max_supported_size; - } - if( iheight > max_supported_size ) - { - reduce_block_y = iheight / max_supported_size; - } - new_width = iwidth / reduce_block_x; - new_height = iheight / reduce_block_y; - resampled = (unsigned char*)malloc( channels*new_width*new_height ); - /* perform the actual reduction */ - mipmap_image( NULL != img ? img : data, iwidth, iheight, channels, - resampled, reduce_block_x, reduce_block_y ); - /* nuke the old guy, then point it at the new guy */ - SOIL_free_image_data( img ); - img = resampled; - *width = new_width; - *height = new_height; - iwidth = new_width; - iheight = new_height; - } - /* does the user want us to use YCoCg color space? */ - if( flags & SOIL_FLAG_CoCg_Y ) - { - /* this will only work with RGB and RGBA images */ - convert_RGB_to_YCoCg( img, iwidth, iheight, channels ); - } - /* create the OpenGL texture ID handle - (note: allowing a forced texture ID lets me reload a texture) */ - tex_id = reuse_texture_ID; - if( tex_id == 0 ) - { - glGenTextures( 1, &tex_id ); - } - check_for_GL_errors( "glGenTextures" ); - /* Note: sometimes glGenTextures fails (usually no OpenGL context) */ - if( tex_id ) - { - /* and what type am I using as the internal texture format? */ - switch( channels ) - { - case 1: - original_texture_format = GL_LUMINANCE; - break; - case 2: - original_texture_format = GL_LUMINANCE_ALPHA; - break; - case 3: - original_texture_format = GL_RGB; - break; - case 4: - original_texture_format = GL_RGBA; - break; - } - internal_texture_format = original_texture_format; - /* does the user want me to, and can I, save as DXT? */ - if( flags & SOIL_FLAG_COMPRESS_TO_DXT ) - { - DXT_mode = query_DXT_capability(); - if( DXT_mode == SOIL_CAPABILITY_PRESENT ) - { - /* I can use DXT, whether I compress it or OpenGL does */ - if( (channels & 1) == 1 ) - { - /* 1 or 3 channels = DXT1 */ - internal_texture_format = sRGB_texture ? SOIL_GL_COMPRESSED_SRGB_S3TC_DXT1_EXT : SOIL_RGB_S3TC_DXT1; - } else - { - /* 2 or 4 channels = DXT5 */ - internal_texture_format = sRGB_texture ? SOIL_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : SOIL_RGBA_S3TC_DXT5; - } - } - } - else if ( sRGB_texture ) - { - switch( channels ) - { - case 3: - internal_texture_format = SOIL_GL_SRGB; - break; - case 4: - internal_texture_format = SOIL_GL_SRGB_ALPHA; - break; - } - } - - /* bind an OpenGL texture ID */ - glBindTexture( opengl_texture_type, tex_id ); - check_for_GL_errors( "glBindTexture" ); - - /* set the unpack aligment */ - glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_aligment); - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT,1); - } - - /* upload the main image */ - if( DXT_mode == SOIL_CAPABILITY_PRESENT ) - { - /* user wants me to do the DXT conversion! */ - int DDS_size; - unsigned char *DDS_data = NULL; - if( (channels & 1) == 1 ) - { - /* RGB, use DXT1 */ - DDS_data = convert_image_to_DXT1( NULL != img ? img : data, iwidth, iheight, channels, &DDS_size ); - } else - { - /* RGBA, use DXT5 */ - DDS_data = convert_image_to_DXT5( NULL != img ? img : data, iwidth, iheight, channels, &DDS_size ); - } - if( DDS_data ) - { - soilGlCompressedTexImage2D( - opengl_texture_target, 0, - internal_texture_format, iwidth, iheight, 0, - DDS_size, DDS_data ); - check_for_GL_errors( "glCompressedTexImage2D" ); - SOIL_free_image_data( DDS_data ); - /* printf( "Internal DXT compressor\n" ); */ - } else - { - /* my compression failed, try the OpenGL driver's version */ - glTexImage2D( - opengl_texture_target, 0, - internal_texture_format, iwidth, iheight, 0, - original_texture_format, GL_UNSIGNED_BYTE, NULL != img ? img : data ); - check_for_GL_errors( "glTexImage2D" ); - /* printf( "OpenGL DXT compressor\n" ); */ - } - } else - { - /* user want OpenGL to do all the work! */ - glTexImage2D( - opengl_texture_target, 0, - internal_texture_format, iwidth, iheight, 0, - original_texture_format, GL_UNSIGNED_BYTE, NULL != img ? img : data ); - - check_for_GL_errors( "glTexImage2D" ); - /*printf( "OpenGL DXT compressor\n" ); */ - } - - /* are any MIPmaps desired? */ - if( flags & SOIL_FLAG_MIPMAPS || flags & SOIL_FLAG_GL_MIPMAPS ) - { - createMipmaps( NULL != img ? img : data, iwidth, iheight, channels, flags, opengl_texture_target, internal_texture_format, original_texture_format, DXT_mode ); - - /* instruct OpenGL to use the MIPmaps */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); - check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" ); - } else - { - /* instruct OpenGL _NOT_ to use the MIPmaps */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" ); - } - - /* recover the unpack aligment */ - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_aligment); - } - - /* does the user want clamping, or wrapping? */ - if( flags & SOIL_FLAG_TEXTURE_REPEATS ) - { - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT ); - if( opengl_texture_type == SOIL_TEXTURE_CUBE_MAP ) - { - /* SOIL_TEXTURE_WRAP_R is invalid if cubemaps aren't supported */ - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT ); - } - check_for_GL_errors( "GL_TEXTURE_WRAP_*" ); - } else - { - unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; - /* unsigned int clamp_mode = GL_CLAMP; */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode ); - if( opengl_texture_type == SOIL_TEXTURE_CUBE_MAP ) - { - /* SOIL_TEXTURE_WRAP_R is invalid if cubemaps aren't supported */ - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode ); - } - check_for_GL_errors( "GL_TEXTURE_WRAP_*" ); - } - /* done */ - result_string_pointer = "Image loaded as an OpenGL texture"; - } else - { - /* failed */ - result_string_pointer = "Failed to generate an OpenGL texture name; missing OpenGL context?"; - } - - SOIL_free_image_data( img ); - - return tex_id; -} - -int - SOIL_save_screenshot - ( - const char *filename, - int image_type, - int x, int y, - int width, int height - ) -{ - unsigned char *pixel_data; - int i, j; - int save_result; - GLint pack_aligment; - - /* error checks */ - if( (width < 1) || (height < 1) ) - { - result_string_pointer = "Invalid screenshot dimensions"; - return 0; - } - if( (x < 0) || (y < 0) ) - { - result_string_pointer = "Invalid screenshot location"; - return 0; - } - if( filename == NULL ) - { - result_string_pointer = "Invalid screenshot filename"; - return 0; - } - - glGetIntegerv(GL_PACK_ALIGNMENT, &pack_aligment); - if ( 1 != pack_aligment ) - { - glPixelStorei(GL_PACK_ALIGNMENT,1); - } - - /* Get the data from OpenGL */ - pixel_data = (unsigned char*)malloc( 3*width*height ); - glReadPixels (x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixel_data); - - if ( 1 != pack_aligment ) - { - glPixelStorei(GL_PACK_ALIGNMENT, pack_aligment); - } - - /* invert the image */ - for( j = 0; j*2 < height; ++j ) - { - int index1 = j * width * 3; - int index2 = (height - 1 - j) * width * 3; - for( i = width * 3; i > 0; --i ) - { - unsigned char temp = pixel_data[index1]; - pixel_data[index1] = pixel_data[index2]; - pixel_data[index2] = temp; - ++index1; - ++index2; - } - } - - /* save the image */ - save_result = SOIL_save_image( filename, image_type, width, height, 3, pixel_data); - - /* And free the memory */ - SOIL_free_image_data( pixel_data ); - return save_result; -} - -unsigned char* - SOIL_load_image - ( - const char *filename, - int *width, int *height, int *channels, - int force_channels - ) -{ - unsigned char *result = stbi_load( filename, - width, height, channels, force_channels ); - if( result == NULL ) - { - result_string_pointer = stbi_failure_reason(); - } else - { - result_string_pointer = "Image loaded"; - } - return result; -} - -unsigned char* - SOIL_load_image_from_memory - ( - const unsigned char *const buffer, - int buffer_length, - int *width, int *height, int *channels, - int force_channels - ) -{ - unsigned char *result = stbi_load_from_memory( - buffer, buffer_length, - width, height, channels, - force_channels ); - if( result == NULL ) - { - result_string_pointer = stbi_failure_reason(); - } else - { - result_string_pointer = "Image loaded from memory"; - } - return result; -} - - -int - SOIL_save_image - ( - const char *filename, - int image_type, - int width, int height, int channels, - const unsigned char *const data - ) -{ - return SOIL_save_image_quality( filename, image_type, width, height, channels, data, 80 ); -} - -int - SOIL_save_image_quality - ( - const char *filename, - int image_type, - int width, int height, int channels, - const unsigned char *const data, - int quality - ) -{ - int save_result; - - /* error check */ - if( (width < 1) || (height < 1) || - (channels < 1) || (channels > 4) || - (data == NULL) || - (filename == NULL) ) - { - return 0; - } - if( image_type == SOIL_SAVE_TYPE_BMP ) - { - save_result = stbi_write_bmp( filename, - width, height, channels, (const void*)data ); - } else - if( image_type == SOIL_SAVE_TYPE_TGA ) - { - save_result = stbi_write_tga( filename, - width, height, channels, (const void*)data ); - } else - if( image_type == SOIL_SAVE_TYPE_DDS ) - { - save_result = save_image_as_DDS( filename, - width, height, channels, (const unsigned char *const)data ); - } else - if( image_type == SOIL_SAVE_TYPE_PNG ) - { - save_result = stbi_write_png( filename, - width, height, channels, (const void*)data, 0 ); - } else - if ( image_type == SOIL_SAVE_TYPE_JPG ) - { - save_result = stbi_write_jpg( filename, width, height, channels, (const void*)data, quality ); - } else - if ( image_type == SOIL_SAVE_TYPE_QOI ) - { - save_result = stbi_write_qoi( filename, width, height, channels, (const void*)data ); - } - else - { - save_result = 0; - } - - if( save_result == 0 ) - { - result_string_pointer = "Saving the image failed"; - } else - { - result_string_pointer = "Image saved"; - } - return save_result; -} - - -typedef struct -{ - unsigned char* buffer; - int allocated; // number of bytes allocated to the buffer - int written; // number of bytes written to the buffer - int alloc_block_size; // size of blocks to alloc as memory is required -} stbi_write_context; - -void write_to_memory(void* context, void* data, int size) -{ - stbi_write_context* ctx = (stbi_write_context*)context; - - if(ctx == 0) - return; - - if (ctx->buffer == 0) - { - // safety - ctx->written = 0; - ctx->allocated = 0; - - // first alloc - while (ctx->allocated < (ctx->written + size)) - { - ctx->allocated += ctx->alloc_block_size; - } - ctx->buffer = (unsigned char*) malloc(ctx->allocated); - } - else if((ctx->written + size) > ctx->allocated) - { - ctx->allocated += ctx->alloc_block_size; - while (ctx->allocated < (ctx->written + size)) - { - ctx->allocated += ctx->alloc_block_size; - } - - unsigned char* rebuff = (unsigned char*)realloc(ctx->buffer, ctx->allocated); - if (rebuff == 0) - { - // out of memory - free(ctx->buffer); - ctx->buffer = 0; - ctx->allocated = 0; - return; - } - else - { - ctx->buffer = rebuff; - } - } - - if(ctx->buffer == 0) - return; - - memcpy(ctx->buffer + ctx->written, data, size); - ctx->written += size; -} - - -// release the returned memory with SOIL_free_image_data -unsigned char* -SOIL_write_image_to_memory_quality -( - int image_type, - int width, int height, int channels, - const unsigned char* const data, - int quality, - int* imageSize -) -{ - int save_result; - - /* error check */ - if ((width < 1) || (height < 1) || - (channels < 1) || (channels > 4) || - (data == NULL) || - (imageSize == NULL) - ) - { - return 0; - } - - unsigned char* imageMemory = NULL; - *imageSize = 0; - - stbi_write_context context; - context.alloc_block_size = 4096; // 4k chunks - context.buffer = 0; - context.allocated = 0; - context.written = 0; - - if (image_type == SOIL_SAVE_TYPE_BMP) - { - save_result = stbi_write_bmp_to_func(write_to_memory, &context, width, height, channels, (const unsigned char*)data); - } - else if (image_type == SOIL_SAVE_TYPE_TGA) - { - save_result = stbi_write_tga_to_func(write_to_memory, &context, width, height, channels, (const unsigned char*)data); - } - else if (image_type == SOIL_SAVE_TYPE_DDS) - { - save_result = 0; // not supported thru stbi - } - else if (image_type == SOIL_SAVE_TYPE_PNG) - { - save_result = stbi_write_png_to_func(write_to_memory, &context, width, height, channels, (const unsigned char*)data, 0); - } - else if (image_type == SOIL_SAVE_TYPE_JPG) - { - save_result = stbi_write_jpg_to_func(write_to_memory, &context, width, height, channels, (const unsigned char*)data, quality); - } - else if (image_type == SOIL_SAVE_TYPE_QOI) - { - save_result = stbi_write_qoi_to_func(write_to_memory, &context, width, height, channels, (const unsigned char*)data); - } - else - { - save_result = 0; - } - - if (save_result) - { - imageMemory = context.buffer; - *imageSize = context.written; - } - else - { - if (context.buffer) - free(context.buffer); - } - - if (save_result == 0) - { - result_string_pointer = "writing the image failed"; - } - else - { - result_string_pointer = "Image written"; - } - - return imageMemory; -} - -// release the returned memory with SOIL_free_image_data -unsigned char* -SOIL_write_image_to_memory -( - int image_type, - int width, int height, int channels, - const unsigned char* const data, - int* imageSize -) -{ - return SOIL_write_image_to_memory_quality(image_type, width, height, channels, data, 80, imageSize); -} - -void - SOIL_free_image_data - ( - unsigned char *img_data - ) -{ - if ( img_data ) - free( (void*)img_data ); -} - -const char* - SOIL_last_result - ( - void - ) -{ - return result_string_pointer; -} - -/* This circumvent a VS2022 compiler bug */ -#ifdef _MSC_VER -#pragma optimize( "", off ) -#endif -static inline int calc_total_block_size( int w, int h, int block_size ) { - return ( ( w + 3 ) >> 2 ) * ( ( h + 3 ) >> 2 ) * block_size; -} -#ifdef _MSC_VER -#pragma optimize( "", on ) -#endif - -unsigned int SOIL_direct_load_DDS_from_memory( - const unsigned char *const buffer, - int buffer_length, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap) -{ - - unsigned int buffer_index = 0; - unsigned int tex_ID = 0; - - unsigned int internal_format = 0; - unsigned char *DDS_data; - unsigned int DDS_main_size; - unsigned int DDS_full_size; - int mipmaps, block_size = 16; - unsigned int cf_target, ogl_target_start, ogl_target_end; - unsigned int opengl_texture_type; - unsigned int format_type = GL_UNSIGNED_BYTE; - - /* 1st off, does the filename even exist? */ - if( NULL == buffer ) - { - /* we can't do it! */ - result_string_pointer = "NULL buffer"; - return 0; - } - if( buffer_length < (int)sizeof( DDS_header ) ) - { - /* we can't do it! */ - result_string_pointer = "DDS file was too small to contain the DDS header"; - return 0; - } - - // Try reading in the header - DDS_header header; - memcpy( (void *)( &header ), (const void *)buffer, sizeof( DDS_header ) ); - - buffer_index += sizeof(DDS_header); - /* guilty until proven innocent */ - result_string_pointer = "Failed to read a known DDS header"; - /* validate the header (warning, "goto"'s ahead, shield your eyes!!) */ - unsigned int flag = ( 'D' << 0 ) | ( 'D' << 8 ) | ( 'S' << 16 ) | ( ' ' << 24 ); - - if( header.dwMagic != flag ) { goto quick_exit; } - if( header.dwSize != 124 ) { goto quick_exit; } - /* I need all of these */ - flag = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; - if( ( header.dwFlags & flag ) != flag ) { goto quick_exit; } - /* According to the MSDN spec, the dwFlags should contain - DDSD_LINEARSIZE if it's compressed, or DDSD_PITCH if - uncompressed. Some DDS writers do not conform to the - spec, so I need to make my reader more tolerant */ - /* I need one of these */ - flag = DDPF_FOURCC | DDPF_RGB | DDPF_LUMINANCE; - if( ( header.sPixelFormat.dwFlags & flag ) == 0 ) { goto quick_exit; } - if( header.sPixelFormat.dwSize != 32 ) { goto quick_exit; } - if( ( header.sCaps.dwCaps1 & DDSCAPS_TEXTURE ) == 0 ) { goto quick_exit; } - - enum Magics - { - DXT1 = ( 'D' << 0 ) | ( 'X' << 8 ) | ( 'T' << 16 ) | ( '1' << 24 ), - DXT3 = ( 'D' << 0 ) | ( 'X' << 8 ) | ( 'T' << 16 ) | ( '3' << 24 ), - DXT5 = ( 'D' << 0 ) | ( 'X' << 8 ) | ( 'T' << 16 ) | ( '5' << 24 ), - ATI2 = ( 'A' << 0 ) | ( 'T' << 8 ) | ( 'I' << 16 ) | ( '2' << 24 ), - DX10 = ( 'D' << 0 ) | ( 'X' << 8 ) | ( '1' << 16 ) | ( '0' << 24 ), - }; - - // DX10 has an extended header - DDS_HEADER_DXT10 dx10_header; - if (header.sPixelFormat.dwFourCC == DX10) { - memcpy((void*)(&dx10_header), (const void*)&buffer[buffer_index], sizeof(DDS_HEADER_DXT10)); - buffer_index += sizeof(dx10_header); - } - - // make sure it is a type we can upload - if ((header.sPixelFormat.dwFlags & DDPF_FOURCC) - && header.sPixelFormat.dwFourCC != DXT1 - && header.sPixelFormat.dwFourCC != DXT3 - && header.sPixelFormat.dwFourCC != DXT5 - && header.sPixelFormat.dwFourCC != ATI2 - && header.sPixelFormat.dwFourCC != DX10 - ){ - goto quick_exit; - } - - /* OK, validated the header, let's load the image data */ - result_string_pointer = "DDS header loaded and validated"; - - const int width = header.dwWidth; - const int height = header.dwHeight; - int uncompressed = 1 - ( header.sPixelFormat.dwFlags & DDPF_FOURCC ) / DDPF_FOURCC; - int cubemap = ( header.sCaps.dwCaps2 & DDSCAPS2_CUBEMAP ) / DDSCAPS2_CUBEMAP; - if( uncompressed ) - { - if( header.sPixelFormat.dwRGBBitCount == 8 ) - { - if( ( header.sPixelFormat.dwRBitMask == 0xe0 ) && ( header.sPixelFormat.dwGBitMask == 0x1c ) && - ( header.sPixelFormat.dwBBitMask == 0x3 ) ) - { - internal_format = GL_RGB; - format_type = GL_UNSIGNED_BYTE_3_3_2; - block_size = 1; - } - else - { - internal_format = GL_LUMINANCE; - block_size = 1; - } - } - else if( header.sPixelFormat.dwRGBBitCount == 16 ) - { - if( ( header.sPixelFormat.dwRBitMask == 0xf800 ) && ( header.sPixelFormat.dwGBitMask == 0x7e0 ) && - ( header.sPixelFormat.dwBBitMask == 0x1f ) ) - { - // DXGI_FORMAT_B5G6R5_UNORM - internal_format = GL_RGBA; - format_type = GL_UNSIGNED_SHORT_5_5_5_1; - block_size = 2; - } - else if( ( header.sPixelFormat.dwRBitMask == 0xf00 ) && ( header.sPixelFormat.dwGBitMask == 0xf0 ) && - ( header.sPixelFormat.dwBBitMask == 0xf ) && ( header.sPixelFormat.dwAlphaBitMask == 0xf000 ) ) - { - // D3DFMT_A4R4G4B4 - internal_format = GL_RGBA; - format_type = GL_UNSIGNED_SHORT_4_4_4_4; - block_size = 2; - } - else if( ( header.sPixelFormat.dwRBitMask == 0x7c00 ) && ( header.sPixelFormat.dwGBitMask == 0x3e0 ) && - ( header.sPixelFormat.dwBBitMask == 0x1f ) ) - { - // DXGI_FORMAT_B5G5R5A1_UNORM - internal_format = GL_RGBA; - format_type = GL_UNSIGNED_SHORT_5_5_5_1; - block_size = 2; - } - else - { - internal_format = GL_RG; - block_size = 2; - } - } - else - { - internal_format = GL_RGB; - block_size = 3; - if( header.sPixelFormat.dwFlags & DDPF_ALPHAPIXELS ) - { - internal_format = GL_RGBA; - block_size = 4; - } - } - DDS_main_size = width * height * block_size; - } - else - { - if( header.sPixelFormat.dwFourCC == ATI2 ) - { - if( query_3Dc_capability() != SOIL_CAPABILITY_PRESENT ) - { - /* we can't do it! */ - result_string_pointer = "Direct upload of 3Dc images not supported by the OpenGL driver"; - return 0; - } - } - else - { - if( query_DXT_capability() != SOIL_CAPABILITY_PRESENT ) - { - /* we can't do it! */ - result_string_pointer = "Direct upload of S3TC images not supported by the OpenGL driver"; - return 0; - } - } - - switch( header.sPixelFormat.dwFourCC ) - { - case DXT1: - internal_format = SOIL_RGBA_S3TC_DXT1; - block_size = 8; - break; - case DXT3: - internal_format = SOIL_RGBA_S3TC_DXT3; - block_size = 16; - break; - case DXT5: - internal_format = SOIL_RGBA_S3TC_DXT5; - block_size = 16; - break; - case ATI2: - block_size = 16; - internal_format = SOIL_COMPRESSED_RG_RGTC2; - break; - case DX10: - if (dx10_header.dxgiFormat != DXGI_FORMAT_BC5_UNORM) { - result_string_pointer = "The DX10 reader only supports BC5 unorm at the moment"; - return 0; - } - block_size = 16; - internal_format = SOIL_COMPRESSED_RG_RGTC2; - break; - } - DDS_main_size = ( ( width + 3 ) >> 2 ) * ( ( height + 3 ) >> 2 ) * block_size; - } - - if( cubemap ) - { - /* does the user want a cubemap? */ - if( !loading_as_cubemap ) - { - /* we can't do it! */ - result_string_pointer = "DDS image was a cubemap"; - return 0; - } - /* can we even handle cubemaps with the OpenGL driver? */ - if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT ) - { - /* we can't do it! */ - result_string_pointer = "Direct upload of cubemap images not supported by the OpenGL driver"; - return 0; - } - ogl_target_start = SOIL_TEXTURE_CUBE_MAP_POSITIVE_X; - ogl_target_end = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z; - opengl_texture_type = SOIL_TEXTURE_CUBE_MAP; - } - else - { - /* does the user want a non-cubemap? */ - if( loading_as_cubemap ) - { - /* we can't do it! */ - result_string_pointer = "DDS image was not a cubemap"; - return 0; - } - ogl_target_start = GL_TEXTURE_2D; - ogl_target_end = GL_TEXTURE_2D; - opengl_texture_type = GL_TEXTURE_2D; - } - - if( ( header.sCaps.dwCaps1 & DDSCAPS_MIPMAP ) && ( header.dwMipMapCount > 1 ) ) - { - mipmaps = header.dwMipMapCount - 1; - DDS_full_size = DDS_main_size; - - for( int i = 1; i <= mipmaps; ++i ) - { - int w = width >> i; - int h = height >> i; - if( w < 1 ) { w = 1; } - if( h < 1 ) { h = 1; } - if( uncompressed ) - { - /* uncompressed DDS, simple MIPmap size calculation */ - DDS_full_size += w * h * block_size; - } - else - { - /* compressed DDS, MIPmap size calculation is block based */ - DDS_full_size += calc_total_block_size( w, h, block_size ); - } - } - } - else - { - mipmaps = 0; - DDS_full_size = DDS_main_size; - } - DDS_data = (unsigned char *)malloc( DDS_full_size ); - /* got the image data RAM, create or use an existing OpenGL texture handle */ - tex_ID = reuse_texture_ID; - if( tex_ID == 0 ) { glGenTextures( 1, &tex_ID ); } - /* bind an OpenGL texture ID */ - glBindTexture( opengl_texture_type, tex_ID ); - /* do this for each face of the cubemap! */ - for( cf_target = ogl_target_start; cf_target <= ogl_target_end; ++cf_target ) - { - if( buffer_index + DDS_full_size <= (unsigned int)buffer_length ) - { - unsigned int byte_offset = DDS_main_size; - memcpy( (void *)DDS_data, (const void *)( &buffer[buffer_index] ), DDS_full_size ); - buffer_index += DDS_full_size; - /* upload the main chunk */ - if( uncompressed ) - { - if( ( header.sPixelFormat.dwRBitMask == 0xff0000 ) && - ( ( block_size == 3 && internal_format == GL_RGB ) || - ( block_size == 4 && internal_format == GL_RGBA ) ) ) - { - for( int i = 0; i < (int)DDS_full_size; i += block_size ) - { - unsigned char temp = DDS_data[i]; - DDS_data[i] = DDS_data[i + 2]; - DDS_data[i + 2] = temp; - } - } - else if( block_size == 2 && - ( header.sPixelFormat.dwRBitMask == 0xf800 || header.sPixelFormat.dwRBitMask == 0x7c00 ) ) - { - // convert to R5G5B5A1 - for( int i = 0; i < (int)DDS_full_size; i += block_size ) - { - unsigned short pixel = DDS_data[i] << 0 | DDS_data[i + 1] << 8; - char r = ( ( pixel & header.sPixelFormat.dwRBitMask ) >> 10 ); - char g = ( ( pixel & header.sPixelFormat.dwGBitMask ) >> 5 ); - char b = ( ( pixel & header.sPixelFormat.dwBBitMask ) >> 0 ); - char a = 1; - if( header.sPixelFormat.dwAlphaBitMask != 0 ) - { a = ( pixel & header.sPixelFormat.dwAlphaBitMask ) >> 15; } - unsigned short pixel_new = ( r << 11 ) | ( g << 6 ) | ( b << 1 ) | a; - DDS_data[i] = ( pixel_new >> 0 ) & 0xff; - DDS_data[i + 1] = ( pixel_new >> 8 ) & 0xff; - } - } - else if( block_size == 2 && ( header.sPixelFormat.dwRBitMask == 0xf00 ) && - ( header.sPixelFormat.dwGBitMask == 0xf0 ) && ( header.sPixelFormat.dwBBitMask == 0xf ) && - ( header.sPixelFormat.dwAlphaBitMask == 0xf000 ) ) - { - for( int i = 0; i < (int)DDS_full_size; i += block_size ) - { - unsigned short pixel = DDS_data[i] << 0 | DDS_data[i + 1] << 8; - char r = ( ( pixel & header.sPixelFormat.dwRBitMask ) >> 8 ); - char g = ( ( pixel & header.sPixelFormat.dwGBitMask ) >> 4 ); - char b = ( ( pixel & header.sPixelFormat.dwBBitMask ) >> 0 ); - char a = ( ( pixel & header.sPixelFormat.dwAlphaBitMask ) >> 12 ); - unsigned short pixel_new = ( r << 12 ) | ( g << 8 ) | ( b << 4 ) | a; - DDS_data[i] = ( pixel_new >> 0 ) & 0xff; - DDS_data[i + 1] = ( pixel_new >> 8 ) & 0xff; - } - } - glTexImage2D( cf_target, 0, internal_format, width, height, 0, internal_format, format_type, DDS_data ); - } - else - { - soilGlCompressedTexImage2D( cf_target, 0, internal_format, width, height, 0, DDS_main_size, DDS_data ); - } - /* upload the mipmaps, if we have them */ - for( int i = 1; i <= mipmaps; ++i ) - { - int w, h, mip_size; - w = width >> i; - h = height >> i; - if( w < 1 ) { w = 1; } - if( h < 1 ) { h = 1; } - /* upload this mipmap */ - if( uncompressed ) - { - mip_size = w * h * block_size; - glTexImage2D( cf_target, i, internal_format, w, h, 0, internal_format, format_type, - &DDS_data[byte_offset] ); - } - else - { - mip_size = ( ( w + 3 ) / 4 ) * ( ( h + 3 ) / 4 ) * block_size; - soilGlCompressedTexImage2D( cf_target, i, internal_format, w, h, 0, mip_size, - &DDS_data[byte_offset] ); - } - /* and move to the next mipmap */ - byte_offset += mip_size; - } - /* it worked! */ - result_string_pointer = "DDS file loaded"; - } - else - { - glDeleteTextures( 1, &tex_ID ); - tex_ID = 0; - cf_target = ogl_target_end + 1; - result_string_pointer = "DDS file was too small for expected image data"; - } - } /* end reading each face */ - SOIL_free_image_data( DDS_data ); - if( tex_ID ) - { - /* did I have MIPmaps? */ - if( mipmaps > 0 ) - { - /* instruct OpenGL to use the MIPmaps */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); - } - else - { - /* instruct OpenGL _NOT_ to use the MIPmaps */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - } - /* does the user want clamping, or wrapping? */ - if( flags & SOIL_FLAG_TEXTURE_REPEATS ) - { - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT ); - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT ); - } - else - { - unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; - /* unsigned int clamp_mode = GL_CLAMP; */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode ); - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode ); - } - } - -quick_exit: - return tex_ID; -} - -unsigned int SOIL_direct_load_DDS( - const char *filename, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap ) -{ - FILE *f; - unsigned char *buffer; - size_t buffer_length, bytes_read; - unsigned int tex_ID = 0; - /* error checks */ - if( NULL == filename ) - { - result_string_pointer = "NULL filename"; - return 0; - } - f = fopen( filename, "rb" ); - if( NULL == f ) - { - /* the file doesn't seem to exist (or be open-able) */ - result_string_pointer = "Can not find DDS file"; - return 0; - } - fseek( f, 0, SEEK_END ); - buffer_length = ftell( f ); - fseek( f, 0, SEEK_SET ); - buffer = (unsigned char *) malloc( buffer_length ); - if( NULL == buffer ) - { - result_string_pointer = "malloc failed"; - fclose( f ); - return 0; - } - bytes_read = fread( (void*)buffer, 1, buffer_length, f ); - fclose( f ); - if( bytes_read < buffer_length ) - { - /* huh? */ - buffer_length = bytes_read; - } - /* now try to do the loading */ - tex_ID = SOIL_direct_load_DDS_from_memory( - (const unsigned char *const)buffer, (int)buffer_length, - reuse_texture_ID, flags, loading_as_cubemap ); - SOIL_free_image_data( buffer ); - return tex_ID; -} - -unsigned int SOIL_direct_load_PVR_from_memory( - const unsigned char *const buffer, - int buffer_length, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap ) -{ - PVR_Texture_Header* header = (PVR_Texture_Header*)buffer; - int num_surfs = 1; - GLuint tex_ID = 0; - GLenum PVR_format = 0; - GLenum PVR_type = GL_RGB; - unsigned int opengl_texture_type = loading_as_cubemap ? SOIL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; - int is_PVRTC_supported = query_PVR_capability() == SOIL_CAPABILITY_PRESENT; - int is_BGRA8888_supported = query_BGRA8888_capability() == SOIL_CAPABILITY_PRESENT; - int is_compressed_format_supported = 0; - int is_compressed_format = 0; - int mipmaps = 0; - int i; - GLint unpack_aligment; - - // Check the header size - if ( header->dwHeaderSize != sizeof(PVR_Texture_Header) ) { - if ( header->dwHeaderSize == PVRTEX_V1_HEADER_SIZE ) { - result_string_pointer = "this is an old pvr ( update the PVR file )"; - - if ( loading_as_cubemap ) { - if( header->dwpfFlags & PVRTEX_CUBEMAP ) { - num_surfs = 6; - } else { - result_string_pointer = "tried to load a non-cubemap PVR as cubemap"; - return 0; - } - } - } else { - result_string_pointer = "invalid PVR header"; - - return 0; - } - } else { - if ( loading_as_cubemap ) { - // Header V2 - if( header->dwNumSurfs < 1 ) { - if( header->dwpfFlags & PVRTEX_CUBEMAP ) { - num_surfs = 6; - } else { - result_string_pointer = "tried to load a non-cubemap PVR as cubemap"; - return 0; - } - } else { - num_surfs = header->dwNumSurfs; - } - } - } - - // Check the magic identifier - if ( header->dwPVR != PVRTEX_IDENTIFIER ) { - result_string_pointer = "invalid PVR header"; - return 0; - } - - /* Only accept untwiddled data UNLESS texture format is PVRTC */ - if ( ((header->dwpfFlags & PVRTEX_TWIDDLE) == PVRTEX_TWIDDLE) - && ((header->dwpfFlags & PVRTEX_PIXELTYPE)!=OGL_PVRTC2) - && ((header->dwpfFlags & PVRTEX_PIXELTYPE)!=OGL_PVRTC4) ) - { - // We need to load untwiddled textures -- hw will twiddle for us. - result_string_pointer = "pvr is not compressed ( untwiddled texture )"; - return 0; - } - - switch( header->dwpfFlags & PVRTEX_PIXELTYPE ) - { - case OGL_RGBA_4444: - PVR_format = GL_UNSIGNED_SHORT_4_4_4_4; - PVR_type = GL_RGBA; - break; - case OGL_RGBA_5551: - PVR_format = GL_UNSIGNED_SHORT_5_5_5_1; - PVR_type = GL_RGBA; - break; - case OGL_RGBA_8888: - PVR_format = GL_UNSIGNED_BYTE; - PVR_type = GL_RGBA; - break; - case OGL_RGB_565: - PVR_format = GL_UNSIGNED_SHORT_5_6_5; - PVR_type = GL_RGB; - break; - case OGL_RGB_555: - result_string_pointer = "failed: pixel type OGL_RGB_555 not supported."; - return 0; - case OGL_RGB_888: - PVR_format = GL_UNSIGNED_BYTE; - PVR_type = GL_RGB; - break; - case OGL_I_8: - PVR_format = GL_UNSIGNED_BYTE; - PVR_type = GL_LUMINANCE; - break; - case OGL_AI_88: - PVR_format = GL_UNSIGNED_BYTE; - PVR_type = GL_LUMINANCE_ALPHA; - break; - case MGLPT_PVRTC2: - case OGL_PVRTC2: - if(is_PVRTC_supported) { - is_compressed_format_supported = is_compressed_format = 1; - PVR_format = header->dwAlphaBitMask==0 ? SOIL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG : SOIL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG ; // PVRTC2 - } else { - result_string_pointer = "error: PVRTC2 not supported.Decompress the texture first."; - return 0; - } - break; - case MGLPT_PVRTC4: - case OGL_PVRTC4: - if(is_PVRTC_supported) { - is_compressed_format_supported = is_compressed_format = 1; - PVR_format = header->dwAlphaBitMask==0 ? SOIL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG : SOIL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG ; // PVRTC4 - } else { - result_string_pointer = "error: PVRTC4 not supported. Decompress the texture first."; - return 0; - } - break; - case OGL_BGRA_8888: - if(is_BGRA8888_supported) { - PVR_format = GL_UNSIGNED_BYTE; - PVR_type = GL_BGRA; - break; - } else { - result_string_pointer = "Unable to load GL_BGRA texture as extension GL_IMG_texture_format_BGRA8888 is unsupported."; - return 0; - } - default: // NOT SUPPORTED - result_string_pointer = "failed: pixel type not supported."; - return 0; - } - - #ifdef SOIL_GLES1 - // check that this data is cube map data or not. - if( loading_as_cubemap ) { - result_string_pointer = "cube map textures are not available in GLES1.x."; - return 0; - } - #endif - - // load the texture up - tex_ID = reuse_texture_ID; - if( tex_ID == 0 ) - { - glGenTextures( 1, &tex_ID ); - } - - glBindTexture( opengl_texture_type, tex_ID ); - - if( glGetError() ) { - result_string_pointer = "failed: glBindTexture() failed."; - return 0; - } - - glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_aligment); - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT,1); // Never have row-aligned in headers - } - - #define _MAX( a, b ) (( a <= b )? b : a) - for(i=0; idwHeaderSize + header->dwTextureDataSize * i; - char *cur_texture_ptr = 0; - int mipmap_level; - unsigned int width= header->dwWidth, height = header->dwHeight; - unsigned int compressed_image_size = 0; - - mipmaps = ( ( flags & SOIL_FLAG_MIPMAPS ) && (header->dwpfFlags & PVRTEX_MIPMAP) ) ? header->dwMipMapCount : 0; - - for(mipmap_level = 0; mipmap_level <= mipmaps; width = _MAX(width/2, (unsigned int)1), height = _MAX(height/2, (unsigned int)1), mipmap_level++ ) { - // Do Alpha-swap if needed - cur_texture_ptr = texture_ptr; - - // Load the Texture - /* If the texture is PVRTC then use GLCompressedTexImage2D */ - if( is_compressed_format ) { - /* Calculate how many bytes this MIP level occupies */ - if ((header->dwpfFlags & PVRTEX_PIXELTYPE)==OGL_PVRTC2) { - compressed_image_size = ( _MAX(width, PVRTC2_MIN_TEXWIDTH) * _MAX(height, PVRTC2_MIN_TEXHEIGHT) * header->dwBitCount + 7 ) / 8; - } else {// PVRTC4 case - compressed_image_size = ( _MAX(width, PVRTC4_MIN_TEXWIDTH) * _MAX(height, PVRTC4_MIN_TEXHEIGHT) * header->dwBitCount + 7 ) / 8; - } - - if ( is_compressed_format_supported ) { - /* Load compressed texture data at selected MIP level */ - if ( loading_as_cubemap ) { - soilGlCompressedTexImage2D( SOIL_TEXTURE_CUBE_MAP_POSITIVE_X + i, mipmap_level, PVR_format, width, height, 0, compressed_image_size, cur_texture_ptr ); - } else { - soilGlCompressedTexImage2D( opengl_texture_type, mipmap_level, PVR_format, width, height, 0, compressed_image_size, cur_texture_ptr ); - } - } else { - result_string_pointer = "failed: GPU doesnt support compressed textures"; - } - } else { - /* Load uncompressed texture data at selected MIP level */ - if ( loading_as_cubemap ) { - glTexImage2D( SOIL_TEXTURE_CUBE_MAP_POSITIVE_X + i, mipmap_level, PVR_type, width, height, 0, PVR_type, PVR_format, cur_texture_ptr ); - } else { - glTexImage2D( opengl_texture_type, mipmap_level, PVR_type, width, height, 0, PVR_type, PVR_format, cur_texture_ptr ); - } - } - - if( glGetError() ) { - result_string_pointer = "failed: glCompressedTexImage2D() failed."; - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_aligment); - } - return 0; - } - - // offset the texture pointer by one mip-map level - /* PVRTC case */ - if ( is_compressed_format ) { - texture_ptr += compressed_image_size; - } else { - /* New formula that takes into account bit counts inferior to 8 (e.g. 1 bpp) */ - texture_ptr += (width * height * header->dwBitCount + 7) / 8; - } - } - } - #undef _MAX - - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_aligment); - } - - if( tex_ID ) - { - /* did I have MIPmaps? */ - if( mipmaps ) - { - /* instruct OpenGL to use the MIPmaps */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); - } else - { - /* instruct OpenGL _NOT_ to use the MIPmaps */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - } - - /* does the user want clamping, or wrapping? */ - if( flags & SOIL_FLAG_TEXTURE_REPEATS ) - { - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT ); - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT ); - } else - { - unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; - /* unsigned int clamp_mode = GL_CLAMP; */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode ); - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode ); - } - } - - return tex_ID; -} - -unsigned int SOIL_direct_load_PVR( - const char *filename, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap ) -{ - FILE *f; - unsigned char *buffer; - size_t buffer_length, bytes_read; - unsigned int tex_ID = 0; - /* error checks */ - if( NULL == filename ) - { - result_string_pointer = "NULL filename"; - return 0; - } - f = fopen( filename, "rb" ); - if( NULL == f ) - { - /* the file doesn't seem to exist (or be open-able) */ - result_string_pointer = "Can not find PVR file"; - return 0; - } - fseek( f, 0, SEEK_END ); - buffer_length = ftell( f ); - fseek( f, 0, SEEK_SET ); - buffer = (unsigned char *) malloc( buffer_length ); - if( NULL == buffer ) - { - result_string_pointer = "malloc failed"; - fclose( f ); - return 0; - } - bytes_read = fread( (void*)buffer, 1, buffer_length, f ); - fclose( f ); - if( bytes_read < buffer_length ) - { - /* huh? */ - buffer_length = bytes_read; - } - /* now try to do the loading */ - tex_ID = SOIL_direct_load_PVR_from_memory( - (const unsigned char *const)buffer, (int)buffer_length, - reuse_texture_ID, flags, loading_as_cubemap ); - SOIL_free_image_data( buffer ); - return tex_ID; -} - -unsigned int SOIL_direct_load_ETC1_from_memory( - const unsigned char *const buffer, - int buffer_length, - unsigned int reuse_texture_ID, - int flags ) -{ - GLuint tex_ID = 0; - PKMHeader* header = (PKMHeader*)buffer; - unsigned int opengl_texture_type = GL_TEXTURE_2D; - unsigned int width; - unsigned int height; - unsigned long compressed_image_size = buffer_length - PKM_HEADER_SIZE; - char *texture_ptr = (char*)buffer + PKM_HEADER_SIZE; - GLint unpack_aligment; - - if ( query_ETC1_capability() != SOIL_CAPABILITY_PRESENT ) { - result_string_pointer = "error: ETC1 not supported. Decompress the texture first."; - return 0; - } - - if ( 0 != strcmp( header->aName, "PKM 10" ) ) { - result_string_pointer = "error: PKM 10 header not found."; - return 0; - } - - width = (header->iWidthMSB << 8) | header->iWidthLSB; - height = (header->iHeightMSB << 8) | header->iHeightLSB; - compressed_image_size = (((width + 3) & ~3) * ((height + 3) & ~3)) >> 1; - - // load the texture up - tex_ID = reuse_texture_ID; - if( tex_ID == 0 ) - { - glGenTextures( 1, &tex_ID ); - } - - glBindTexture( opengl_texture_type, tex_ID ); - - if( glGetError() ) { - result_string_pointer = "failed: glBindTexture() failed."; - return 0; - } - - glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_aligment); - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT,1); // Never have row-aligned in headers - } - - soilGlCompressedTexImage2D( opengl_texture_type, 0, SOIL_GL_ETC1_RGB8_OES, width, height, 0, compressed_image_size, texture_ptr ); - - if( glGetError() ) { - result_string_pointer = "failed: glCompressedTexImage2D() failed."; - - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_aligment); - } - return 0; - } - - if ( 1 != unpack_aligment ) - { - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_aligment); - } - - if( tex_ID ) - { - /* No MIPmaps for ETC1 */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - - /* does the user want clamping, or wrapping? */ - if( flags & SOIL_FLAG_TEXTURE_REPEATS ) - { - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT ); - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT ); - } else - { - unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; - /* unsigned int clamp_mode = GL_CLAMP; */ - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode ); - glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode ); - glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode ); - } - } - - return tex_ID; -} - -unsigned int SOIL_direct_load_ETC1(const char *filename, - unsigned int reuse_texture_ID, - int flags ) -{ - FILE *f; - unsigned char *buffer; - size_t buffer_length, bytes_read; - unsigned int tex_ID = 0; - /* error checks */ - if( NULL == filename ) - { - result_string_pointer = "NULL filename"; - return 0; - } - f = fopen( filename, "rb" ); - if( NULL == f ) - { - /* the file doesn't seem to exist (or be open-able) */ - result_string_pointer = "Can not find PVR file"; - return 0; - } - fseek( f, 0, SEEK_END ); - buffer_length = ftell( f ); - fseek( f, 0, SEEK_SET ); - buffer = (unsigned char *) malloc( buffer_length ); - if( NULL == buffer ) - { - result_string_pointer = "malloc failed"; - fclose( f ); - return 0; - } - bytes_read = fread( (void*)buffer, 1, buffer_length, f ); - fclose( f ); - if( bytes_read < buffer_length ) - { - /* huh? */ - buffer_length = bytes_read; - } - /* now try to do the loading */ - tex_ID = SOIL_direct_load_ETC1_from_memory( - (const unsigned char *const)buffer, (int)buffer_length, - reuse_texture_ID, flags ); - SOIL_free_image_data( buffer ); - return tex_ID; -} - -int query_NPOT_capability( void ) -{ - /* check for the capability */ - if( has_NPOT_capability == SOIL_CAPABILITY_UNKNOWN ) - { - /* we haven't yet checked for the capability, do so */ - if( (0 == SOIL_GL_ExtensionSupported( "GL_ARB_texture_non_power_of_two" ) ) && - (0 == SOIL_GL_ExtensionSupported( "GL_OES_texture_npot" ) ) && - !isAtLeastGL3() - ) - { - /* not there, flag the failure */ - has_NPOT_capability = SOIL_CAPABILITY_NONE; - } else - { - /* it's there! */ - has_NPOT_capability = SOIL_CAPABILITY_PRESENT; - } - - #if defined( __emscripten__ ) || defined( EMSCRIPTEN ) - has_NPOT_capability = SOIL_CAPABILITY_PRESENT; - #endif - } - /* let the user know if we can do non-power-of-two textures or not */ - return has_NPOT_capability; -} - -int query_tex_rectangle_capability( void ) -{ - /* check for the capability */ - if( has_tex_rectangle_capability == SOIL_CAPABILITY_UNKNOWN ) - { - /* we haven't yet checked for the capability, do so */ - if( - (0 == SOIL_GL_ExtensionSupported( "GL_ARB_texture_rectangle" ) ) && - (0 == SOIL_GL_ExtensionSupported( "GL_EXT_texture_rectangle" ) ) && - (0 == SOIL_GL_ExtensionSupported( "GL_NV_texture_rectangle" ) ) && - !isAtLeastGL3() ) - { - /* not there, flag the failure */ - has_tex_rectangle_capability = SOIL_CAPABILITY_NONE; - } else - { - /* it's there! */ - has_tex_rectangle_capability = SOIL_CAPABILITY_PRESENT; - } - } - /* let the user know if we can do texture rectangles or not */ - return has_tex_rectangle_capability; -} - -int query_cubemap_capability( void ) -{ - /* check for the capability */ - if( has_cubemap_capability == SOIL_CAPABILITY_UNKNOWN ) - { - /* we haven't yet checked for the capability, do so */ - if( - (0 == SOIL_GL_ExtensionSupported( "GL_ARB_texture_cube_map" ) ) && - (0 == SOIL_GL_ExtensionSupported( "GL_EXT_texture_cube_map" ) ) && - !isAtLeastGL3() - ) - { - /* not there, flag the failure */ - has_cubemap_capability = SOIL_CAPABILITY_NONE; - } else - { - /* it's there! */ - has_cubemap_capability = SOIL_CAPABILITY_PRESENT; - } - } - /* let the user know if we can do cubemaps or not */ - return has_cubemap_capability; -} - -static P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC get_glCompressedTexImage2D_addr() -{ - /* and find the address of the extension function */ - P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC ext_addr = NULL; - -#if defined( SOIL_PLATFORM_WIN32 ) || defined( SOIL_PLATFORM_OSX ) || defined( SOIL_X11_PLATFORM ) - ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)SOIL_GL_GetProcAddress( "glCompressedTexImage2D" ); -#else - ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)&glCompressedTexImage2D; -#endif - - return ext_addr; -} - -int query_DXT_capability( void ) -{ - /* check for the capability */ - if( has_DXT_capability == SOIL_CAPABILITY_UNKNOWN ) - { - /* we haven't yet checked for the capability, do so */ - if ( 0 == SOIL_GL_ExtensionSupported( - "GL_EXT_texture_compression_s3tc" ) && - 0 == SOIL_GL_ExtensionSupported( - "WEBGL_compressed_texture_s3tc ") && - 0 == SOIL_GL_ExtensionSupported( - "WEBKIT_WEBGL_compressed_texture_s3tc") && - 0 == SOIL_GL_ExtensionSupported( - "MOZ_WEBGL_compressed_texture_s3tc" - ) - ) - { - /* not there, flag the failure */ - has_DXT_capability = SOIL_CAPABILITY_NONE; - } else - { - P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC ext_addr = get_glCompressedTexImage2D_addr(); - - /* Flag it so no checks needed later */ - if( NULL == ext_addr ) - { - /* hmm, not good!! This should not happen, but does on my - laptop's VIA chipset. The GL_EXT_texture_compression_s3tc - spec requires that ARB_texture_compression be present too. - this means I can upload and have the OpenGL drive do the - conversion, but I can't use my own routines or load DDS files - from disk and upload them directly [8^( */ - has_DXT_capability = SOIL_CAPABILITY_NONE; - } else - { - /* all's well! */ - soilGlCompressedTexImage2D = ext_addr; - has_DXT_capability = SOIL_CAPABILITY_PRESENT; - } - } - } - /* let the user know if we can do DXT or not */ - return has_DXT_capability; -} - -int query_3Dc_capability(void) { - /* check for the capability */ - if (has_3Dc_capability == SOIL_CAPABILITY_UNKNOWN) - { - /* we haven't yet checked for the capability, do so */ - if (0 == SOIL_GL_ExtensionSupported( - "ARB_texture_compression_rgtc") && - 0 == SOIL_GL_ExtensionSupported( - "GL_ARB_texture_compression_rgtc") && - 0 == SOIL_GL_ExtensionSupported( - "GL_EXT_texture_compression_rgtc") - ) { - /* not there, flag the failure */ - has_3Dc_capability = SOIL_CAPABILITY_NONE; - } else - { - P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC ext_addr = get_glCompressedTexImage2D_addr(); - - /* Flag it so no checks needed later */ - if (NULL == ext_addr) - { - /* hmm, not good!! This should not happen, but does on my - laptop's VIA chipset. The GL_EXT_texture_compression_s3tc - spec requires that ARB_texture_compression be present too. - this means I can upload and have the OpenGL drive do the - conversion, but I can't use my own routines or load DDS files - from disk and upload them directly [8^( */ - has_3Dc_capability = SOIL_CAPABILITY_NONE; - } else - { - /* all's well! */ - soilGlCompressedTexImage2D = ext_addr; - has_3Dc_capability = SOIL_CAPABILITY_PRESENT; - } - } - } - /* let the user know if we can do DXT or not */ - return has_3Dc_capability; -} - -int query_PVR_capability( void ) -{ - /* check for the capability */ - if( has_PVR_capability == SOIL_CAPABILITY_UNKNOWN ) - { - /* we haven't yet checked for the capability, do so */ - if (0 == SOIL_GL_ExtensionSupported( - "GL_IMG_texture_compression_pvrtc" ) ) - { - /* not there, flag the failure */ - has_PVR_capability = SOIL_CAPABILITY_NONE; - } else - { - if ( NULL == soilGlCompressedTexImage2D ) { - soilGlCompressedTexImage2D = get_glCompressedTexImage2D_addr(); - } - - /* it's there! */ - has_PVR_capability = SOIL_CAPABILITY_PRESENT; - } - } - /* let the user know if we can do cubemaps or not */ - return has_PVR_capability; -} - -int query_BGRA8888_capability( void ) -{ - /* check for the capability */ - if( has_BGRA8888_capability == SOIL_CAPABILITY_UNKNOWN ) - { - /* we haven't yet checked for the capability, do so */ - if (0 == SOIL_GL_ExtensionSupported( - "GL_IMG_texture_format_BGRA8888" ) ) - { - /* not there, flag the failure */ - has_BGRA8888_capability = SOIL_CAPABILITY_NONE; - } else - { - /* it's there! */ - has_BGRA8888_capability = SOIL_CAPABILITY_PRESENT; - } - } - /* let the user know if we can do cubemaps or not */ - return has_BGRA8888_capability; -} - -int query_sRGB_capability( void ) -{ - if ( has_sRGB_capability == SOIL_CAPABILITY_UNKNOWN ) - { - if (0 == SOIL_GL_ExtensionSupported( "GL_EXT_texture_sRGB" ) && - 0 == SOIL_GL_ExtensionSupported( "GL_EXT_sRGB" ) && - 0 == SOIL_GL_ExtensionSupported( "EXT_sRGB" ) && - !isAtLeastGL3() - ) - { - has_sRGB_capability = SOIL_CAPABILITY_NONE; - } else - { - has_sRGB_capability = SOIL_CAPABILITY_PRESENT; - } - } - - return has_sRGB_capability; -} - -int query_ETC1_capability( void ) -{ - /* check for the capability */ - if( has_ETC1_capability == SOIL_CAPABILITY_UNKNOWN ) - { - /* we haven't yet checked for the capability, do so */ - if (0 == SOIL_GL_ExtensionSupported( - "GL_OES_compressed_ETC1_RGB8_texture" ) ) - { - /* not there, flag the failure */ - has_ETC1_capability = SOIL_CAPABILITY_NONE; - } else - { - if ( NULL == soilGlCompressedTexImage2D ) { - soilGlCompressedTexImage2D = get_glCompressedTexImage2D_addr(); - } - - /* it's there! */ - has_ETC1_capability = SOIL_CAPABILITY_PRESENT; - } - } - /* let the user know if we can do cubemaps or not */ - return has_ETC1_capability; -} - -int query_gen_mipmap_capability( void ) -{ - /* check for the capability */ - P_SOIL_GLGENERATEMIPMAPPROC ext_addr = NULL; - - if( has_gen_mipmap_capability == SOIL_CAPABILITY_UNKNOWN ) - { - if ( 0 == SOIL_GL_ExtensionSupported( "GL_ARB_framebuffer_object" ) && - 0 == SOIL_GL_ExtensionSupported( "GL_EXT_framebuffer_object" ) && - 0 == SOIL_GL_ExtensionSupported( "GL_OES_framebuffer_object" ) && - !isAtLeastGL3() - ) - { - /* not there, flag the failure */ - has_gen_mipmap_capability = SOIL_CAPABILITY_NONE; - } - else - { - #if !defined( SOIL_GLES1 ) && !defined( SOIL_GLES2 ) - - ext_addr = (P_SOIL_GLGENERATEMIPMAPPROC)SOIL_GL_GetProcAddress("glGenerateMipmap"); - - if(ext_addr == NULL) - { - ext_addr = (P_SOIL_GLGENERATEMIPMAPPROC)SOIL_GL_GetProcAddress("glGenerateMipmapEXT"); - } - - #elif !defined( SOIL_NO_EGL ) - - ext_addr = (P_SOIL_GLGENERATEMIPMAPPROC)SOIL_GL_GetProcAddress("glGenerateMipmapOES"); - - if(ext_addr == NULL) - { - ext_addr = (P_SOIL_GLGENERATEMIPMAPPROC)SOIL_GL_GetProcAddress("glGenerateMipmap"); - } - - #elif defined( SOIL_GLES2 ) - ext_addr = &glGenerateMipmap; - #else /** SOIL_GLES1 */ - ext_addr = &glGenerateMipmapOES; - #endif - } - - if(ext_addr == NULL) - { - /* this should never happen */ - has_gen_mipmap_capability = SOIL_CAPABILITY_NONE; - } else - { - /* it's there! */ - has_gen_mipmap_capability = SOIL_CAPABILITY_PRESENT; - soilGlGenerateMipmap = ext_addr; - } - } - - return has_gen_mipmap_capability; -} diff --git a/vendor/SOIL2/src/SOIL2/SOIL2.h b/vendor/SOIL2/src/SOIL2/SOIL2.h deleted file mode 100755 index 941103cef7..0000000000 --- a/vendor/SOIL2/src/SOIL2/SOIL2.h +++ /dev/null @@ -1,554 +0,0 @@ -/** - @mainpage SOIL2 - - Fork by Martin Lucas Golini - - Original author Jonathan Dummer - 2007-07-26-10.36 - - Simple OpenGL Image Library 2 - - A tiny c library for uploading images as - textures into OpenGL. Also saving and - loading of images is supported. - - I'm using Sean's Tool Box image loader as a base: - http://www.nothings.org/ - - I'm upgrading it to load TGA and DDS files, and a direct - path for loading DDS files straight into OpenGL textures, - when applicable. - - Image Formats: - - BMP load & save - - TGA load & save - - DDS load & save - - PNG load & save - - JPG load & save - - QOI load & save - - PSD load - - HDR load - - PIC load - - OpenGL Texture Features: - - resample to power-of-two sizes - - MIPmap generation - - compressed texture S3TC formats (if supported) - - can pre-multiply alpha for you, for better compositing - - can flip image about the y-axis (except pre-compressed DDS files) - - Thanks to: - * Sean Barret - for the awesome stb_image - * Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts - * everybody at gamedev.net -**/ - -#ifndef HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY -#define HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOIL_MAJOR_VERSION 1 -#define SOIL_MINOR_VERSION 3 -#define SOIL_PATCH_LEVEL 0 - -#define SOIL_VERSION_NUM( X, Y, Z ) ( (X)*1000 + (Y)*100 + ( Z ) ) - -#define SOIL_COMPILED_VERSION \ - SOIL_VERSION_NUM( SOIL_MAJOR_VERSION, SOIL_MINOR_VERSION, SOIL_PATCH_LEVEL ) - -#define SOIL_VERSION_ATLEAST( X, Y, Z ) ( SOIL_COMPILED_VERSION >= SOIL_VERSION_NUM( X, Y, Z ) ) - - unsigned long SOIL_version(); - -/** - The format of images that may be loaded (force_channels). - SOIL_LOAD_AUTO leaves the image in whatever format it was found. - SOIL_LOAD_L forces the image to load as Luminous (greyscale) - SOIL_LOAD_LA forces the image to load as Luminous with Alpha - SOIL_LOAD_RGB forces the image to load as Red Green Blue - SOIL_LOAD_RGBA forces the image to load as Red Green Blue Alpha -**/ -enum -{ - SOIL_LOAD_AUTO = 0, - SOIL_LOAD_L = 1, - SOIL_LOAD_LA = 2, - SOIL_LOAD_RGB = 3, - SOIL_LOAD_RGBA = 4 -}; - -/** - Passed in as reuse_texture_ID, will cause SOIL to - register a new texture ID using glGenTextures(). - If the value passed into reuse_texture_ID > 0 then - SOIL will just re-use that texture ID (great for - reloading image assets in-game!) -**/ -enum -{ - SOIL_CREATE_NEW_ID = 0 -}; - -/** - flags you can pass into SOIL_load_OGL_texture() - and SOIL_create_OGL_texture(). - (note that if SOIL_FLAG_DDS_LOAD_DIRECT is used - the rest of the flags with the exception of - SOIL_FLAG_TEXTURE_REPEATS will be ignored while - loading already-compressed DDS files.) - - SOIL_FLAG_POWER_OF_TWO: force the image to be POT - SOIL_FLAG_MIPMAPS: generate mipmaps for the texture - SOIL_FLAG_TEXTURE_REPEATS: otherwise will clamp - SOIL_FLAG_MULTIPLY_ALPHA: for using (GL_ONE,GL_ONE_MINUS_SRC_ALPHA) blending - SOIL_FLAG_INVERT_Y: flip the image vertically - SOIL_FLAG_COMPRESS_TO_DXT: if the card can display them, will convert RGB to DXT1, RGBA to DXT5 - SOIL_FLAG_DDS_LOAD_DIRECT: will load DDS files directly without _ANY_ additional processing ( if supported ) - SOIL_FLAG_NTSC_SAFE_RGB: clamps RGB components to the range [16,235] - SOIL_FLAG_CoCg_Y: Google YCoCg; RGB=>CoYCg, RGBA=>CoCgAY - SOIL_FLAG_TEXTURE_RECTANGE: uses ARB_texture_rectangle ; pixel indexed & no repeat or MIPmaps or cubemaps - SOIL_FLAG_PVR_LOAD_DIRECT: will load PVR files directly without _ANY_ additional processing ( if supported ) -**/ -enum -{ - SOIL_FLAG_POWER_OF_TWO = 1, - SOIL_FLAG_MIPMAPS = 2, - SOIL_FLAG_TEXTURE_REPEATS = 4, - SOIL_FLAG_MULTIPLY_ALPHA = 8, - SOIL_FLAG_INVERT_Y = 16, - SOIL_FLAG_COMPRESS_TO_DXT = 32, - SOIL_FLAG_DDS_LOAD_DIRECT = 64, - SOIL_FLAG_NTSC_SAFE_RGB = 128, - SOIL_FLAG_CoCg_Y = 256, - SOIL_FLAG_TEXTURE_RECTANGLE = 512, - SOIL_FLAG_PVR_LOAD_DIRECT = 1024, - SOIL_FLAG_ETC1_LOAD_DIRECT = 2048, - SOIL_FLAG_GL_MIPMAPS = 4096, - SOIL_FLAG_SRGB_COLOR_SPACE = 8192 -}; - -/** - The types of images that may be saved. - (TGA supports uncompressed RGB / RGBA) - (BMP supports uncompressed RGB) - (DDS supports DXT1 and DXT5) - (PNG supports RGB / RGBA) -**/ -enum -{ - SOIL_SAVE_TYPE_TGA = 0, - SOIL_SAVE_TYPE_BMP = 1, - SOIL_SAVE_TYPE_PNG = 2, - SOIL_SAVE_TYPE_DDS = 3, - SOIL_SAVE_TYPE_JPG = 4, - SOIL_SAVE_TYPE_QOI = 5 -}; - -/** - Defines the order of faces in a DDS cubemap. - I recommend that you use the same order in single - image cubemap files, so they will be interchangeable - with DDS cubemaps when using SOIL. -**/ -#define SOIL_DDS_CUBEMAP_FACE_ORDER "EWUDNS" - -/** - The types of internal fake HDR representations - - SOIL_HDR_RGBE: RGB * pow( 2.0, A - 128.0 ) - SOIL_HDR_RGBdivA: RGB / A - SOIL_HDR_RGBdivA2: RGB / (A*A) -**/ -enum -{ - SOIL_HDR_RGBE = 0, - SOIL_HDR_RGBdivA = 1, - SOIL_HDR_RGBdivA2 = 2 -}; - -/** - Loads an image from disk into an OpenGL texture. - \param filename the name of the file to upload as a texture - \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_load_OGL_texture - ( - const char *filename, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Loads 6 images from disk into an OpenGL cubemap texture. - \param x_pos_file the name of the file to upload as the +x cube face - \param x_neg_file the name of the file to upload as the -x cube face - \param y_pos_file the name of the file to upload as the +y cube face - \param y_neg_file the name of the file to upload as the -y cube face - \param z_pos_file the name of the file to upload as the +z cube face - \param z_neg_file the name of the file to upload as the -z cube face - \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_load_OGL_cubemap - ( - const char *x_pos_file, - const char *x_neg_file, - const char *y_pos_file, - const char *y_neg_file, - const char *z_pos_file, - const char *z_neg_file, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Loads 1 image from disk and splits it into an OpenGL cubemap texture. - \param filename the name of the file to upload as a texture - \param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc. - \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_load_OGL_single_cubemap - ( - const char *filename, - const char face_order[6], - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Loads an HDR image from disk into an OpenGL texture. - \param filename the name of the file to upload as a texture - \param fake_HDR_format SOIL_HDR_RGBE, SOIL_HDR_RGBdivA, SOIL_HDR_RGBdivA2 - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_load_OGL_HDR_texture - ( - const char *filename, - int fake_HDR_format, - int rescale_to_max, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Loads an image from RAM into an OpenGL texture. - \param buffer the image data in RAM just as if it were still in a file - \param buffer_length the size of the buffer in bytes - \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_load_OGL_texture_from_memory - ( - const unsigned char *const buffer, - int buffer_length, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Loads 6 images from memory into an OpenGL cubemap texture. - \param x_pos_buffer the image data in RAM to upload as the +x cube face - \param x_pos_buffer_length the size of the above buffer - \param x_neg_buffer the image data in RAM to upload as the +x cube face - \param x_neg_buffer_length the size of the above buffer - \param y_pos_buffer the image data in RAM to upload as the +x cube face - \param y_pos_buffer_length the size of the above buffer - \param y_neg_buffer the image data in RAM to upload as the +x cube face - \param y_neg_buffer_length the size of the above buffer - \param z_pos_buffer the image data in RAM to upload as the +x cube face - \param z_pos_buffer_length the size of the above buffer - \param z_neg_buffer the image data in RAM to upload as the +x cube face - \param z_neg_buffer_length the size of the above buffer - \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_load_OGL_cubemap_from_memory - ( - const unsigned char *const x_pos_buffer, - int x_pos_buffer_length, - const unsigned char *const x_neg_buffer, - int x_neg_buffer_length, - const unsigned char *const y_pos_buffer, - int y_pos_buffer_length, - const unsigned char *const y_neg_buffer, - int y_neg_buffer_length, - const unsigned char *const z_pos_buffer, - int z_pos_buffer_length, - const unsigned char *const z_neg_buffer, - int z_neg_buffer_length, - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Loads 1 image from RAM and splits it into an OpenGL cubemap texture. - \param buffer the image data in RAM just as if it were still in a file - \param buffer_length the size of the buffer in bytes - \param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc. - \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_load_OGL_single_cubemap_from_memory - ( - const unsigned char *const buffer, - int buffer_length, - const char face_order[6], - int force_channels, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Creates a 2D OpenGL texture from raw image data. Note that the raw data is - _NOT_ freed after the upload (so the user can load various versions). - \param data the raw data to be uploaded as an OpenGL texture - \param width the pointer of the width of the image in pixels ( if the texture size change, width will be overrided with the new width ) - \param height the pointer of the height of the image in pixels ( if the texture size change, height will be overrided with the new height ) - \param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_create_OGL_texture - ( - const unsigned char *const data, - int *width, int *height, int channels, - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Creates an OpenGL cubemap texture by splitting up 1 image into 6 parts. - \param data the raw data to be uploaded as an OpenGL texture - \param width the width of the image in pixels - \param height the height of the image in pixels - \param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA - \param face_order the order of the faces in the file, and combination of NSWEUD, for North, South, Up, etc. - \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) - \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT - \return 0-failed, otherwise returns the OpenGL texture handle -**/ -unsigned int - SOIL_create_OGL_single_cubemap - ( - const unsigned char *const data, - int width, int height, int channels, - const char face_order[6], - unsigned int reuse_texture_ID, - unsigned int flags - ); - -/** - Captures the OpenGL window (RGB) and saves it to disk - \return 0 if it failed, otherwise returns 1 -**/ -int - SOIL_save_screenshot - ( - const char *filename, - int image_type, - int x, int y, - int width, int height - ); - -/** - Loads an image from disk into an array of unsigned chars. - Note that *channels return the original channel count of the - image. If force_channels was other than SOIL_LOAD_AUTO, - the resulting image has force_channels, but *channels may be - different (if the original image had a different channel - count). - \return 0 if failed, otherwise returns 1 -**/ -unsigned char* - SOIL_load_image - ( - const char *filename, - int *width, int *height, int *channels, - int force_channels - ); - -/** - Loads an image from memory into an array of unsigned chars. - Note that *channels return the original channel count of the - image. If force_channels was other than SOIL_LOAD_AUTO, - the resulting image has force_channels, but *channels may be - different (if the original image had a different channel - count). - \return 0 if failed, otherwise returns 1 -**/ -unsigned char* - SOIL_load_image_from_memory - ( - const unsigned char *const buffer, - int buffer_length, - int *width, int *height, int *channels, - int force_channels - ); - -/** - Saves an image from an array of unsigned chars (RGBA) to disk - \param quality parameter only used for SOIL_SAVE_TYPE_JPG files, values accepted between 0 and 100. - \return 0 if failed, otherwise returns 1 -**/ -int - SOIL_save_image_quality - ( - const char *filename, - int image_type, - int width, int height, int channels, - const unsigned char *const data, - int quality - ); - -int - SOIL_save_image - ( - const char *filename, - int image_type, - int width, int height, int channels, - const unsigned char *const data - ); - - -/** - Saves an image from an array of unsigned chars (RGBA) to a memory buffer in the target format. - Free the buffer with SOIL_free_image_data. - \param quality parameter only used for SOIL_SAVE_TYPE_JPG files, values accepted between 0 and 100. - \param imageSize returns the byte count of the image. - \return 0 if failed, otherwise returns 1 -**/ - -unsigned char* -SOIL_write_image_to_memory_quality -( - int image_type, - int width, int height, int channels, - const unsigned char* const data, - int quality, - int* imageSize -); - -unsigned char* -SOIL_write_image_to_memory -( - int image_type, - int width, int height, int channels, - const unsigned char* const data, - int* imageSize -); - -/** - Frees the image data (note, this is just C's "free()"...this function is - present mostly so C++ programmers don't forget to use "free()" and call - "delete []" instead [8^) -**/ -void - SOIL_free_image_data - ( - unsigned char *img_data - ); - -/** - This function resturn a pointer to a string describing the last thing - that happened inside SOIL. It can be used to determine why an image - failed to load. -**/ -const char* - SOIL_last_result - ( - void - ); - -/** @return The address of the GL function proc, or NULL if the function is not found. */ -void * - SOIL_GL_GetProcAddress - ( - const char *proc - ); - -/** @return 1 if an OpenGL extension is supported for the current context, 0 otherwise. */ -int - SOIL_GL_ExtensionSupported - ( - const char *extension - ); - -/** Loads the DDS texture directly to the GPU memory ( if supported ) */ -unsigned int SOIL_direct_load_DDS( - const char *filename, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap ); - -/** Loads the DDS texture directly to the GPU memory ( if supported ) */ -unsigned int SOIL_direct_load_DDS_from_memory( - const unsigned char *const buffer, - int buffer_length, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap ); - -/** Loads the PVR texture directly to the GPU memory ( if supported ) */ -unsigned int SOIL_direct_load_PVR( - const char *filename, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap ); - -/** Loads the PVR texture directly to the GPU memory ( if supported ) */ -unsigned int SOIL_direct_load_PVR_from_memory( - const unsigned char *const buffer, - int buffer_length, - unsigned int reuse_texture_ID, - int flags, - int loading_as_cubemap ); - -/** Loads the PVR texture directly to the GPU memory ( if supported ) */ -unsigned int SOIL_direct_load_ETC1(const char *filename, - unsigned int reuse_texture_ID, - int flags ); - -/** Loads the PVR texture directly to the GPU memory ( if supported ) */ -unsigned int SOIL_direct_load_ETC1_from_memory(const unsigned char *const buffer, - int buffer_length, - unsigned int reuse_texture_ID, - int flags ); - -#ifdef __cplusplus -} -#endif - -#endif /* HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY */ diff --git a/vendor/SOIL2/src/SOIL2/image_helper.c b/vendor/SOIL2/src/SOIL2/image_helper.c deleted file mode 100755 index 12c701ee68..0000000000 --- a/vendor/SOIL2/src/SOIL2/image_helper.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - Jonathan Dummer - - image helper functions - - MIT license -*/ - -#include "image_helper.h" -#include -#include - -/* Upscaling the image uses simple bilinear interpolation */ -int - up_scale_image - ( - const unsigned char* const orig, - int width, int height, int channels, - unsigned char* resampled, - int resampled_width, int resampled_height - ) -{ - float dx, dy; - int x, y, c; - - /* error(s) check */ - if ( (width < 1) || (height < 1) || - (resampled_width < 2) || (resampled_height < 2) || - (channels < 1) || - (NULL == orig) || (NULL == resampled) ) - { - /* signify badness */ - return 0; - } - /* - for each given pixel in the new map, find the exact location - from the original map which would contribute to this guy - */ - dx = (width - 1.0f) / (resampled_width - 1.0f); - dy = (height - 1.0f) / (resampled_height - 1.0f); - for ( y = 0; y < resampled_height; ++y ) - { - /* find the base y index and fractional offset from that */ - float sampley = y * dy; - int inty = (int)sampley; - /* if( inty < 0 ) { inty = 0; } else */ - if( inty > height - 2 ) { inty = height - 2; } - sampley -= inty; - for ( x = 0; x < resampled_width; ++x ) - { - float samplex = x * dx; - int intx = (int)samplex; - int base_index; - /* find the base x index and fractional offset from that */ - /* if( intx < 0 ) { intx = 0; } else */ - if( intx > width - 2 ) { intx = width - 2; } - samplex -= intx; - /* base index into the original image */ - base_index = (inty * width + intx) * channels; - for ( c = 0; c < channels; ++c ) - { - /* do the sampling */ - float value = 0.5f; - value += orig[base_index] - *(1.0f-samplex)*(1.0f-sampley); - value += orig[base_index+channels] - *(samplex)*(1.0f-sampley); - value += orig[base_index+width*channels] - *(1.0f-samplex)*(sampley); - value += orig[base_index+width*channels+channels] - *(samplex)*(sampley); - /* move to the next channel */ - ++base_index; - /* save the new value */ - resampled[y*resampled_width*channels+x*channels+c] = - (unsigned char)(value); - } - } - } - /* done */ - return 1; -} - -int - mipmap_image - ( - const unsigned char* const orig, - int width, int height, int channels, - unsigned char* resampled, - int block_size_x, int block_size_y - ) -{ - int mip_width, mip_height; - int i, j, c; - - /* error check */ - if( (width < 1) || (height < 1) || - (channels < 1) || (orig == NULL) || - (resampled == NULL) || - (block_size_x < 1) || (block_size_y < 1) ) - { - /* nothing to do */ - return 0; - } - mip_width = width / block_size_x; - mip_height = height / block_size_y; - if( mip_width < 1 ) - { - mip_width = 1; - } - if( mip_height < 1 ) - { - mip_height = 1; - } - for( j = 0; j < mip_height; ++j ) - { - for( i = 0; i < mip_width; ++i ) - { - for( c = 0; c < channels; ++c ) - { - const int index = (j*block_size_y)*width*channels + (i*block_size_x)*channels + c; - int sum_value; - int u,v; - int u_block = block_size_x; - int v_block = block_size_y; - int block_area; - /* do a bit of checking so we don't over-run the boundaries - (necessary for non-square textures!) */ - if( block_size_x * (i+1) > width ) - { - u_block = width - i*block_size_y; - } - if( block_size_y * (j+1) > height ) - { - v_block = height - j*block_size_y; - } - block_area = u_block*v_block; - /* for this pixel, see what the average - of all the values in the block are. - note: start the sum at the rounding value, not at 0 */ - sum_value = block_area >> 1; - for( v = 0; v < v_block; ++v ) - for( u = 0; u < u_block; ++u ) - { - sum_value += orig[index + v*width*channels + u*channels]; - } - resampled[j*mip_width*channels + i*channels + c] = sum_value / block_area; - } - } - } - return 1; -} - -int - scale_image_RGB_to_NTSC_safe - ( - unsigned char* orig, - int width, int height, int channels - ) -{ - const float scale_lo = 16.0f - 0.499f; - const float scale_hi = 235.0f + 0.499f; - int i, j; - int nc = channels; - unsigned char scale_LUT[256]; - /* error check */ - if( (width < 1) || (height < 1) || - (channels < 1) || (orig == NULL) ) - { - /* nothing to do */ - return 0; - } - /* set up the scaling Look Up Table */ - for( i = 0; i < 256; ++i ) - { - scale_LUT[i] = (unsigned char)((scale_hi - scale_lo) * i / 255.0f + scale_lo); - } - /* for channels = 2 or 4, ignore the alpha component */ - nc -= 1 - (channels & 1); - /* OK, go through the image and scale any non-alpha components */ - for( i = 0; i < width*height*channels; i += channels ) - { - for( j = 0; j < nc; ++j ) - { - orig[i+j] = scale_LUT[orig[i+j]]; - } - } - return 1; -} - -unsigned char clamp_byte( int x ) { return ( (x) < 0 ? (0) : ( (x) > 255 ? 255 : (x) ) ); } - -/* - This function takes the RGB components of the image - and converts them into YCoCg. 3 components will be - re-ordered to CoYCg (for optimum DXT1 compression), - while 4 components will be ordered CoCgAY (for DXT5 - compression). -*/ -int - convert_RGB_to_YCoCg - ( - unsigned char* orig, - int width, int height, int channels - ) -{ - int i; - /* error check */ - if( (width < 1) || (height < 1) || - (channels < 3) || (channels > 4) || - (orig == NULL) ) - { - /* nothing to do */ - return -1; - } - /* do the conversion */ - if( channels == 3 ) - { - for( i = 0; i < width*height*3; i += 3 ) - { - int r = orig[i+0]; - int g = (orig[i+1] + 1) >> 1; - int b = orig[i+2]; - int tmp = (2 + r + b) >> 2; - /* Co */ - orig[i+0] = clamp_byte( 128 + ((r - b + 1) >> 1) ); - /* Y */ - orig[i+1] = clamp_byte( g + tmp ); - /* Cg */ - orig[i+2] = clamp_byte( 128 + g - tmp ); - } - } else - { - for( i = 0; i < width*height*4; i += 4 ) - { - int r = orig[i+0]; - int g = (orig[i+1] + 1) >> 1; - int b = orig[i+2]; - unsigned char a = orig[i+3]; - int tmp = (2 + r + b) >> 2; - /* Co */ - orig[i+0] = clamp_byte( 128 + ((r - b + 1) >> 1) ); - /* Cg */ - orig[i+1] = clamp_byte( 128 + g - tmp ); - /* Alpha */ - orig[i+2] = a; - /* Y */ - orig[i+3] = clamp_byte( g + tmp ); - } - } - /* done */ - return 0; -} - -/* - This function takes the YCoCg components of the image - and converts them into RGB. See above. -*/ -int - convert_YCoCg_to_RGB - ( - unsigned char* orig, - int width, int height, int channels - ) -{ - int i; - /* error check */ - if( (width < 1) || (height < 1) || - (channels < 3) || (channels > 4) || - (orig == NULL) ) - { - /* nothing to do */ - return -1; - } - /* do the conversion */ - if( channels == 3 ) - { - for( i = 0; i < width*height*3; i += 3 ) - { - int co = orig[i+0] - 128; - int y = orig[i+1]; - int cg = orig[i+2] - 128; - /* R */ - orig[i+0] = clamp_byte( y + co - cg ); - /* G */ - orig[i+1] = clamp_byte( y + cg ); - /* B */ - orig[i+2] = clamp_byte( y - co - cg ); - } - } else - { - for( i = 0; i < width*height*4; i += 4 ) - { - int co = orig[i+0] - 128; - int cg = orig[i+1] - 128; - unsigned char a = orig[i+2]; - int y = orig[i+3]; - /* R */ - orig[i+0] = clamp_byte( y + co - cg ); - /* G */ - orig[i+1] = clamp_byte( y + cg ); - /* B */ - orig[i+2] = clamp_byte( y - co - cg ); - /* A */ - orig[i+3] = a; - } - } - /* done */ - return 0; -} - -float -find_max_RGBE -( - unsigned char *image, - int width, int height -) -{ - float max_val = 0.0f; - unsigned char *img = image; - int i, j; - for( i = width * height; i > 0; --i ) - { - /* float scale = powf( 2.0f, img[3] - 128.0f ) / 255.0f; */ - float scale = (float)ldexp( 1.0f / 255.0f, (int)(img[3]) - 128 ); - for( j = 0; j < 3; ++j ) - { - if( img[j] * scale > max_val ) - { - max_val = img[j] * scale; - } - } - /* next pixel */ - img += 4; - } - return max_val; -} - -int -RGBE_to_RGBdivA -( - unsigned char *image, - int width, int height, - int rescale_to_max -) -{ - /* local variables */ - int i, iv; - unsigned char *img = image; - float scale = 1.0f; - /* error check */ - if( (!image) || (width < 1) || (height < 1) ) - { - return 0; - } - /* convert (note: no negative numbers, but 0.0 is possible) */ - if( rescale_to_max ) - { - scale = 255.0f / find_max_RGBE( image, width, height ); - } - for( i = width * height; i > 0; --i ) - { - /* decode this pixel, and find the max */ - float r,g,b,e, m; - /* e = scale * powf( 2.0f, img[3] - 128.0f ) / 255.0f; */ - e = scale * (float)ldexp( 1.0f / 255.0f, (int)(img[3]) - 128 ); - r = e * img[0]; - g = e * img[1]; - b = e * img[2]; - m = (r > g) ? r : g; - m = (b > m) ? b : m; - /* and encode it into RGBdivA */ - iv = (m != 0.0f) ? (int)(255.0f / m) : 1; - iv = (iv < 1) ? 1 : iv; - img[3] = (iv > 255) ? 255 : iv; - iv = (int)(img[3] * r + 0.5f); - img[0] = (iv > 255) ? 255 : iv; - iv = (int)(img[3] * g + 0.5f); - img[1] = (iv > 255) ? 255 : iv; - iv = (int)(img[3] * b + 0.5f); - img[2] = (iv > 255) ? 255 : iv; - /* and on to the next pixel */ - img += 4; - } - return 1; -} - -int -RGBE_to_RGBdivA2 -( - unsigned char *image, - int width, int height, - int rescale_to_max -) -{ - /* local variables */ - int i, iv; - unsigned char *img = image; - float scale = 1.0f; - /* error check */ - if( (!image) || (width < 1) || (height < 1) ) - { - return 0; - } - /* convert (note: no negative numbers, but 0.0 is possible) */ - if( rescale_to_max ) - { - scale = 255.0f * 255.0f / find_max_RGBE( image, width, height ); - } - for( i = width * height; i > 0; --i ) - { - /* decode this pixel, and find the max */ - float r,g,b,e, m; - /* e = scale * powf( 2.0f, img[3] - 128.0f ) / 255.0f; */ - e = scale * (float)ldexp( 1.0f / 255.0f, (int)(img[3]) - 128 ); - r = e * img[0]; - g = e * img[1]; - b = e * img[2]; - m = (r > g) ? r : g; - m = (b > m) ? b : m; - /* and encode it into RGBdivA */ - iv = (m != 0.0f) ? (int)sqrtf( 255.0f * 255.0f / m ) : 1; - iv = (iv < 1) ? 1 : iv; - img[3] = (iv > 255) ? 255 : iv; - iv = (int)(img[3] * img[3] * r / 255.0f + 0.5f); - img[0] = (iv > 255) ? 255 : iv; - iv = (int)(img[3] * img[3] * g / 255.0f + 0.5f); - img[1] = (iv > 255) ? 255 : iv; - iv = (int)(img[3] * img[3] * b / 255.0f + 0.5f); - img[2] = (iv > 255) ? 255 : iv; - /* and on to the next pixel */ - img += 4; - } - return 1; -} diff --git a/vendor/SOIL2/src/SOIL2/image_helper.h b/vendor/SOIL2/src/SOIL2/image_helper.h deleted file mode 100755 index 3fa2662f0b..0000000000 --- a/vendor/SOIL2/src/SOIL2/image_helper.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - Jonathan Dummer - - Image helper functions - - MIT license -*/ - -#ifndef HEADER_IMAGE_HELPER -#define HEADER_IMAGE_HELPER - -#ifdef __cplusplus -extern "C" { -#endif - -/** - This function upscales an image. - Not to be used to create MIPmaps, - but to make it square, - or to make it a power-of-two sized. -**/ -int - up_scale_image - ( - const unsigned char* const orig, - int width, int height, int channels, - unsigned char* resampled, - int resampled_width, int resampled_height - ); - -/** - This function downscales an image. - Used for creating MIPmaps, - the incoming image should be a - power-of-two sized. -**/ -int - mipmap_image - ( - const unsigned char* const orig, - int width, int height, int channels, - unsigned char* resampled, - int block_size_x, int block_size_y - ); - -/** - This function takes the RGB components of the image - and scales each channel from [0,255] to [16,235]. - This makes the colors "Safe" for display on NTSC - displays. Note that this is _NOT_ a good idea for - loading images like normal- or height-maps! -**/ -int - scale_image_RGB_to_NTSC_safe - ( - unsigned char* orig, - int width, int height, int channels - ); - -/** - This function takes the RGB components of the image - and converts them into YCoCg. 3 components will be - re-ordered to CoYCg (for optimum DXT1 compression), - while 4 components will be ordered CoCgAY (for DXT5 - compression). -**/ -int - convert_RGB_to_YCoCg - ( - unsigned char* orig, - int width, int height, int channels - ); - -/** - This function takes the YCoCg components of the image - and converts them into RGB. See above. -**/ -int - convert_YCoCg_to_RGB - ( - unsigned char* orig, - int width, int height, int channels - ); - -/** - Converts an HDR image from an array - of unsigned chars (RGBE) to RGBdivA - \return 0 if failed, otherwise returns 1 -**/ -int - RGBE_to_RGBdivA - ( - unsigned char *image, - int width, int height, - int rescale_to_max - ); - -/** - Converts an HDR image from an array - of unsigned chars (RGBE) to RGBdivA2 - \return 0 if failed, otherwise returns 1 -**/ -int - RGBE_to_RGBdivA2 - ( - unsigned char *image, - int width, int height, - int rescale_to_max - ); - -#ifdef __cplusplus -} -#endif - -#endif /* HEADER_IMAGE_HELPER */ diff --git a/vendor/SOIL2/src/common/common.cpp b/vendor/SOIL2/src/common/common.cpp deleted file mode 100644 index 0704601c40..0000000000 --- a/vendor/SOIL2/src/common/common.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "common.hpp" -#include -#include -#include -#include -#include - -#if defined( __APPLE_CC__ ) || defined ( __APPLE__ ) - #define PLATFORM_OSX - #include -#elif defined( __WIN32__ ) || defined( _WIN32 ) || defined( _WIN64 ) - #define PLATFORM_WIN32 - #include - -#if defined(_MSC_VER) && defined( UNICODE ) -static std::string wcharToString(TCHAR* text) { - std::vector buffer; - int size = WideCharToMultiByte(CP_UTF8, 0, text, -1, NULL, 0, NULL, NULL); - if (size > 0) { - buffer.resize(size); - WideCharToMultiByte(CP_UTF8, 0, text, -1, reinterpret_cast(&buffer[0]), buffer.size(), NULL, NULL); - } - return std::string(&buffer[0]); -} -#endif - -#elif defined ( linux ) || defined( __linux__ ) - #define PLATFORM_LINUX - #include - #include -#elif defined( __HAIKU__ ) || defined( __BEOS__ ) - #define PLATFORM_HAIKU - #include - #include -#elif defined( __SVR4 ) - #define PLATFORM_SOLARIS - #include -#elif defined( __FreeBSD__ ) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined( __DragonFly__ ) - #define PLATFORM_BSD - #include -#endif - -std::string FileRemoveFileName( const std::string& filepath ) { - return filepath.substr( 0, filepath.find_last_of("/\\") + 1 ); -} - -static std::string GetProcessPath() { -#if defined( PLATFORM_OSX ) - char exe_file[PATH_MAX + 1]; - CFBundleRef mainBundle = CFBundleGetMainBundle(); - if (mainBundle) { - CFURLRef mainURL = CFBundleCopyBundleURL(mainBundle); - - if (mainURL) { - int ok = CFURLGetFileSystemRepresentation ( mainURL, (Boolean) true, (UInt8*)exe_file, PATH_MAX ); - - if (ok) { - return std::string(exe_file) + "/"; - } - } - } - - return "./"; -#elif defined( PLATFORM_LINUX ) - char exe_file[PATH_MAX + 1]; - int size; - size = readlink("/proc/self/exe", exe_file, PATH_MAX); - if (size < 0) { - return "./"; - } else { - exe_file[size] = '\0'; - return std::string(dirname(exe_file)) + "/"; - } -#elif defined( PLATFORM_WIN32 ) - #ifdef UNICODE - // Get path to executable: - TCHAR szDllName[_MAX_PATH]; - TCHAR szDrive[_MAX_DRIVE]; - TCHAR szDir[_MAX_DIR]; - TCHAR szFilename[_MAX_DIR]; - TCHAR szExt[_MAX_DIR]; - GetModuleFileName(0, szDllName, _MAX_PATH); - - #if ( defined( _MSCVER ) || defined( _MSC_VER ) ) - _wsplitpath_s(szDllName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, szExt, _MAX_DIR); - #else - _splitpath(szDllName, szDrive, szDir, szFilename, szExt); - #endif - - return wcharToString(szDrive) + wcharToString(szDir); - #else - // Get path to executable: - TCHAR szDllName[_MAX_PATH]; - TCHAR szDrive[_MAX_DRIVE]; - TCHAR szDir[_MAX_DIR]; - TCHAR szFilename[_MAX_DIR]; - TCHAR szExt[_MAX_DIR]; - GetModuleFileName(0, szDllName, _MAX_PATH); - #if ( defined( _MSCVER ) || defined( _MSC_VER ) ) - _splitpath_s(szDllName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, szExt, _MAX_DIR); - #else - _splitpath(szDllName, szDrive, szDir, szFilename, szExt); - #endif - return std::string(szDrive) + std::string(szDir); - #endif -#elif defined( PLATFORM_BSD ) - int mib[4]; - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PATHNAME; - mib[3] = -1; - char buf[1024]; - size_t cb = sizeof(buf); - sysctl(mib, 4, buf, &cb, NULL, 0); - - return FileRemoveFileName( std::string( buf ) ); -#elif defined( PLATFORM_SOLARIS ) - return FileRemoveFileName( std::string( getexecname() ) ); -#elif defined( PLATFORM_HAIKU ) - image_info info; - int32 cookie = 0; - - while ( B_OK == get_next_image_info( 0, &cookie, &info ) ) { - if ( info.type == B_APP_IMAGE ) - break; - } - - return FileRemoveFileName( std::string( info.name ) ); -#else - #warning GetProcessPath() not implemented on this platform. ( will return "./" ) - return "./"; -#endif -} - -std::string ResourcePath(std::string fileName) { - return GetProcessPath() + fileName; -} - diff --git a/vendor/SOIL2/src/common/common.hpp b/vendor/SOIL2/src/common/common.hpp deleted file mode 100644 index f8f179d63d..0000000000 --- a/vendor/SOIL2/src/common/common.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -std::string ResourcePath(std::string fileName); diff --git a/vendor/stb_image/CMakeLists.txt b/vendor/stb_image/CMakeLists.txt new file mode 100644 index 0000000000..bc74bc9ee9 --- /dev/null +++ b/vendor/stb_image/CMakeLists.txt @@ -0,0 +1,31 @@ +add_library(stb_image OBJECT + ${CMAKE_CURRENT_SOURCE_DIR}/image_DXT.c + ${CMAKE_CURRENT_SOURCE_DIR}/image_DXT.h + ${CMAKE_CURRENT_SOURCE_DIR}/pkm_helper.h + ${CMAKE_CURRENT_SOURCE_DIR}/pvr_helper.h + ${CMAKE_CURRENT_SOURCE_DIR}/stb_image.h + ${CMAKE_CURRENT_SOURCE_DIR}/stb_image.c + ${CMAKE_CURRENT_SOURCE_DIR}/stb_image_write.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_DDS.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_DDS_c.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_ext.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_ext_c.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_pkm.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_pkm_c.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_pvr.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_pvr_c.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_qoi.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_qoi_c.h + ${CMAKE_CURRENT_SOURCE_DIR}/stbi_qoi_write.h + ${CMAKE_CURRENT_SOURCE_DIR}/wfETC.c + ${CMAKE_CURRENT_SOURCE_DIR}/wfETC.h + ) + +target_include_directories(stb_image + PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + ) + +set_target_properties(stb_image PROPERTIES + FOLDER vendor/stb_image + ) diff --git a/vendor/SOIL2/src/SOIL2/image_DXT.c b/vendor/stb_image/image_DXT.c similarity index 100% rename from vendor/SOIL2/src/SOIL2/image_DXT.c rename to vendor/stb_image/image_DXT.c index c708733023..ffaad59e7d 100755 --- a/vendor/SOIL2/src/SOIL2/image_DXT.c +++ b/vendor/stb_image/image_DXT.c @@ -9,9 +9,9 @@ #include "image_DXT.h" #include +#include #include #include -#include /* set this =1 if you want to use the covarince matrix method... which is better than my method of using standard deviations diff --git a/vendor/SOIL2/src/SOIL2/image_DXT.h b/vendor/stb_image/image_DXT.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/image_DXT.h rename to vendor/stb_image/image_DXT.h diff --git a/vendor/SOIL2/src/SOIL2/pkm_helper.h b/vendor/stb_image/pkm_helper.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/pkm_helper.h rename to vendor/stb_image/pkm_helper.h diff --git a/vendor/SOIL2/src/SOIL2/pvr_helper.h b/vendor/stb_image/pvr_helper.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/pvr_helper.h rename to vendor/stb_image/pvr_helper.h diff --git a/vendor/stb_image/stb_image.c b/vendor/stb_image/stb_image.c new file mode 100644 index 0000000000..8ddfd1f546 --- /dev/null +++ b/vendor/stb_image/stb_image.c @@ -0,0 +1,2 @@ +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" diff --git a/vendor/SOIL2/src/SOIL2/stb_image.h b/vendor/stb_image/stb_image.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stb_image.h rename to vendor/stb_image/stb_image.h diff --git a/vendor/SOIL2/src/SOIL2/stb_image_write.h b/vendor/stb_image/stb_image_write.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stb_image_write.h rename to vendor/stb_image/stb_image_write.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_DDS.h b/vendor/stb_image/stbi_DDS.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_DDS.h rename to vendor/stb_image/stbi_DDS.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_DDS_c.h b/vendor/stb_image/stbi_DDS_c.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_DDS_c.h rename to vendor/stb_image/stbi_DDS_c.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_ext.h b/vendor/stb_image/stbi_ext.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_ext.h rename to vendor/stb_image/stbi_ext.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_ext_c.h b/vendor/stb_image/stbi_ext_c.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_ext_c.h rename to vendor/stb_image/stbi_ext_c.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_pkm.h b/vendor/stb_image/stbi_pkm.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_pkm.h rename to vendor/stb_image/stbi_pkm.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_pkm_c.h b/vendor/stb_image/stbi_pkm_c.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_pkm_c.h rename to vendor/stb_image/stbi_pkm_c.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_pvr.h b/vendor/stb_image/stbi_pvr.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_pvr.h rename to vendor/stb_image/stbi_pvr.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_pvr_c.h b/vendor/stb_image/stbi_pvr_c.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_pvr_c.h rename to vendor/stb_image/stbi_pvr_c.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_qoi.h b/vendor/stb_image/stbi_qoi.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_qoi.h rename to vendor/stb_image/stbi_qoi.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_qoi_c.h b/vendor/stb_image/stbi_qoi_c.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_qoi_c.h rename to vendor/stb_image/stbi_qoi_c.h diff --git a/vendor/SOIL2/src/SOIL2/stbi_qoi_write.h b/vendor/stb_image/stbi_qoi_write.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/stbi_qoi_write.h rename to vendor/stb_image/stbi_qoi_write.h diff --git a/vendor/SOIL2/src/SOIL2/wfETC.c b/vendor/stb_image/wfETC.c similarity index 100% rename from vendor/SOIL2/src/SOIL2/wfETC.c rename to vendor/stb_image/wfETC.c diff --git a/vendor/SOIL2/src/SOIL2/wfETC.h b/vendor/stb_image/wfETC.h similarity index 100% rename from vendor/SOIL2/src/SOIL2/wfETC.h rename to vendor/stb_image/wfETC.h