//Pobrane z http://www.opengl.org/registry/

//#include <gl/GL.h>
#include "wglext.h"
#include "glext.h"

/* Do COknoGL::InitWGL */

/*
//wyjete z glext.h
#define GL_MAJOR_VERSION 0x821B 
#define GL_MINOR_VERSION 0x821C

//wyjete z wglext.h
#define WGL_CONTEXT_MAJOR_VERSION_ARB  0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB  0x2092
#define WGL_CONTEXT_FLAGS_ARB          0x2094
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
#define WGL_CONTEXT_PROFILE_MASK_ARB   0x9126
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002

typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
*/
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;

/* Do COknoGL::InitBuforWerteksow i COknoGL::UsunBuforWerteksow */
/*
//VAO
//#define GL_VERTEX_ARRAY_BINDING  0x85B5
typedef void (WINAPI * PFNGLBINDVERTEXARRAYPROC) (GLuint array);
typedef void (WINAPI * PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
typedef void (WINAPI * PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
typedef GLboolean (WINAPI * PFNGLISVERTEXARRAYPROC) (GLuint array);
*/
PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
PFNGLISVERTEXARRAYPROC glIsVertexArray;

//VBO
/*
typedef ptrdiff_t GLsizeiptr;
#define GL_ARRAY_BUFFER  0x8892
#define GL_STATIC_DRAW   0x88E4
typedef void (WINAPI * PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
typedef void (WINAPI * PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
typedef void (WINAPI * PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
typedef GLboolean (WINAPI * PFNGLISBUFFERPROC) (GLuint buffer);
typedef void (WINAPI * PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
*/
PFNGLBINDBUFFERPROC glBindBuffer;
PFNGLDELETEBUFFERSPROC glDeleteBuffers;
PFNGLGENBUFFERSPROC glGenBuffers;
PFNGLISBUFFERPROC glIsBuffer;
PFNGLBUFFERDATAPROC glBufferData;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;

/* Shadery */
//funkcje obiektow shaderow
PFNGLCREATESHADERPROC glCreateShader;
PFNGLDELETESHADERPROC glDeleteShader;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
//obiekty programow
PFNGLGETPROGRAMIVPROC glGetProgramiv;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLUSEPROGRAMPROC glUseProgram;
//funkcje obiektow (niektore ARB)
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
PFNGLATTACHOBJECTARBPROC glAttachObjectARB; //usunac nieuzywane!!?!?!?!?!?!?!?!
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation;

//macierze
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv;

//tekstury
PFNGLACTIVETEXTUREPROC glActiveTexture;
PFNGLUNIFORM1IPROC glUniform1i;
PFNGLGENERATEMIPMAPPROC glGenerateMipmap;


/* Pobieranie adresow funkcji */

