1
/************************************************************************************
3
AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
4
Copyright © 2006-2012 Michael Kurinnoy, Viewizard
7
AstroMenace is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
AstroMenace is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with AstroMenace. If not, see <http://www.gnu.org/licenses/>.
21
Web Site: http://www.viewizard.com/
22
Project: http://sourceforge.net/projects/openastromenace/
23
E-mail: viewizard@viewizard.com
25
*************************************************************************************/
28
#include "RendererInterface.h"
31
// VBO Extension Function Pointers
32
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL; // VBO Name Generation Procedure
33
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL; // VBO Bind Procedure
34
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL; // VBO Data Loading Procedure
35
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL; // VBO Deletion Procedure
36
PFNGLISBUFFERARBPROC glIsBufferARB = NULL;
43
//------------------------------------------------------------------------------------
44
// Инициализация работы с VBO
45
//------------------------------------------------------------------------------------
46
bool vw_Internal_InitializationVBO()
48
// Get Pointers To The GL Functions
49
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) SDL_GL_GetProcAddress("glGenBuffersARB");
50
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) SDL_GL_GetProcAddress("glBindBufferARB");
51
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) SDL_GL_GetProcAddress("glBufferDataARB");
52
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) SDL_GL_GetProcAddress("glDeleteBuffersARB");
53
glIsBufferARB = (PFNGLISBUFFERARBPROC) SDL_GL_GetProcAddress("glIsBufferARB");
55
if (glGenBuffersARB == NULL || glBindBufferARB == NULL || glBufferDataARB == NULL ||
56
glDeleteBuffersARB == NULL || glIsBufferARB == NULL)
58
glGenBuffersARB = NULL;
59
glBindBufferARB = NULL;
60
glBufferDataARB = NULL;
61
glDeleteBuffersARB = NULL;
73
//------------------------------------------------------------------------------------
74
// Процедура генерации буферов
75
//------------------------------------------------------------------------------------
76
bool vw_BuildVBO(int NumVertices, void *Data, int Stride, unsigned int *VBO)
78
if (Data == 0) return false;
79
if (VBO == 0) return false;
80
if (glGenBuffersARB == NULL) return false;
81
if (glBindBufferARB == NULL) return false;
82
if (glBufferDataARB == NULL) return false;
83
if (glIsBufferARB == NULL) return false;
85
glGenBuffersARB( 1, VBO ); // Get A Valid Name
86
glBindBufferARB( GL_ARRAY_BUFFER_ARB, *VBO ); // Bind The Buffer
88
glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertices*Stride*sizeof(float), Data, GL_STATIC_DRAW_ARB );
90
glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
92
if (!glIsBufferARB(*VBO)) return false;
98
//------------------------------------------------------------------------------------
99
// Процедура генерации индекс буферов
100
//------------------------------------------------------------------------------------
101
bool vw_BuildIBO(int NumIndex, void *Data, unsigned int *IBO)
103
if (Data == 0) return false;
104
if (IBO == 0) return false;
105
if (glGenBuffersARB == NULL) return false;
106
if (glBindBufferARB == NULL) return false;
107
if (glBufferDataARB == NULL) return false;
108
if (glIsBufferARB == NULL) return false;
110
glGenBuffersARB( 1, IBO ); // Get A Valid Name
111
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, *IBO ); // Bind The Buffer
113
glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, NumIndex*sizeof(unsigned int), Data, GL_STATIC_DRAW_ARB );
115
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
117
if (!glIsBufferARB(*IBO)) return false;
123
//------------------------------------------------------------------------------------
124
// Установка текущего буфера
125
//------------------------------------------------------------------------------------
126
void vw_BindVBO(int target, unsigned int VBO)
128
if (glBindBufferARB == NULL) return;
132
case RI_ARRAY_BUFFER: glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO); break;
133
case RI_ELEMENT_ARRAY_BUFFER: glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, VBO); break;
141
//------------------------------------------------------------------------------------
142
// Процедура удаления буфера
143
//------------------------------------------------------------------------------------
144
void vw_DeleteVBO(unsigned int VBO)
146
if (glIsBufferARB == NULL) return;
147
if (glDeleteBuffersARB == NULL) return;
149
if (glIsBufferARB(VBO)) glDeleteBuffersARB(1, &VBO);