From c38d76f42a8bb1a8a3eb0b5bba3400f52c026570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 19 Jul 2017 22:53:48 -0700 Subject: [PATCH] texturev: Added image orientation. --- examples/common/bgfx_utils.cpp | 11 ++++++++--- examples/common/bgfx_utils.h | 2 +- tools/texturev/texturev.cpp | 28 +++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index c316769d6..155fce965 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -155,7 +155,7 @@ static void imageReleaseCb(void* _ptr, void* _userData) bimg::imageFree(imageContainer); } -bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _filePath, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info) +bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _filePath, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info, bimg::Orientation::Enum* _orientation) { BX_UNUSED(_skip); bgfx::TextureHandle handle = BGFX_INVALID_HANDLE; @@ -168,6 +168,11 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _filePath, if (NULL != imageContainer) { + if (NULL != _orientation) + { + *_orientation = imageContainer->m_orientation; + } + const bgfx::Memory* mem = bgfx::makeRef( imageContainer->m_data , imageContainer->m_size @@ -231,9 +236,9 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _filePath, return handle; } -bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info) +bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info, bimg::Orientation::Enum* _orientation) { - return loadTexture(entry::getFileReader(), _name, _flags, _skip, _info); + return loadTexture(entry::getFileReader(), _name, _flags, _skip, _info, _orientation); } bimg::ImageContainer* imageLoad(const char* _filePath, bgfx::TextureFormat::Enum _dstFormat) diff --git a/examples/common/bgfx_utils.h b/examples/common/bgfx_utils.h index 45b24904d..92b8a5b6d 100644 --- a/examples/common/bgfx_utils.h +++ b/examples/common/bgfx_utils.h @@ -23,7 +23,7 @@ bgfx::ShaderHandle loadShader(const char* _name); bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName); /// -bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL); +bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL, bimg::Orientation::Enum* _orientation = NULL); /// bimg::ImageContainer* imageLoad(const char* _filePath, bgfx::TextureFormat::Enum _dstFormat); diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index 084a93d3d..2d6a54dd6 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -205,6 +205,7 @@ struct View , m_angy(0.0f) , m_zoom(1.0f) , m_angle(0.0f) + , m_orientation(0.0f) , m_filter(true) , m_fit(true) , m_alpha(false) @@ -401,6 +402,19 @@ struct View m_angle = 0.0f; } } + else if (0 == bx::strCmp(_argv[1], "orientation") ) + { + if (_argc >= 3) + { + float angle; + bx::fromString(&angle, _argv[2]); + m_orientation = bx::toRad(angle); + } + else + { + m_orientation = 0.0f; + } + } else if (0 == bx::strCmp(_argv[1], "filter") ) { if (_argc >= 3) @@ -588,6 +602,7 @@ struct View float m_angy; float m_zoom; float m_angle; + float m_orientation; bool m_filter; bool m_fit; bool m_alpha; @@ -1423,6 +1438,7 @@ int _main_(int _argc, char** _argv) bx::FilePath fp = view.m_path; fp.join(view.m_fileList[view.m_fileIndex].c_str() ); + bimg::Orientation::Enum orientation; texture = loadTexture(fp.get() , 0 | BGFX_TEXTURE_U_CLAMP @@ -1430,8 +1446,18 @@ int _main_(int _argc, char** _argv) | BGFX_TEXTURE_W_CLAMP , 0 , &view.m_info + , &orientation ); + switch (orientation) + { + default: + case bimg::Orientation::R0: cmdExec("view orientation 0"); break; + case bimg::Orientation::R90: cmdExec("view orientation -90"); break; + case bimg::Orientation::R180: cmdExec("view orientation -180"); break; + case bimg::Orientation::R270: cmdExec("view orientation -270"); break; + } + std::string title; if (isValid(texture) ) { @@ -1566,7 +1592,7 @@ int _main_(int _argc, char** _argv) ); float rotz[16]; - bx::mtxRotateZ(rotz, angle.getValue() ); + bx::mtxRotateZ(rotz, angle.getValue()+view.m_orientation); bgfx::setTransform(rotz); float mtx[16];