/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2009 Torus Knot Software Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef __EAGLSupport_H__
#define __EAGLSupport_H__

#include "OgreGLESSupport.h"

#ifdef __OBJC__
// Forward declarations
@class CAEAGLLayer;
@class UIWindow;
@class NSString;
typedef UIWindow *NativeWindowType;
#endif

namespace Ogre {
    class EAGLWindow;
    class EAGLESContext;

	template<class C> void removeDuplicates(C& c)
	{
		std::sort(c.begin(), c.end());
		typename C::iterator p = std::unique(c.begin(), c.end());
		c.erase(p, c.end());
	}

    class _OgrePrivate EAGLSupport : public GLESSupport
    {
        protected:
        public:
            EAGLSupport();
            virtual ~EAGLSupport();

            void start(void);
            void stop(void);
            void addConfig(void);
            String validateConfig(void);
            virtual String getDisplayName(void);
			CFDictionaryRef chooseGLConfig(const GLint *attribList, GLint *nElements);
            GLint getGLConfigAttrib(CFDictionaryRef fbConfig, GLint attribute, GLint *value);
            void * getProcAddress(const Ogre::String& name);
            RenderWindow * createWindow(bool autoCreateWindow,
                                           GLESRenderSystem *renderSystem,
                                           const String& windowTitle);

            RenderWindow * newWindow(const String& name,
                                        unsigned int width, unsigned int height,
                                        bool fullScreen,
                                        const NameValuePairList *miscParams = 0);
            virtual GLESPBuffer * createPBuffer(PixelComponentType format,
                                                   size_t width, size_t height);

#ifdef __OBJC__
            bool portraitIsSupported(void);
            bool interfaceOrientationIsSupported(NSString *orientation);

            EAGLESContext * createNewContext(CFDictionaryRef &glconfig, CAEAGLLayer *drawable, EAGLSharegroup *group) const;
            CFDictionaryRef getGLConfigFromContext(EAGLESContext context);
            CFDictionaryRef getGLConfigFromDrawable(CAEAGLLayer *drawable, unsigned int *w, unsigned int *h);
#endif
			CFDictionaryRef selectGLConfig(const int* minAttribs, const int *maxAttribs);
	};
}

#endif
