~ubuntu-branches/debian/sid/astromenace/sid

« back to all changes in this revision

Viewing changes to AstroMenaceSource/Core/RendererInterface/OGL_VBO.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek
  • Date: 2013-04-09 02:04:25 UTC
  • Revision ID: package-import@ubuntu.com-20130409020425-a7fl9xk4diamw6di
Tags: upstream-1.3.1+repack
Import upstream version 1.3.1+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
 
 
3
        AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
 
4
        Copyright © 2006-2012 Michael Kurinnoy, Viewizard
 
5
 
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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/>.
 
19
 
 
20
 
 
21
        Web Site: http://www.viewizard.com/
 
22
        Project: http://sourceforge.net/projects/openastromenace/
 
23
        E-mail: viewizard@viewizard.com
 
24
 
 
25
*************************************************************************************/
 
26
 
 
27
 
 
28
#include "RendererInterface.h"
 
29
 
 
30
 
 
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;
 
37
 
 
38
 
 
39
 
 
40
 
 
41
 
 
42
 
 
43
//------------------------------------------------------------------------------------
 
44
// Инициализация работы с VBO
 
45
//------------------------------------------------------------------------------------
 
46
bool vw_Internal_InitializationVBO()
 
47
{
 
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");
 
54
 
 
55
        if (glGenBuffersARB == NULL || glBindBufferARB == NULL || glBufferDataARB == NULL ||
 
56
                glDeleteBuffersARB == NULL || glIsBufferARB == NULL)
 
57
        {
 
58
                glGenBuffersARB         = NULL;
 
59
                glBindBufferARB         = NULL;
 
60
                glBufferDataARB         = NULL;
 
61
                glDeleteBuffersARB      = NULL;
 
62
                glIsBufferARB           = NULL;
 
63
 
 
64
                return false;
 
65
        }
 
66
 
 
67
        return true;
 
68
}
 
69
 
 
70
 
 
71
 
 
72
 
 
73
//------------------------------------------------------------------------------------
 
74
// Процедура генерации буферов
 
75
//------------------------------------------------------------------------------------
 
76
bool vw_BuildVBO(int NumVertices, void *Data, int Stride, unsigned int *VBO)
 
77
{
 
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;
 
84
 
 
85
        glGenBuffersARB( 1, VBO );                                              // Get A Valid Name
 
86
        glBindBufferARB( GL_ARRAY_BUFFER_ARB, *VBO );   // Bind The Buffer
 
87
        // Load The Data
 
88
        glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertices*Stride*sizeof(float), Data, GL_STATIC_DRAW_ARB );
 
89
        // убираем буфер
 
90
        glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
 
91
 
 
92
        if (!glIsBufferARB(*VBO)) return false;
 
93
 
 
94
        return true;
 
95
}
 
96
 
 
97
 
 
98
//------------------------------------------------------------------------------------
 
99
// Процедура генерации индекс буферов
 
100
//------------------------------------------------------------------------------------
 
101
bool vw_BuildIBO(int NumIndex, void *Data, unsigned int *IBO)
 
102
{
 
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;
 
109
 
 
110
        glGenBuffersARB( 1, IBO );                                                              // Get A Valid Name
 
111
        glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, *IBO );   // Bind The Buffer
 
112
        // Load The Data
 
113
        glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, NumIndex*sizeof(unsigned int), Data, GL_STATIC_DRAW_ARB );
 
114
        // убираем буфер
 
115
        glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
 
116
 
 
117
        if (!glIsBufferARB(*IBO)) return false;
 
118
 
 
119
        return true;
 
120
}
 
121
 
 
122
 
 
123
//------------------------------------------------------------------------------------
 
124
// Установка текущего буфера
 
125
//------------------------------------------------------------------------------------
 
126
void vw_BindVBO(int target, unsigned int VBO)
 
127
{
 
128
        if (glBindBufferARB == NULL) return;
 
129
 
 
130
        switch (target)
 
131
        {
 
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;
 
134
        }
 
135
}
 
136
 
 
137
 
 
138
 
 
139
 
 
140
 
 
141
//------------------------------------------------------------------------------------
 
142
// Процедура удаления буфера
 
143
//------------------------------------------------------------------------------------
 
144
void vw_DeleteVBO(unsigned int VBO)
 
145
{
 
146
        if (glIsBufferARB == NULL) return;
 
147
        if (glDeleteBuffersARB == NULL) return;
 
148
 
 
149
        if (glIsBufferARB(VBO)) glDeleteBuffersARB(1, &VBO);
 
150
}
 
151