Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_immediate_internal.h « intern « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e885cdc89e7405df2554686449952d76addd976d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2012 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Jason Wilkins.
*
* ***** END GPL LICENSE BLOCK *****
*/

/** \file blender/gpu/intern/gpu_internal.h
*  \ingroup gpu
*/

#ifndef _GPU_IMMEDIATE_INTERNAL_H_
#define _GPU_IMMEDIATE_INTERNAL_H_

#include "gpu_immediate_inline.h"

#ifdef __cplusplus
extern "C" {
#endif



#if GPU_SAFETY

/* Define some useful, but slow, checks for correct API usage. */

BLI_INLINE void GPU_CHECK_NO_ERROR(void)
{
	GLboolean no_gl_error = GL_TRUE;

	for (;;) {
		GLenum error = glGetError();

		if (error == GL_NO_ERROR) {
			break;
		}
		else {
			no_gl_error = GL_FALSE;
			printf("gl error: %s\n", gpuErrorString(error));
		}
	}

	GPU_ASSERT(no_gl_error);
}

/* Each block contains variables that can be inspected by a
   debugger in the event that an assert is triggered. */

#define GPU_CHECK_CAN_SETUP()     \
    {                             \
    GLboolean immediateOK;        \
    GLboolean noLockOK;           \
    GLboolean noBeginOK;          \
    GPU_CHECK_BASE(immediateOK);  \
    GPU_CHECK_NO_LOCK(noLockOK)   \
    GPU_CHECK_NO_BEGIN(noBeginOK) \
    }

#define GPU_CHECK_CAN_PUSH()                                    \
    {                                                           \
    GLboolean immediateStackOK;                                 \
    GLboolean noLockOK;                                         \
    GLboolean noBeginOK;                                        \
    GPU_SAFE_RETURN(immediateStack == NULL, immediateStackOK,); \
    GPU_SAFE_RETURN(GPU_IMMEDIATE->buffer == NULL, noLockOK,);  \
    GPU_SAFE_RETURN(GPU_IMMEDIATE->lockCount == 0, noBeginOK,); \
    }

#define GPU_CHECK_CAN_POP()                                          \
    {                                                                \
    GLboolean immediateOK;                                           \
    GLboolean noLockOK;                                              \
    GLboolean noBeginOK;                                             \
    GPU_SAFE_RETURN(GPU_IMMEDIATE != NULL, immediateOK, NULL);       \
    GPU_SAFE_RETURN(GPU_IMMEDIATE->buffer == NULL, noLockOK, NULL);  \
    GPU_SAFE_RETURN(GPU_IMMEDIATE->lockCount == 0, noBeginOK, NULL); \
    }

#define GPU_CHECK_CAN_LOCK()       \
    {                              \
    GLboolean immediateOK;         \
    GLboolean noBeginOK;           \
    GLboolean noLockOK;            \
    GPU_CHECK_BASE(immediateOK);   \
    GPU_CHECK_NO_BEGIN(noBeginOK); \
    GPU_CHECK_NO_LOCK(noLockOK);   \
    }

#define GPU_CHECK_CAN_UNLOCK()      \
    {                               \
    GLboolean immediateOK;          \
    GLboolean isLockedOK;           \
    GLboolean noBeginOK;            \
    GPU_CHECK_BASE(immediateOK);    \
    GPU_CHECK_IS_LOCKED(isLockedOK) \
    GPU_CHECK_NO_BEGIN(noBeginOK)   \
    }

#define GPU_CHECK_CAN_CURRENT()    \
    {                              \
    GLboolean immediateOK;         \
    GLboolean noBeginOK;           \
    GPU_CHECK_BASE(immediateOK);   \
    GPU_CHECK_NO_BEGIN(noBeginOK); \
    }

#define GPU_CHECK_CAN_GET_COLOR()                                  \
    {                                                              \
    GLboolean immediateOK;                                         \
    GLboolean noBeginOK;                                           \
    GLboolean isColorValidOK;                                      \
    GPU_CHECK_BASE(immediateOK);                                   \
    GPU_CHECK_NO_BEGIN(noBeginOK);                                 \
    GPU_SAFE_RETURN(GPU_IMMEDIATE->isColorValid, isColorValidOK,); \
    }

#define GPU_CHECK_CAN_GET_NORMAL()                                   \
    {                                                                \
    GLboolean immediateOK;                                           \
    GLboolean noBeginOK;                                             \
    GLboolean isNormalValidOK;                                       \
    GPU_CHECK_BASE(immediateOK);                                     \
    GPU_CHECK_NO_BEGIN(noBeginOK);                                   \
    GPU_SAFE_RETURN(GPU_IMMEDIATE->isNormalValid, isNormalValidOK,); \
    }

#define GPU_SAFE_STMT(var, test, stmt) \
    var = (GLboolean)(test);           \
    GPU_ASSERT((#test, var));          \
    if (var) {                         \
        stmt;                          \
    }

#else

#define GPU_CHECK_NO_ERROR()    ((void)0)

#define GPU_CHECK_CAN_SETUP()
#define GPU_CHECK_CAN_PUSH()
#define GPU_CHECK_CAN_POP()
#define GPU_CHECK_CAN_LOCK()
#define GPU_CHECK_CAN_UNLOCK()

#define GPU_CHECK_CAN_CURRENT()
#define GPU_CHECK_CAN_GET_COLOR()
#define GPU_CHECK_CAN_GET_NORMAL()

#define GPU_SAFE_STMT(var, test, stmt) { (void)(var); stmt; }

#endif



GLsizei gpu_calc_stride(void);

#ifndef GLES

void gpu_lock_buffer_gl11(void);
void gpu_unlock_buffer_gl11(void);
void gpu_begin_buffer_gl11(void);
void gpu_end_buffer_gl11(void);
void gpu_shutdown_buffer_gl11(GPUimmediate *restrict immediate);
void gpu_current_color_gl11(void);
void gpu_get_current_color_gl11(GLfloat *restrict v);
void gpu_current_normal_gl11(void);
void gpu_index_begin_buffer_gl11(void);
void gpu_index_end_buffer_gl11(void);
void gpu_index_shutdown_buffer_gl11(GPUindex *restrict index);
void gpu_draw_elements_gl11(void);
void gpu_draw_range_elements_gl11(void);

#endif

void gpu_lock_buffer_glsl(void);
void gpu_unlock_buffer_glsl(void);
void gpu_begin_buffer_glsl(void);
void gpu_end_buffer_glsl(void);
void gpu_shutdown_buffer_glsl(GPUimmediate *restrict immediate);
void gpu_current_color_glsl(void);
void gpu_get_current_color_glsl(GLfloat *restrict v);
void gpu_current_normal_glsl(void);
void gpu_index_begin_buffer_glsl(void);
void gpu_index_end_buffer_glsl(void);
void gpu_index_shutdown_buffer_glsl(GPUindex *restrict index);
void gpu_draw_elements_glsl(void);
void gpu_draw_range_elements_glsl(void);

void gpu_quad_elements_init(void);

void gpu_lock_buffer_vbo(void);
void gpu_unlock_buffer_vbo(void);
void gpu_begin_buffer_vbo(void);
void gpu_end_buffer_vbo(void);
void gpu_shutdown_buffer_vbo(GPUimmediate *restrict immediate);
void gpu_current_color_vbo(void);
void gpu_get_current_color_vbo(GLfloat *restrict v);
void gpu_current_normal_vbo(void);
void gpu_index_begin_buffer_vbo(void);
void gpu_index_end_buffer_vbo(void);
void gpu_index_shutdown_buffer_vbo(GPUindex *restrict index);
void gpu_draw_elements_vbo(void);
void gpu_draw_range_elements_vbo(void);



#ifdef __cplusplus
}
#endif

#endif /* _GPU_INTERNAL_H_ */