//  @ Project : hello eagl ++
//  @ File Name : eglView.h
//  @ Date : 2008-9-8
//  @ Author : kongfu.yang
//  @ Company : http://www.play3d.net
//  @ Copyright : 2008-9, Example source license. 
//        By keep this header comment, 
//        you may use this source file in your project for non-commercial or commercial purpose.

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#include <OpenGLES/ES1/gl.h>
/**
 * OpenGL ES View
 * This view has capacity to display OpenGL ES content.
 * But the OpenGL ES system is not initialized inside,
 * it depends on extern c function void init_egl(NativeWindow) to do it.
 * It doesn't call rendering too, the user has to hold the context and surface by himself.
 *
 * Apple finally hide all EGL details and provide a wrapper class in objc
 * So that we have to do all initialization inside now.
 * We still may trigger some callbacks using gl prefixed functions only.
 */
@interface eglView : UIView 
{
   @private
	GLint backingWidth;
	GLint backingHeight;
	
	EAGLContext * context;
	GLuint viewRenderbuffer, viewFramebuffer;
	
	GLuint depthRenderbuffer;
}

- (BOOL)createFramebuffer;
- (void)destroyFramebuffer;

@end

extern "C" {
	
	/**
	 * Return native window of this view.
	 */
	//- (EAGLNativeWindow) getNativeWindow;
	// active the context with the surface
	// return 0 if success, else use OpenGL call to get error code.
	int makeCurrent(void);
	
	// swap buffers to show the drawing
	// return 0 if success, else use OpenGL call to get error code.
	int swapBuffers(void);
	
}

