├── .gitignore ├── LICENSE ├── Platforms ├── CMakeLists.txt └── OpenGLES │ └── OpenGLESPlatform │ ├── include │ ├── MyGUI_OpenGLESDataManager.h │ ├── MyGUI_OpenGLESDiagnostic.h │ ├── MyGUI_OpenGLESImageLoader.h │ ├── MyGUI_OpenGLESPlatform.h │ ├── MyGUI_OpenGLESRTTexture.h │ ├── MyGUI_OpenGLESRenderManager.h │ ├── MyGUI_OpenGLESTexture.h │ ├── MyGUI_OpenGLESVertexBuffer.h │ └── platform.h │ └── src │ ├── MyGUI_OpenGLESDataManager.cpp │ ├── MyGUI_OpenGLESPlatform.cpp │ ├── MyGUI_OpenGLESRTTexture.cpp │ ├── MyGUI_OpenGLESRenderManager.cpp │ ├── MyGUI_OpenGLESTexture.cpp │ └── MyGUI_OpenGLESVertexBuffer.cpp └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2012 - 2013 wangdy ( wangdy#outlook.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Platforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(MYGUI_RENDERSYSTEM EQUAL 1) 2 | add_subdirectory(DirectX/DirectXPlatform) 3 | elseif(MYGUI_RENDERSYSTEM EQUAL 2) 4 | add_subdirectory(Ogre/OgrePlatform) 5 | elseif(MYGUI_RENDERSYSTEM EQUAL 3) 6 | add_subdirectory(OpenGL/OpenGLPlatform) 7 | elseif(MYGUI_RENDERSYSTEM EQUAL 4) 8 | add_subdirectory(DirectX11/DirectX11Platform) 9 | elseif(MYGUI_RENDERSYSTEM EQUAL 5) 10 | add_subdirectory(OpenGLES/OpenGLESPlatform) 11 | endif() 12 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESDataManager.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | #ifndef __MYGUI_OPENGLES_DATA_MANAGER_H__ 8 | #define __MYGUI_OPENGLES_DATA_MANAGER_H__ 9 | 10 | #include "MyGUI_Prerequest.h" 11 | #include "MyGUI_DataManager.h" 12 | 13 | namespace MyGUI 14 | { 15 | 16 | class OpenGLESDataManager : 17 | public DataManager 18 | { 19 | public: 20 | OpenGLESDataManager(); 21 | 22 | void initialise(); 23 | void shutdown(); 24 | 25 | static OpenGLESDataManager& getInstance() 26 | { 27 | return *getInstancePtr(); 28 | } 29 | static OpenGLESDataManager* getInstancePtr() 30 | { 31 | return static_cast(DataManager::getInstancePtr()); 32 | } 33 | 34 | /** @see DataManager::getData(const std::string& _name) */ 35 | virtual IDataStream* getData(const std::string& _name); 36 | 37 | /** @see DataManager::isDataExist(const std::string& _name) */ 38 | virtual bool isDataExist(const std::string& _name); 39 | 40 | /** @see DataManager::getDataListNames(const std::string& _pattern) */ 41 | virtual const VectorString& getDataListNames(const std::string& _pattern); 42 | 43 | /** @see DataManager::getDataPath(const std::string& _name) */ 44 | virtual const std::string& getDataPath(const std::string& _name); 45 | 46 | /*internal:*/ 47 | void addResourceLocation(const std::string& _name, bool _recursive); 48 | 49 | private: 50 | struct ArhivInfo 51 | { 52 | std::wstring name; 53 | bool recursive; 54 | }; 55 | typedef std::vector VectorArhivInfo; 56 | VectorArhivInfo mPaths; 57 | 58 | bool mIsInitialise; 59 | }; 60 | 61 | } // namespace MyGUI 62 | 63 | #endif // __MYGUI_OPENGLES_DATA_MANAGER_H__ 64 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESDiagnostic.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | #ifndef __MYGUI_OPENGLES_DIAGNOSTIC_H__ 8 | #define __MYGUI_OPENGLES_DIAGNOSTIC_H__ 9 | 10 | #include "MyGUI_Prerequest.h" 11 | 12 | #define MYGUI_PLATFORM_LOG_SECTION "Platform" 13 | #define MYGUI_PLATFORM_LOG_FILENAME "MyGUI.log" 14 | #define MYGUI_PLATFORM_LOG(level, text) MYGUI_LOGGING(MYGUI_PLATFORM_LOG_SECTION, level, text) 15 | 16 | #define MYGUI_PLATFORM_EXCEPT(dest) \ 17 | { \ 18 | MYGUI_PLATFORM_LOG(Critical, dest); \ 19 | MYGUI_DBG_BREAK;\ 20 | std::ostringstream stream; \ 21 | stream << dest << "\n"; \ 22 | MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \ 23 | } 24 | 25 | #define MYGUI_PLATFORM_ASSERT(exp, dest) \ 26 | { \ 27 | if ( ! (exp) ) \ 28 | { \ 29 | MYGUI_PLATFORM_LOG(Critical, dest); \ 30 | MYGUI_DBG_BREAK;\ 31 | std::ostringstream stream; \ 32 | stream << dest << "\n"; \ 33 | MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \ 34 | } \ 35 | } 36 | 37 | #endif // __MYGUI_OPENGLES_DIAGNOSTIC_H__ 38 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESImageLoader.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 09/2009 5 | @module 6 | */ 7 | 8 | #ifndef __MYGUI_OPENGLES_IMAGE_LOADER_H__ 9 | #define __MYGUI_OPENGLES_IMAGE_LOADER_H__ 10 | 11 | #include "MyGUI_Prerequest.h" 12 | #include "MyGUI_RenderFormat.h" 13 | 14 | namespace MyGUI 15 | { 16 | 17 | class OpenGLESImageLoader 18 | { 19 | public: 20 | OpenGLESImageLoader() { } 21 | virtual ~OpenGLESImageLoader() { } 22 | 23 | virtual void* loadImage(int& _width, int& _height, PixelFormat& _format, const std::string& _filename) = 0; 24 | virtual void saveImage(int _width, int _height, MyGUI::PixelFormat _format, void* _texture, const std::string& _filename) = 0; 25 | }; 26 | 27 | } // namespace MyGUI 28 | 29 | #endif // __MYGUI_OPENGLES_IMAGE_LOADER_H__ 30 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESPlatform.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESPlatform.h 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #ifndef __MYGUI_OPENGLES_PLATFORM_H__ 15 | #define __MYGUI_OPENGLES_PLATFORM_H__ 16 | 17 | #include "MyGUI_Prerequest.h" 18 | #include "MyGUI_OpenGLESDiagnostic.h" 19 | #include "MyGUI_OpenGLESRenderManager.h" 20 | #include "MyGUI_OpenGLESDataManager.h" 21 | #include "MyGUI_OpenGLESImageLoader.h" 22 | #include "MyGUI_LogManager.h" 23 | 24 | namespace MyGUI 25 | { 26 | 27 | class OpenGLESPlatform 28 | { 29 | public: 30 | OpenGLESPlatform(); 31 | ~OpenGLESPlatform(); 32 | 33 | void initialise(OpenGLESImageLoader* _loader, const std::string& _logName = MYGUI_PLATFORM_LOG_FILENAME); 34 | void shutdown(); 35 | 36 | OpenGLESRenderManager* getRenderManagerPtr(); 37 | OpenGLESDataManager* getDataManagerPtr(); 38 | 39 | private: 40 | bool mIsInitialise; 41 | OpenGLESRenderManager* mRenderManager; 42 | OpenGLESDataManager* mDataManager; 43 | LogManager* mLogManager; 44 | }; 45 | 46 | } // namespace MyGUI 47 | 48 | #endif // __MYGUI_OPENGLES_PLATFORM_H__ 49 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESRTTexture.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author Albert Semenov 4 | @date 12/2009 5 | */ 6 | 7 | #ifndef __MYGUI_OPENGLES_RTTEXTURE_H__ 8 | #define __MYGUI_OPENGLES_RTTEXTURE_H__ 9 | 10 | #include "MyGUI_Prerequest.h" 11 | #include "MyGUI_ITexture.h" 12 | #include "MyGUI_RenderFormat.h" 13 | #include "MyGUI_IRenderTarget.h" 14 | 15 | namespace MyGUI 16 | { 17 | 18 | class OpenGLESRTTexture : 19 | public IRenderTarget 20 | { 21 | public: 22 | OpenGLESRTTexture(unsigned int _texture); 23 | virtual ~OpenGLESRTTexture(); 24 | 25 | virtual void begin(); 26 | virtual void end(); 27 | 28 | virtual void doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count); 29 | 30 | virtual const RenderTargetInfo& getInfo() 31 | { 32 | return mRenderTargetInfo; 33 | } 34 | 35 | private: 36 | RenderTargetInfo mRenderTargetInfo; 37 | unsigned int mTextureID; 38 | int mWidth; 39 | int mHeight; 40 | unsigned int mFBOID; 41 | unsigned int mRBOID; 42 | }; 43 | 44 | } // namespace MyGUI 45 | 46 | #endif // __MYGUI_OPENGLES_RTTEXTURE_H__ 47 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESRenderManager.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESRenderManager.h 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #ifndef __MYGUI_OPENGLES_RENDER_MANAGER_H__ 15 | #define __MYGUI_OPENGLES_RENDER_MANAGER_H__ 16 | 17 | #include "MyGUI_Prerequest.h" 18 | #include "MyGUI_RenderFormat.h" 19 | #include "MyGUI_IVertexBuffer.h" 20 | #include "MyGUI_RenderManager.h" 21 | #include "MyGUI_OpenGLESImageLoader.h" 22 | 23 | #include 24 | #include 25 | 26 | namespace MyGUI 27 | { 28 | 29 | class OpenGLESRenderManager : 30 | public RenderManager, 31 | public IRenderTarget 32 | { 33 | public: 34 | OpenGLESRenderManager(); 35 | 36 | void initialise(OpenGLESImageLoader* _loader = 0); 37 | void shutdown(); 38 | 39 | static OpenGLESRenderManager& getInstance() 40 | { 41 | return *getInstancePtr(); 42 | } 43 | static OpenGLESRenderManager* getInstancePtr() 44 | { 45 | return static_cast(RenderManager::getInstancePtr()); 46 | } 47 | 48 | /** @see OpenGLESRenderManager::getViewSize */ 49 | virtual const IntSize& getViewSize() const; 50 | 51 | /** @see OpenGLESRenderManager::getVertexFormat */ 52 | virtual VertexColourType getVertexFormat(); 53 | 54 | /** @see OpenGLESRenderManager::createVertexBuffer */ 55 | virtual IVertexBuffer* createVertexBuffer(); 56 | /** @see OpenGLESRenderManager::destroyVertexBuffer */ 57 | virtual void destroyVertexBuffer(IVertexBuffer* _buffer); 58 | 59 | /** @see OpenGLESRenderManager::createTexture */ 60 | virtual ITexture* createTexture(const std::string& _name); 61 | /** @see OpenGLESRenderManager::destroyTexture */ 62 | virtual void destroyTexture(ITexture* _texture); 63 | /** @see OpenGLESRenderManager::getTexture */ 64 | virtual ITexture* getTexture(const std::string& _name); 65 | 66 | 67 | /** @see IRenderTarget::begin */ 68 | virtual void begin(); 69 | /** @see IRenderTarget::end */ 70 | virtual void end(); 71 | /** @see IRenderTarget::doRender */ 72 | virtual void doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count); 73 | /** @see IRenderTarget::getInfo */ 74 | virtual const RenderTargetInfo& getInfo(); 75 | 76 | 77 | /*internal:*/ 78 | void drawOneFrame(); 79 | void setViewSize(int _width, int _height); 80 | bool isPixelBufferObjectSupported() const; 81 | 82 | private: 83 | void destroyAllResources(); 84 | GLuint BuildShader(const char* source, GLenum shaderType) const; 85 | GLuint BuildProgram(const char* vertexShaderSource, 86 | const char* fragmentShaderSource) const; 87 | 88 | private: 89 | IntSize mViewSize; 90 | bool mUpdate; 91 | VertexColourType mVertexFormat; 92 | RenderTargetInfo mInfo; 93 | 94 | typedef std::map MapTexture; 95 | MapTexture mTextures; 96 | OpenGLESImageLoader* mImageLoader; 97 | bool mPboIsSupported; 98 | 99 | bool mIsInitialise; 100 | 101 | float angle=0.0; 102 | int step=1; 103 | void renderScene(void); 104 | 105 | GLuint _positionSlot; 106 | GLuint _colorSlot; 107 | GLuint _texSlot; 108 | 109 | GLuint mProgram; 110 | GLuint mVertShader; 111 | GLuint mFragShader; 112 | }; 113 | 114 | } // namespace MyGUI 115 | 116 | #endif // __MYGUI_OPENGLES_RENDER_MANAGER_H__ 117 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESTexture.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESTexture.h 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #ifndef __MYGUI_OPENGLES_TEXTURE_H__ 15 | #define __MYGUI_OPENGLES_TEXTURE_H__ 16 | 17 | #include "MyGUI_Prerequest.h" 18 | #include "MyGUI_ITexture.h" 19 | #include "MyGUI_RenderFormat.h" 20 | #include "MyGUI_OpenGLESImageLoader.h" 21 | 22 | #include 23 | #include 24 | 25 | namespace MyGUI 26 | { 27 | 28 | class OpenGLESRTTexture; 29 | 30 | class OpenGLESTexture : public ITexture 31 | { 32 | public: 33 | OpenGLESTexture(const std::string& _name, OpenGLESImageLoader* _loader); 34 | virtual ~OpenGLESTexture(); 35 | 36 | virtual const std::string& getName() const; 37 | 38 | virtual void createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format); 39 | virtual void loadFromFile(const std::string& _filename); 40 | virtual void saveToFile(const std::string& _filename); 41 | 42 | virtual void destroy(); 43 | 44 | virtual int getWidth() 45 | { 46 | return mWidth; 47 | } 48 | virtual int getHeight() 49 | { 50 | return mHeight; 51 | } 52 | 53 | virtual void* lock(TextureUsage _access); 54 | virtual void unlock(); 55 | virtual bool isLocked() 56 | { 57 | return mLock; 58 | } 59 | 60 | virtual PixelFormat getFormat() 61 | { 62 | return mOriginalFormat; 63 | } 64 | virtual TextureUsage getUsage() 65 | { 66 | return mOriginalUsage; 67 | } 68 | virtual size_t getNumElemBytes() 69 | { 70 | return mNumElemBytes; 71 | } 72 | 73 | virtual IRenderTarget* getRenderTarget(); 74 | 75 | /*internal:*/ 76 | unsigned int getTextureID() const; 77 | void setUsage(TextureUsage _usage); 78 | void createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format, void* _data); 79 | 80 | private: 81 | void _create(); 82 | 83 | private: 84 | std::string mName; 85 | int mWidth; 86 | int mHeight; 87 | int mPixelFormat; 88 | int mInternalPixelFormat; 89 | int mUsage; 90 | int mAccess; 91 | size_t mNumElemBytes; 92 | size_t mDataSize; 93 | unsigned int mTextureID; 94 | unsigned int mPboID; 95 | bool mLock; 96 | void* mBuffer; 97 | PixelFormat mOriginalFormat; 98 | TextureUsage mOriginalUsage; 99 | OpenGLESImageLoader* mImageLoader; 100 | OpenGLESRTTexture* mRenderTarget; 101 | }; 102 | 103 | } // namespace MyGUI 104 | 105 | #endif // __MYGUI_OPENGLES_TEXTURE_H__ 106 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/MyGUI_OpenGLESVertexBuffer.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESVertexBuffer.h 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #ifndef __MYGUI_OPENGLES_VERTEX_BUFFER_H__ 15 | #define __MYGUI_OPENGLES_VERTEX_BUFFER_H__ 16 | 17 | #include "MyGUI_Prerequest.h" 18 | #include "MyGUI_IVertexBuffer.h" 19 | //#include "MyGUI_OpenGLESRenderManager.h" 20 | 21 | #include 22 | #include 23 | 24 | namespace MyGUI 25 | { 26 | 27 | class OpenGLESVertexBuffer : public IVertexBuffer 28 | { 29 | public: 30 | OpenGLESVertexBuffer(); 31 | virtual ~OpenGLESVertexBuffer(); 32 | 33 | virtual void setVertexCount(size_t _count); 34 | virtual size_t getVertexCount(); 35 | 36 | virtual Vertex* lock(); 37 | virtual void unlock(); 38 | 39 | /*internal:*/ 40 | void destroy(); 41 | void create(); 42 | 43 | unsigned int getBufferID() const 44 | { 45 | return mBufferID; 46 | } 47 | 48 | private: 49 | unsigned int mBufferID; 50 | size_t mVertexCount; 51 | size_t mNeedVertexCount; 52 | size_t mSizeInBytes; 53 | }; 54 | 55 | } // namespace MyGUI 56 | 57 | #endif // __MYGUI_OPENGLES_VERTEX_BUFFER_H__ 58 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/include/platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // platform.h 3 | // 4 | // Created by wangdy on 12-10-19. 5 | // 6 | // 7 | 8 | #ifndef CHECK_GL_ERROR_DEBUG//() 9 | #define CHECK_GL_ERROR_DEBUG() \ 10 | do { \ 11 | GLenum __error = glGetError(); \ 12 | if(__error) { \ 13 | MYGUI_PLATFORM_LOG(Info, "OpenGLES error 0x%04X in " << __error << " " << __FILE__<< " " << __FUNCTION__<< " "<< __LINE__); \ 14 | } \ 15 | } while (false) 16 | #endif -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/src/MyGUI_OpenGLESDataManager.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESDataManager.cpp 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #include "MyGUI_OpenGLESDataManager.h" 15 | #include "MyGUI_OpenGLESDiagnostic.h" 16 | #include "MyGUI_DataFileStream.h" 17 | #include "FileSystemInfo/FileSystemInfo.h" 18 | #include 19 | 20 | #include "MyGUI_Diagnostic.h" 21 | 22 | namespace MyGUI 23 | { 24 | 25 | OpenGLESDataManager::OpenGLESDataManager() : 26 | mIsInitialise(false) 27 | { 28 | } 29 | 30 | void OpenGLESDataManager::initialise() 31 | { 32 | MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 33 | MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName()); 34 | 35 | MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized"); 36 | mIsInitialise = true; 37 | } 38 | 39 | void OpenGLESDataManager::shutdown() 40 | { 41 | MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 42 | MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName()); 43 | 44 | MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown"); 45 | mIsInitialise = false; 46 | } 47 | 48 | IDataStream* OpenGLESDataManager::getData(const std::string& _name) 49 | { 50 | std::string filepath = getDataPath(_name); 51 | if (filepath.empty()) 52 | return nullptr; 53 | 54 | std::ifstream* stream = new std::ifstream(); 55 | stream->open(filepath.c_str(), std::ios_base::binary); 56 | 57 | if (!stream->is_open()) 58 | { 59 | delete stream; 60 | return nullptr; 61 | } 62 | 63 | DataFileStream* data = new DataFileStream(stream); 64 | 65 | return data; 66 | } 67 | 68 | bool OpenGLESDataManager::isDataExist(const std::string& _name) 69 | { 70 | const VectorString& files = getDataListNames(_name); 71 | return files.size() == 1; 72 | } 73 | 74 | const VectorString& OpenGLESDataManager::getDataListNames(const std::string& _pattern) 75 | { 76 | static VectorString result; 77 | common::VectorWString wresult; 78 | result.clear(); 79 | 80 | for (VectorArhivInfo::const_iterator item = mPaths.begin(); item != mPaths.end(); ++item) 81 | { 82 | common::scanFolder(wresult, (*item).name, (*item).recursive, MyGUI::UString(_pattern).asWStr(), false); 83 | } 84 | 85 | for (common::VectorWString::const_iterator item = wresult.begin(); item != wresult.end(); ++item) 86 | { 87 | result.push_back(MyGUI::UString(*item).asUTF8()); 88 | } 89 | 90 | return result; 91 | } 92 | 93 | const std::string& OpenGLESDataManager::getDataPath(const std::string& _name) 94 | { 95 | static std::string path; 96 | VectorString result; 97 | common::VectorWString wresult; 98 | 99 | for (VectorArhivInfo::const_iterator item = mPaths.begin(); item != mPaths.end(); ++item) 100 | { 101 | common::scanFolder(wresult, (*item).name, (*item).recursive, MyGUI::UString(_name).asWStr(), true); 102 | } 103 | 104 | for (common::VectorWString::const_iterator item = wresult.begin(); item != wresult.end(); ++item) 105 | { 106 | result.push_back(MyGUI::UString(*item).asUTF8()); 107 | } 108 | 109 | path = result.size() == 1 ? result[0] : ""; 110 | return path; 111 | } 112 | 113 | void OpenGLESDataManager::addResourceLocation(const std::string& _name, bool _recursive) 114 | { 115 | ArhivInfo info; 116 | info.name = MyGUI::UString(_name).asWStr(); 117 | info.recursive = _recursive; 118 | mPaths.push_back(info); 119 | } 120 | 121 | } // namespace MyGUI 122 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/src/MyGUI_OpenGLESPlatform.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author Albert Semenov 4 | @date 09/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESPlatform.cpp 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #include "MyGUI_OpenGLESPlatform.h" 15 | #include 16 | 17 | namespace MyGUI 18 | { 19 | 20 | OpenGLESPlatform::OpenGLESPlatform() : 21 | mIsInitialise(false) 22 | { 23 | mRenderManager = new OpenGLESRenderManager(); 24 | mDataManager = new OpenGLESDataManager(); 25 | mLogManager = new LogManager(); 26 | } 27 | 28 | OpenGLESPlatform::~OpenGLESPlatform() 29 | { 30 | assert(!mIsInitialise); 31 | delete mRenderManager; 32 | delete mDataManager; 33 | delete mLogManager; 34 | } 35 | 36 | void OpenGLESPlatform::initialise(OpenGLESImageLoader* _loader, const std::string& _logName) 37 | { 38 | assert(!mIsInitialise); 39 | mIsInitialise = true; 40 | 41 | if (!_logName.empty()) 42 | LogManager::getInstance().createDefaultSource(_logName); 43 | 44 | mRenderManager->initialise(_loader); 45 | mDataManager->initialise(); 46 | } 47 | 48 | void OpenGLESPlatform::shutdown() 49 | { 50 | assert(mIsInitialise); 51 | mIsInitialise = false; 52 | 53 | mRenderManager->shutdown(); 54 | mDataManager->shutdown(); 55 | } 56 | 57 | OpenGLESRenderManager* OpenGLESPlatform::getRenderManagerPtr() 58 | { 59 | assert(mIsInitialise); 60 | return mRenderManager; 61 | } 62 | 63 | OpenGLESDataManager* OpenGLESPlatform::getDataManagerPtr() 64 | { 65 | assert(mIsInitialise); 66 | return mDataManager; 67 | } 68 | 69 | } // namespace MyGUI 70 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/src/MyGUI_OpenGLESRTTexture.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author Albert Semenov 4 | @date 12/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESRTTexture.cpp 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #include "MyGUI_OpenGLESRTTexture.h" 15 | #include "MyGUI_OpenGLESRenderManager.h" 16 | #include "MyGUI_OpenGLESDiagnostic.h" 17 | 18 | #include 19 | #include 20 | 21 | #include "platform.h" 22 | 23 | namespace MyGUI 24 | { 25 | 26 | OpenGLESRTTexture::OpenGLESRTTexture(unsigned int _texture) : 27 | mTextureID(_texture), 28 | mWidth(0), 29 | mHeight(0), 30 | mFBOID(0), 31 | mRBOID(0) 32 | { 33 | //int miplevel = 0; 34 | glBindTexture(GL_TEXTURE_2D, mTextureID); 35 | CHECK_GL_ERROR_DEBUG(); 36 | //glGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_WIDTH, (GLint *)&mWidth); 37 | //glGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_HEIGHT, (GLint *)&mHeight); 38 | glBindTexture(GL_TEXTURE_2D, 0); 39 | CHECK_GL_ERROR_DEBUG(); 40 | 41 | mRenderTargetInfo.maximumDepth = 1.0f; 42 | mRenderTargetInfo.hOffset = 0; 43 | mRenderTargetInfo.vOffset = 0; 44 | mRenderTargetInfo.aspectCoef = float(mHeight) / float(mWidth); 45 | mRenderTargetInfo.pixScaleX = 1.0f / float(mWidth); 46 | mRenderTargetInfo.pixScaleY = 1.0f / float(mHeight); 47 | 48 | // create a framebuffer object, you need to delete them when program exits. 49 | //glGenFramebuffersEXT(1, (GLuint *)&mFBOID); 50 | glGenFramebuffers(1, (GLuint *)&mFBOID); 51 | CHECK_GL_ERROR_DEBUG(); 52 | //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBOID); 53 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOID); 54 | CHECK_GL_ERROR_DEBUG(); 55 | 56 | // create a renderbuffer object to store depth info 57 | // NOTE: A depth renderable image should be attached the FBO for depth test. 58 | // If we don't attach a depth renderable image to the FBO, then 59 | // the rendering output will be corrupted because of missing depth test. 60 | // If you also need stencil test for your rendering, then you must 61 | // attach additional image to the stencil attachement point, too. 62 | //glGenRenderbuffersEXT(1, (GLuint *)&mRBOID); 63 | //glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mRBOID); 64 | //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, mWidth, mHeight); 65 | //glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); 66 | glGenRenderbuffers(1, (GLuint *)&mRBOID); 67 | CHECK_GL_ERROR_DEBUG(); 68 | glBindRenderbuffer(GL_RENDERBUFFER, mRBOID); 69 | CHECK_GL_ERROR_DEBUG(); 70 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, mWidth, mHeight); 71 | CHECK_GL_ERROR_DEBUG(); 72 | glBindRenderbuffer(GL_RENDERBUFFER, 0); 73 | CHECK_GL_ERROR_DEBUG(); 74 | 75 | // attach a texture to FBO color attachement point 76 | //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mTextureID, 0); 77 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextureID, 0); 78 | CHECK_GL_ERROR_DEBUG(); 79 | 80 | // attach a renderbuffer to depth attachment point 81 | //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mRBOID); 82 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mRBOID); 83 | CHECK_GL_ERROR_DEBUG(); 84 | 85 | //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 86 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 87 | CHECK_GL_ERROR_DEBUG(); 88 | } 89 | 90 | OpenGLESRTTexture::~OpenGLESRTTexture() 91 | { 92 | if (mFBOID != 0) 93 | { 94 | //glDeleteFramebuffersEXT(1, (GLuint *)&mFBOID); 95 | glDeleteFramebuffers(1, (GLuint *)&mFBOID); 96 | CHECK_GL_ERROR_DEBUG(); 97 | mFBOID = 0; 98 | } 99 | if (mRBOID != 0) 100 | { 101 | //glDeleteRenderbuffersEXT(1, (GLuint *)&mRBOID); 102 | glDeleteRenderbuffers(1, (GLuint *)&mRBOID); 103 | CHECK_GL_ERROR_DEBUG(); 104 | mRBOID = 0; 105 | } 106 | } 107 | 108 | void OpenGLESRTTexture::begin() 109 | { 110 | //glPushAttrib(GL_VIEWPORT_BIT); 111 | 112 | //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBOID); 113 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOID); 114 | CHECK_GL_ERROR_DEBUG(); 115 | 116 | glViewport(0, 0, mWidth, mHeight); 117 | CHECK_GL_ERROR_DEBUG(); 118 | 119 | OpenGLESRenderManager::getInstance().begin(); 120 | CHECK_GL_ERROR_DEBUG(); 121 | glClear(GL_COLOR_BUFFER_BIT/* | GL_DEPTH_BUFFER_BIT*/); 122 | CHECK_GL_ERROR_DEBUG(); 123 | } 124 | 125 | void OpenGLESRTTexture::end() 126 | { 127 | OpenGLESRenderManager::getInstance().end(); 128 | 129 | //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // unbind 130 | glBindFramebuffer(GL_FRAMEBUFFER, 0); // unbind 131 | CHECK_GL_ERROR_DEBUG(); 132 | } 133 | 134 | void OpenGLESRTTexture::doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count) 135 | { 136 | OpenGLESRenderManager::getInstance().doRender(_buffer, _texture, _count); 137 | } 138 | 139 | } // namespace MyGUI 140 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/src/MyGUI_OpenGLESRenderManager.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESRenderManager.cpp 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #include "MyGUI_OpenGLESRenderManager.h" 15 | #include "MyGUI_OpenGLESTexture.h" 16 | #include "MyGUI_OpenGLESVertexBuffer.h" 17 | #include "MyGUI_OpenGLESDiagnostic.h" 18 | #include "MyGUI_VertexData.h" 19 | #include "MyGUI_Gui.h" 20 | #include "MyGUI_Timer.h" 21 | 22 | #include 23 | #include "platform.h" 24 | 25 | const char* vShader = " \n\ 26 | \n\ 27 | attribute vec3 a_position; \n\ 28 | attribute vec4 a_color; \n\ 29 | attribute vec2 a_texCoord; \n\ 30 | uniform mat4 u_MVPMatrix; \n\ 31 | \n\ 32 | varying lowp vec4 v_fragmentColor; \n\ 33 | varying mediump vec2 v_texCoord; \n\ 34 | \n\ 35 | void main() \n\ 36 | { \n\ 37 | gl_Position = (vec4(a_position,1)); \n\ 38 | v_fragmentColor = a_color; \n\ 39 | v_texCoord = a_texCoord; \n\ 40 | } \n\ 41 | "; 42 | 43 | const char* fShader = " \n\ 44 | precision lowp float; \n\ 45 | varying vec4 v_fragmentColor; \n\ 46 | varying vec2 v_texCoord; \n\ 47 | uniform sampler2D u_texture; \n\ 48 | void main(void) { \n\ 49 | gl_FragColor = texture2D(u_texture, v_texCoord); \n\ 50 | } \n\ 51 | "; 52 | 53 | // attribute index 54 | enum { 55 | ATTRIB_VERTEX, 56 | ATTRIB_COLOR, 57 | NUM_ATTRIBUTES 58 | }; 59 | 60 | namespace MyGUI 61 | { 62 | 63 | OpenGLESRenderManager::OpenGLESRenderManager() : 64 | mUpdate(false), 65 | mImageLoader(nullptr), 66 | mPboIsSupported(false), 67 | mIsInitialise(false) 68 | { 69 | } 70 | 71 | void OpenGLESRenderManager::initialise(OpenGLESImageLoader* _loader) 72 | { 73 | MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 74 | MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName()); 75 | 76 | mVertexFormat = VertexColourType::ColourABGR; // WDY ??? ColourABGR 77 | 78 | mUpdate = false; 79 | mImageLoader = _loader; 80 | 81 | //glewInit(); 82 | 83 | //mPboIsSupported = glewIsExtensionSupported("GL_EXT_pixel_buffer_object") != 0; 84 | 85 | mProgram = BuildProgram(vShader, fShader); 86 | 87 | //MYGUI_PLATFORM_ASSERT(r, "ShaderProgram Initialise fails! "); 88 | 89 | //p->updateUniforms(); 90 | 91 | 92 | /* 93 | _positionSlot = glGetAttribLocation(mShaderProgram->getProgram(), "a_position"); 94 | CHECK_GL_ERROR_DEBUG(); 95 | _colorSlot = glGetAttribLocation(mShaderProgram->getProgram(), "a_color"); 96 | CHECK_GL_ERROR_DEBUG(); 97 | _texSlot = glGetAttribLocation(mShaderProgram->getProgram(), "a_texCoord"); 98 | CHECK_GL_ERROR_DEBUG(); 99 | */ 100 | 101 | MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized"); 102 | mIsInitialise = true; 103 | } 104 | 105 | void OpenGLESRenderManager::shutdown() 106 | { 107 | MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 108 | MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName()); 109 | 110 | destroyAllResources(); 111 | 112 | MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown"); 113 | mIsInitialise = false; 114 | } 115 | 116 | IVertexBuffer* OpenGLESRenderManager::createVertexBuffer() 117 | { 118 | return new OpenGLESVertexBuffer(); 119 | } 120 | 121 | void OpenGLESRenderManager::destroyVertexBuffer(IVertexBuffer* _buffer) 122 | { 123 | delete _buffer; 124 | } 125 | 126 | 127 | GLuint OpenGLESRenderManager::BuildShader(const char* source, GLenum shaderType) const 128 | { 129 | GLuint shaderHandle = glCreateShader(shaderType); 130 | glShaderSource(shaderHandle, 1, &source, 0); 131 | glCompileShader(shaderHandle); 132 | CHECK_GL_ERROR_DEBUG(); 133 | 134 | GLint compileSuccess; 135 | glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &compileSuccess); 136 | 137 | if (compileSuccess == GL_FALSE) { 138 | GLchar messages[256]; 139 | glGetShaderInfoLog(shaderHandle, sizeof(messages), 0, &messages[0]); 140 | MYGUI_PLATFORM_EXCEPT(messages); 141 | } 142 | 143 | return shaderHandle; 144 | } 145 | 146 | GLuint OpenGLESRenderManager::BuildProgram(const char* vertexShaderSource, 147 | const char* fragmentShaderSource) const 148 | { 149 | GLuint vertexShader = BuildShader(vertexShaderSource, GL_VERTEX_SHADER); 150 | GLuint fragmentShader = BuildShader(fragmentShaderSource, GL_FRAGMENT_SHADER); 151 | 152 | GLuint programHandle = glCreateProgram(); 153 | glAttachShader(programHandle, vertexShader); 154 | glAttachShader(programHandle, fragmentShader); 155 | glLinkProgram(programHandle); 156 | CHECK_GL_ERROR_DEBUG(); 157 | 158 | GLint linkSuccess; 159 | glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess); 160 | if (linkSuccess == GL_FALSE) { 161 | GLchar messages[256]; 162 | glGetProgramInfoLog(programHandle, sizeof(messages), 0, &messages[0]); 163 | MYGUI_PLATFORM_EXCEPT(messages); 164 | } 165 | 166 | return programHandle; 167 | } 168 | 169 | void OpenGLESRenderManager::doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count) 170 | { 171 | OpenGLESVertexBuffer* buffer = static_cast(_buffer); 172 | unsigned int buffer_id = buffer->getBufferID(); 173 | MYGUI_PLATFORM_ASSERT(buffer_id, "Vertex buffer is not created"); 174 | 175 | unsigned int texture_id = 0; 176 | if (_texture) 177 | { 178 | OpenGLESTexture* texture = static_cast(_texture); 179 | texture_id = texture->getTextureID(); 180 | //MYGUI_PLATFORM_ASSERT(texture_id, "Texture is not created"); 181 | } 182 | 183 | 184 | 185 | glBindTexture(GL_TEXTURE_2D, texture_id); 186 | CHECK_GL_ERROR_DEBUG(); 187 | 188 | //glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer_id); 189 | glBindBuffer(GL_ARRAY_BUFFER, buffer_id); 190 | CHECK_GL_ERROR_DEBUG(); 191 | 192 | 193 | GLuint positionSlot = glGetAttribLocation(mProgram, "a_position"); 194 | GLuint colorSlot = glGetAttribLocation(mProgram, "a_color"); 195 | GLuint texSlot = glGetAttribLocation(mProgram, "a_texCoord"); 196 | 197 | GLuint textureUniform = glGetUniformLocation(mProgram, "u_texture"); 198 | 199 | 200 | glEnableVertexAttribArray(positionSlot); 201 | glEnableVertexAttribArray(colorSlot); 202 | glEnableVertexAttribArray(texSlot); 203 | 204 | glUseProgram(mProgram); 205 | 206 | /* 207 | _positionSlot = glGetAttribLocation(mShaderProgram->getProgram(), "a_position"); 208 | _colorSlot = glGetAttribLocation(mShaderProgram->getProgram(), "a_color"); 209 | _texSlot = glGetAttribLocation(mShaderProgram->getProgram(), "a_texCoord"); 210 | 211 | glEnableVertexAttribArray(_positionSlot); 212 | glEnableVertexAttribArray(_colorSlot); 213 | glEnableVertexAttribArray(_texSlot); 214 | */ 215 | 216 | //mShaderProgram->setUniformForModelViewProjectionMatrix(); 217 | 218 | //ccGLBindTexture2D( m_uName ); 219 | 220 | #define kQuadSize sizeof(Vertex) 221 | 222 | size_t offset = 0; 223 | int diff = offsetof( Vertex, x); 224 | glVertexAttribPointer(positionSlot, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); 225 | CHECK_GL_ERROR_DEBUG(); 226 | 227 | diff = offsetof( Vertex, colour); 228 | glVertexAttribPointer(colorSlot, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*) (offset + diff)); 229 | CHECK_GL_ERROR_DEBUG(); 230 | 231 | diff = offsetof( Vertex, u); 232 | glVertexAttribPointer(texSlot, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); 233 | CHECK_GL_ERROR_DEBUG(); 234 | 235 | glUniform1i(textureUniform, 0); 236 | 237 | //glDrawElements(GL_TRIANGLES, _count, GL_UNSIGNED_BYTE, 0); 238 | glDrawArrays(GL_TRIANGLES, 0, _count); 239 | //CHECK_GL_ERROR_DEBUG(); 240 | do { 241 | GLenum __error = glGetError(); 242 | if(__error) { 243 | MYGUI_PLATFORM_LOG(Info, "OpenGLES error 0x%04X in " << __error << " " << __FILE__<< " " << __FUNCTION__<< " "<< __LINE__); 244 | MYGUI_PLATFORM_LOG(Error, "texture_id:"<getName()); 361 | MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '" << _texture->getName() << "' not found"); 362 | 363 | mTextures.erase(item); 364 | delete _texture; 365 | } 366 | 367 | ITexture* OpenGLESRenderManager::getTexture(const std::string& _name) 368 | { 369 | MapTexture::const_iterator item = mTextures.find(_name); 370 | if (item == mTextures.end()) 371 | return nullptr; 372 | return item->second; 373 | } 374 | 375 | void OpenGLESRenderManager::destroyAllResources() 376 | { 377 | for (MapTexture::const_iterator item = mTextures.begin(); item != mTextures.end(); ++item) 378 | { 379 | delete item->second; 380 | } 381 | mTextures.clear(); 382 | } 383 | 384 | 385 | } // namespace MyGUI 386 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/src/MyGUI_OpenGLESTexture.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESPlatform.cpp 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #include "MyGUI_OpenGLESTexture.h" 15 | #include "MyGUI_OpenGLESRenderManager.h" 16 | #include "MyGUI_OpenGLESDiagnostic.h" 17 | #include "MyGUI_OpenGLESPlatform.h" 18 | #include "MyGUI_OpenGLESRTTexture.h" 19 | 20 | #include "platform.h" 21 | 22 | namespace MyGUI 23 | { 24 | 25 | OpenGLESTexture::OpenGLESTexture(const std::string& _name, OpenGLESImageLoader* _loader) : 26 | mName(_name), 27 | mTextureID(0), 28 | mPboID(0), 29 | mWidth(0), 30 | mHeight(0), 31 | mLock(false), 32 | mPixelFormat(0), 33 | mDataSize(0), 34 | mUsage(0), 35 | mBuffer(0), 36 | mInternalPixelFormat(0), 37 | mAccess(0), 38 | mNumElemBytes(0), 39 | mImageLoader(_loader), 40 | mRenderTarget(nullptr) 41 | { 42 | } 43 | 44 | OpenGLESTexture::~OpenGLESTexture() 45 | { 46 | destroy(); 47 | } 48 | 49 | const std::string& OpenGLESTexture::getName() const 50 | { 51 | return mName; 52 | } 53 | 54 | void OpenGLESTexture::setUsage(TextureUsage _usage) 55 | { 56 | mAccess = 0; 57 | mUsage = 0; 58 | } 59 | 60 | void OpenGLESTexture::createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format) 61 | { 62 | createManual(_width, _height, _usage, _format, 0); 63 | } 64 | 65 | void OpenGLESTexture::createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format, void* _data) 66 | { 67 | MYGUI_PLATFORM_ASSERT(!mTextureID, "Texture already exist"); 68 | 69 | //FIXME перенести в метод 70 | mInternalPixelFormat = 0; 71 | mPixelFormat = 0; 72 | mNumElemBytes = 0; 73 | if (_format == PixelFormat::L8) 74 | { 75 | mInternalPixelFormat = GL_LUMINANCE; 76 | mPixelFormat = GL_LUMINANCE; 77 | mNumElemBytes = 1; 78 | } 79 | else if (_format == PixelFormat::L8A8) 80 | { 81 | mInternalPixelFormat = GL_LUMINANCE_ALPHA; 82 | mPixelFormat = GL_LUMINANCE_ALPHA; 83 | mNumElemBytes = 2; 84 | } 85 | else if (_format == PixelFormat::R8G8B8) 86 | { 87 | mInternalPixelFormat = GL_RGB; 88 | mPixelFormat = GL_RGB; 89 | mNumElemBytes = 3; 90 | } 91 | else if (_format == PixelFormat::R8G8B8A8) 92 | { 93 | mInternalPixelFormat = GL_RGBA; 94 | mPixelFormat = GL_RGBA; 95 | mNumElemBytes = 4; 96 | } 97 | else 98 | { 99 | MYGUI_PLATFORM_EXCEPT("format not support"); 100 | } 101 | 102 | mWidth = _width; 103 | mHeight = _height; 104 | mDataSize = _width * _height * mNumElemBytes; 105 | setUsage(_usage); 106 | //MYGUI_PLATFORM_ASSERT(mUsage, "usage format not support"); 107 | 108 | mOriginalFormat = _format; 109 | mOriginalUsage = _usage; 110 | 111 | // Set unpack alignment to one byte 112 | int alignment = 0; 113 | glGetIntegerv( GL_UNPACK_ALIGNMENT, (GLint *)&alignment ); 114 | CHECK_GL_ERROR_DEBUG(); 115 | glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); 116 | CHECK_GL_ERROR_DEBUG(); 117 | 118 | // создаем тукстуру 119 | glGenTextures(1, (GLuint *)&mTextureID); 120 | CHECK_GL_ERROR_DEBUG(); 121 | glBindTexture(GL_TEXTURE_2D, mTextureID); 122 | CHECK_GL_ERROR_DEBUG(); 123 | // Set texture parameters 124 | 125 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // GL_LINEAR 126 | CHECK_GL_ERROR_DEBUG(); 127 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 128 | CHECK_GL_ERROR_DEBUG(); 129 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 130 | CHECK_GL_ERROR_DEBUG(); 131 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 132 | CHECK_GL_ERROR_DEBUG(); 133 | 134 | glTexImage2D(GL_TEXTURE_2D, 0, mInternalPixelFormat, mWidth, mHeight, 0, mPixelFormat, GL_UNSIGNED_BYTE, (GLvoid*)_data); 135 | CHECK_GL_ERROR_DEBUG(); 136 | glBindTexture(GL_TEXTURE_2D, 0); 137 | CHECK_GL_ERROR_DEBUG(); 138 | 139 | // Restore old unpack alignment 140 | //glPixelStorei( GL_UNPACK_ALIGNMENT, alignment ); 141 | //CHECK_GL_ERROR_DEBUG(); 142 | #ifdef PixelBufferObjectSupported 143 | if (!_data && OpenGLESRenderManager::getInstance().isPixelBufferObjectSupported()) 144 | { 145 | //создаем текстурнный буфер 146 | //glGenBuffersARB(1, (GLuint *)&mPboID); 147 | //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mPboID); 148 | //glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, mDataSize, 0, mUsage); 149 | //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); 150 | 151 | glGenBuffers(1, (GLuint *)&mPboID); 152 | CHECK_GL_ERROR_DEBUG(); 153 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPboID); 154 | CHECK_GL_ERROR_DEBUG(); 155 | glBufferData(GL_PIXEL_UNPACK_BUFFER, mDataSize, 0, mUsage); 156 | CHECK_GL_ERROR_DEBUG(); 157 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 158 | CHECK_GL_ERROR_DEBUG(); 159 | 160 | } 161 | #endif 162 | } 163 | 164 | void OpenGLESTexture::destroy() 165 | { 166 | if (mRenderTarget != nullptr) 167 | { 168 | delete mRenderTarget; 169 | mRenderTarget = nullptr; 170 | } 171 | 172 | if (mTextureID != 0) 173 | { 174 | glDeleteTextures(1, (GLuint *)&mTextureID); 175 | mTextureID = 0; 176 | } 177 | if (mPboID != 0) 178 | { 179 | glDeleteBuffers(1, (GLuint *)&mPboID); 180 | mPboID = 0; 181 | } 182 | 183 | mWidth = 0; 184 | mHeight = 0; 185 | mLock = false; 186 | mPixelFormat = 0; 187 | mDataSize = 0; 188 | mUsage = 0; 189 | mBuffer = 0; 190 | mInternalPixelFormat = 0; 191 | mAccess = 0; 192 | mNumElemBytes = 0; 193 | mOriginalFormat = PixelFormat::Unknow; 194 | mOriginalUsage = TextureUsage::Default; 195 | } 196 | 197 | void* OpenGLESTexture::lock(TextureUsage _access) 198 | { 199 | MYGUI_PLATFORM_ASSERT(mTextureID, "Texture is not created"); 200 | 201 | /* 202 | if (_access == TextureUsage::Read) 203 | { 204 | glBindTexture(GL_TEXTURE_2D, mTextureID); 205 | CHECK_GL_ERROR_DEBUG(); 206 | 207 | mBuffer = new unsigned char[mDataSize]; 208 | //glGetTexImage(GL_TEXTURE_2D, 0, mPixelFormat, GL_UNSIGNED_BYTE, mBuffer); 209 | 210 | mLock = false; 211 | 212 | return mBuffer; 213 | }*/ 214 | 215 | // bind the texture 216 | glBindTexture(GL_TEXTURE_2D, mTextureID); 217 | CHECK_GL_ERROR_DEBUG(); 218 | if (!OpenGLESRenderManager::getInstance().isPixelBufferObjectSupported()) 219 | { 220 | //Fallback if PBO's are not supported 221 | mBuffer = new unsigned char[mDataSize]; 222 | } 223 | else 224 | { 225 | #ifdef PixelBufferObjectSupported 226 | // bind the PBO 227 | //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mPboID); 228 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPboID); 229 | CHECK_GL_ERROR_DEBUG(); 230 | 231 | // Note that glMapBufferARB() causes sync issue. 232 | // If GPU is working with this buffer, glMapBufferARB() will wait(stall) 233 | // until GPU to finish its job. To avoid waiting (idle), you can call 234 | // first glBufferDataARB() with NULL pointer before glMapBufferARB(). 235 | // If you do that, the previous data in PBO will be discarded and 236 | // glMapBufferARB() returns a new allocated pointer immediately 237 | // even if GPU is still working with the previous data. 238 | //glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, mDataSize, 0, mUsage); 239 | glBufferData(GL_PIXEL_UNPACK_BUFFER, mDataSize, 0, mUsage); 240 | CHECK_GL_ERROR_DEBUG(); 241 | 242 | // map the buffer object into client's memory 243 | //mBuffer = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mAccess); 244 | mBuffer = (GLubyte*)glMapBufferOES(GL_PIXEL_UNPACK_BUFFER_ARB, mAccess); 245 | CHECK_GL_ERROR_DEBUG(); 246 | if (!mBuffer) 247 | { 248 | //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); 249 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); 250 | CHECK_GL_ERROR_DEBUG(); 251 | glBindTexture(GL_TEXTURE_2D, 0); 252 | CHECK_GL_ERROR_DEBUG(); 253 | MYGUI_PLATFORM_EXCEPT("Error texture lock"); 254 | } 255 | #endif 256 | } 257 | 258 | mLock = true; 259 | 260 | return mBuffer; 261 | } 262 | 263 | void OpenGLESTexture::unlock() 264 | { 265 | if (!mLock && mBuffer) 266 | { 267 | delete (unsigned char*)mBuffer; 268 | mBuffer = 0; 269 | 270 | glBindTexture(GL_TEXTURE_2D, 0); 271 | CHECK_GL_ERROR_DEBUG(); 272 | 273 | return; 274 | } 275 | 276 | MYGUI_PLATFORM_ASSERT(mLock, "Texture is not locked"); 277 | 278 | if (!OpenGLESRenderManager::getInstance().isPixelBufferObjectSupported()) 279 | { 280 | //Fallback if PBO's are not supported 281 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mWidth, mHeight, mPixelFormat, GL_UNSIGNED_BYTE, mBuffer); 282 | CHECK_GL_ERROR_DEBUG(); 283 | delete (unsigned char*)mBuffer; 284 | } 285 | else 286 | { 287 | #ifdef PixelBufferObjectSupported 288 | // release the mapped buffer 289 | //glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); 290 | glUnmapBufferOES(GL_PIXEL_UNPACK_BUFFER_ARB); 291 | CHECK_GL_ERROR_DEBUG(); 292 | 293 | // copy pixels from PBO to texture object 294 | // Use offset instead of ponter. 295 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mWidth, mHeight, mPixelFormat, GL_UNSIGNED_BYTE, 0); 296 | CHECK_GL_ERROR_DEBUG(); 297 | 298 | // it is good idea to release PBOs with ID 0 after use. 299 | // Once bound with 0, all pixel operations are back to normal ways. 300 | //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); 301 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); 302 | CHECK_GL_ERROR_DEBUG(); 303 | #endif 304 | } 305 | 306 | glBindTexture(GL_TEXTURE_2D, 0); 307 | CHECK_GL_ERROR_DEBUG(); 308 | mBuffer = 0; 309 | mLock = false; 310 | } 311 | 312 | void OpenGLESTexture::loadFromFile(const std::string& _filename) 313 | { 314 | destroy(); 315 | 316 | if (mImageLoader) 317 | { 318 | int width = 0; 319 | int height = 0; 320 | PixelFormat format = PixelFormat::Unknow; 321 | 322 | void* data = mImageLoader->loadImage(width, height, format, _filename); 323 | if (data) 324 | { 325 | createManual(width, height, TextureUsage::Static | TextureUsage::Write, format, data); 326 | delete (unsigned char*)data; 327 | } 328 | } 329 | } 330 | 331 | void OpenGLESTexture::saveToFile(const std::string& _filename) 332 | { 333 | if (mImageLoader) 334 | { 335 | void* data = lock(TextureUsage::Read); 336 | mImageLoader->saveImage(mWidth, mHeight, mOriginalFormat, data, _filename); 337 | unlock(); 338 | } 339 | } 340 | 341 | IRenderTarget* OpenGLESTexture::getRenderTarget() 342 | { 343 | if (mRenderTarget == nullptr) 344 | mRenderTarget = new OpenGLESRTTexture(mTextureID); 345 | 346 | return mRenderTarget; 347 | } 348 | 349 | unsigned int OpenGLESTexture::getTextureID() const 350 | { 351 | return mTextureID; 352 | } 353 | 354 | } // namespace MyGUI 355 | -------------------------------------------------------------------------------- /Platforms/OpenGLES/OpenGLESPlatform/src/MyGUI_OpenGLESVertexBuffer.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | @file 3 | @author George Evmenov 4 | @date 07/2009 5 | */ 6 | 7 | // 8 | // MyGUI_OpenGLESVertexBuffer.cpp 9 | // 10 | // Created by wangdy on 10/2012. 11 | // 12 | // 13 | 14 | #include "MyGUI_OpenGLESVertexBuffer.h" 15 | #include "MyGUI_VertexData.h" 16 | #include "MyGUI_OpenGLESDiagnostic.h" 17 | 18 | #include "platform.h" 19 | #include 20 | 21 | namespace MyGUI 22 | { 23 | 24 | const size_t VERTEX_IN_QUAD = 6; 25 | const size_t RENDER_ITEM_STEEP_REALLOCK = 5 * VERTEX_IN_QUAD; 26 | 27 | OpenGLESVertexBuffer::OpenGLESVertexBuffer() : 28 | mNeedVertexCount(0), 29 | mVertexCount(RENDER_ITEM_STEEP_REALLOCK), 30 | mBufferID(0), 31 | mSizeInBytes(0) 32 | { 33 | } 34 | 35 | OpenGLESVertexBuffer::~OpenGLESVertexBuffer() 36 | { 37 | destroy(); 38 | } 39 | 40 | void OpenGLESVertexBuffer::setVertexCount(size_t _count) 41 | { 42 | if (_count != mNeedVertexCount) 43 | { 44 | mNeedVertexCount = _count; 45 | destroy(); 46 | create(); 47 | } 48 | } 49 | 50 | size_t OpenGLESVertexBuffer::getVertexCount() 51 | { 52 | return mNeedVertexCount; 53 | } 54 | 55 | Vertex* OpenGLESVertexBuffer::lock() 56 | { 57 | MYGUI_PLATFORM_ASSERT(mBufferID, "Vertex buffer in not created"); 58 | 59 | // Use glMapBuffer 60 | //glBindBufferARB(GL_ARRAY_BUFFER_ARB, mBufferID); 61 | glBindBuffer(GL_ARRAY_BUFFER, mBufferID); 62 | //CHECK_GL_ERROR_DEBUG(); 63 | 64 | GLenum __error = glGetError(); 65 | if(__error) 66 | { 67 | MYGUI_PLATFORM_LOG(Info, "OpenGL error " << __error << " in " << __FILE__<< " " << __FUNCTION__<< " "<< __LINE__); 68 | } 69 | assert(__error==0); 70 | 71 | // Discard the buffer 72 | //glBufferDataARB(GL_ARRAY_BUFFER_ARB, mSizeInBytes, 0, GL_STREAM_DRAW_ARB); 73 | glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, 0, GL_STREAM_DRAW); 74 | CHECK_GL_ERROR_DEBUG(); 75 | 76 | 77 | Vertex* pBuffer = (Vertex*)glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES); 78 | CHECK_GL_ERROR_DEBUG(); 79 | 80 | MYGUI_PLATFORM_ASSERT(pBuffer, "Error lock vertex buffer"); 81 | 82 | glBindBuffer(GL_ARRAY_BUFFER, 0); 83 | CHECK_GL_ERROR_DEBUG(); 84 | 85 | return pBuffer; 86 | } 87 | 88 | void OpenGLESVertexBuffer::unlock() 89 | { 90 | MYGUI_PLATFORM_ASSERT(mBufferID, "Vertex buffer in not created"); 91 | 92 | glBindBuffer(GL_ARRAY_BUFFER, mBufferID); 93 | CHECK_GL_ERROR_DEBUG(); 94 | GLboolean result = glUnmapBufferOES(GL_ARRAY_BUFFER); 95 | CHECK_GL_ERROR_DEBUG(); 96 | glBindBuffer(GL_ARRAY_BUFFER, 0); 97 | CHECK_GL_ERROR_DEBUG(); 98 | 99 | MYGUI_PLATFORM_ASSERT(result, "Error unlock vertex buffer"); 100 | } 101 | 102 | void OpenGLESVertexBuffer::destroy() 103 | { 104 | if (mBufferID != 0) 105 | { 106 | glDeleteBuffers(1, (GLuint*)&mBufferID); //wdy 107 | CHECK_GL_ERROR_DEBUG(); 108 | mBufferID = 0; 109 | } 110 | } 111 | 112 | void OpenGLESVertexBuffer::create() 113 | { 114 | MYGUI_PLATFORM_ASSERT(!mBufferID, "Vertex buffer already exist"); 115 | 116 | mSizeInBytes = mNeedVertexCount * sizeof(MyGUI::Vertex); 117 | void* data = 0; 118 | 119 | glGenBuffers(1, (GLuint*)&mBufferID); //wdy 120 | CHECK_GL_ERROR_DEBUG(); 121 | glBindBuffer(GL_ARRAY_BUFFER, mBufferID); 122 | CHECK_GL_ERROR_DEBUG(); 123 | glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, data, GL_STREAM_DRAW); 124 | CHECK_GL_ERROR_DEBUG(); 125 | 126 | //MYGUI_LOG(Info, mBufferID); 127 | 128 | 129 | // check data size in VBO is same as input array, if not return 0 and delete VBO 130 | int bufferSize = 0; 131 | glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, (GLint*)&bufferSize); //wdy 132 | CHECK_GL_ERROR_DEBUG(); 133 | if (mSizeInBytes != (size_t)bufferSize) 134 | { 135 | destroy(); 136 | MYGUI_PLATFORM_EXCEPT("Data size is mismatch with input array"); 137 | } 138 | 139 | glBindBuffer(GL_ARRAY_BUFFER, 0); 140 | CHECK_GL_ERROR_DEBUG(); 141 | } 142 | 143 | } // namespace MyGUI 144 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mygui-opengles 2 | -------------- 3 | 4 | MyGUI render system for OpenGL ES 2.0 and has been tested on iOS with xcode and cocos2d-x. 5 | 6 | 7 | ## Requirements ## 8 | MyGUI 3.2.0 9 | 10 | ## How to use ## 11 | Copy files of Platforms/OpenGLES into folder of MyGUI "Platforms". 12 | 13 | ## Todo ## 14 | A demo ... --------------------------------------------------------------------------------