void InitAPI()
{
	//do COknoGL::InitWGL
	wglCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(::wglGetProcAddress("wglCreateContextAttribsARB"));
	
	//VAO
	glBindVertexArray = reinterpret_cast<PFNGLBINDVERTEXARRAYPROC>(::wglGetProcAddress("glBindVertexArray"));
	glDeleteVertexArrays = reinterpret_cast<PFNGLDELETEVERTEXARRAYSPROC>(::wglGetProcAddress("glDeleteVertexArrays"));
	glGenVertexArrays = reinterpret_cast<PFNGLGENVERTEXARRAYSPROC>(::wglGetProcAddress("glGenVertexArrays"));
	glIsVertexArray = reinterpret_cast<PFNGLISVERTEXARRAYPROC>(::wglGetProcAddress("glIsVertexArray"));

	//VBO
	glBindBuffer = reinterpret_cast<PFNGLBINDBUFFERPROC>(::wglGetProcAddress("glBindBuffer"));
	glDeleteBuffers = reinterpret_cast<PFNGLDELETEBUFFERSPROC>(::wglGetProcAddress("glDeleteBuffers"));
	glGenBuffers = reinterpret_cast<PFNGLGENBUFFERSPROC>(::wglGetProcAddress("glGenBuffers"));
	glIsBuffer = reinterpret_cast<PFNGLISBUFFERPROC>(::wglGetProcAddress("glIsBuffer"));
	glBufferData = reinterpret_cast<PFNGLBUFFERDATAPROC>(::wglGetProcAddress("glBufferData"));
	glEnableVertexAttribArray = reinterpret_cast<PFNGLENABLEVERTEXATTRIBARRAYPROC>(::wglGetProcAddress("glEnableVertexAttribArray"));
	glVertexAttribPointer = reinterpret_cast<PFNGLVERTEXATTRIBPOINTERPROC>(::wglGetProcAddress("glVertexAttribPointer"));
	glDisableVertexAttribArray = reinterpret_cast<PFNGLDISABLEVERTEXATTRIBARRAYPROC>(::wglGetProcAddress("glDisableVertexAttribArray"));

	//Shadery
	glCreateShader=reinterpret_cast<PFNGLCREATESHADERPROC>(::wglGetProcAddress("glCreateShader"));
	glAttachShader=reinterpret_cast<PFNGLATTACHSHADERPROC>(::wglGetProcAddress("glAttachShader"));
	glDeleteShader=reinterpret_cast<PFNGLDELETESHADERPROC>(::wglGetProcAddress("glDeleteShader"));
	glShaderSource=reinterpret_cast<PFNGLSHADERSOURCEPROC>(::wglGetProcAddress("glShaderSource"));
	glCompileShader=reinterpret_cast<PFNGLCOMPILESHADERPROC>(::wglGetProcAddress("glCompileShader"));
	glCreateProgram=reinterpret_cast<PFNGLCREATEPROGRAMPROC>(::wglGetProcAddress("glCreateProgram"));
	glLinkProgram=reinterpret_cast<PFNGLLINKPROGRAMPROC>(::wglGetProcAddress("glLinkProgram"));
	glUseProgram=reinterpret_cast<PFNGLUSEPROGRAMPROC>(::wglGetProcAddress("glUseProgram"));
	glGetShaderiv=reinterpret_cast<PFNGLGETSHADERIVPROC>(::wglGetProcAddress("glGetShaderiv"));
	glGetObjectParameterivARB=reinterpret_cast<PFNGLGETOBJECTPARAMETERIVARBPROC>(::wglGetProcAddress("glGetObjectParameterivARB"));
	glGetShaderInfoLog=reinterpret_cast<PFNGLGETSHADERINFOLOGPROC>(::wglGetProcAddress("glGetShaderInfoLog"));
	glGetInfoLogARB=reinterpret_cast<PFNGLGETINFOLOGARBPROC>(::wglGetProcAddress("glGetInfoLogARB"));
	glDeleteObjectARB=reinterpret_cast<PFNGLDELETEOBJECTARBPROC>(::wglGetProcAddress("glDeleteObject"));
	glAttachObjectARB=reinterpret_cast<PFNGLATTACHOBJECTARBPROC>(::wglGetProcAddress("glAttachObjectARB"));	
	glGetAttribLocation=reinterpret_cast<PFNGLGETATTRIBLOCATIONPROC>(::wglGetProcAddress("glGetAttribLocation"));

	//Program
	glGetProgramiv=reinterpret_cast<PFNGLGETPROGRAMIVPROC>(::wglGetProcAddress("glGetProgramiv"));
	glGetProgramInfoLog=reinterpret_cast<PFNGLGETPROGRAMINFOLOGPROC>(::wglGetProcAddress("glGetProgramInfoLog"));

	//macierze
	glGetUniformLocation=reinterpret_cast<PFNGLGETUNIFORMLOCATIONPROC>(::wglGetProcAddress("glGetUniformLocation"));
	glUniformMatrix4fv=reinterpret_cast<PFNGLUNIFORMMATRIX4FVPROC>(::wglGetProcAddress("glUniformMatrix4fv"));
	glUniformMatrix4dv=reinterpret_cast<PFNGLUNIFORMMATRIX4DVPROC>(::wglGetProcAddress("glUniformMatrix4dv"));

	//tekstury
	glActiveTexture = reinterpret_cast<PFNGLACTIVETEXTUREPROC>(::wglGetProcAddress("glActiveTexture"));
	glUniform1i = reinterpret_cast<PFNGLUNIFORM1IPROC>(::wglGetProcAddress("glUniform1i"));
	glGenerateMipmap = reinterpret_cast<PFNGLGENERATEMIPMAPPROC>(::wglGetProcAddress("glGenerateMipmap"));
}