rays 0.1.28 → 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +1 -1
- data/.doc/ext/rays/bounds.cpp +1 -1
- data/.doc/ext/rays/camera.cpp +1 -1
- data/.doc/ext/rays/color.cpp +1 -1
- data/.doc/ext/rays/color_space.cpp +1 -1
- data/.doc/ext/rays/exception.cpp +45 -0
- data/.doc/ext/rays/font.cpp +1 -1
- data/.doc/ext/rays/image.cpp +1 -1
- data/.doc/ext/rays/matrix.cpp +1 -1
- data/.doc/ext/rays/native.cpp +35 -33
- data/.doc/ext/rays/noise.cpp +1 -1
- data/.doc/ext/rays/painter.cpp +1 -1
- data/.doc/ext/rays/point.cpp +1 -1
- data/.doc/ext/rays/polygon.cpp +1 -1
- data/.doc/ext/rays/polygon_line.cpp +1 -1
- data/.doc/ext/rays/polyline.cpp +1 -1
- data/.doc/ext/rays/shader.cpp +101 -7
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +1 -1
- data/ext/rays/bounds.cpp +1 -1
- data/ext/rays/camera.cpp +1 -1
- data/ext/rays/color.cpp +1 -1
- data/ext/rays/color_space.cpp +1 -1
- data/ext/rays/defs.h +1 -0
- data/ext/rays/exception.cpp +45 -0
- data/ext/rays/extconf.rb +1 -1
- data/ext/rays/font.cpp +1 -1
- data/ext/rays/image.cpp +1 -1
- data/ext/rays/matrix.cpp +1 -1
- data/ext/rays/native.cpp +35 -33
- data/ext/rays/noise.cpp +1 -1
- data/ext/rays/painter.cpp +1 -1
- data/ext/rays/point.cpp +1 -1
- data/ext/rays/polygon.cpp +1 -1
- data/ext/rays/polygon_line.cpp +1 -1
- data/ext/rays/polyline.cpp +1 -1
- data/ext/rays/shader.cpp +102 -6
- data/include/rays/exception.h +11 -0
- data/include/rays/ruby/bitmap.h +0 -1
- data/include/rays/ruby/bounds.h +0 -2
- data/include/rays/ruby/camera.h +0 -1
- data/include/rays/ruby/color.h +0 -2
- data/include/rays/ruby/color_space.h +0 -1
- data/include/rays/ruby/defs.h +30 -0
- data/include/rays/ruby/exception.h +28 -0
- data/include/rays/ruby/font.h +0 -1
- data/include/rays/ruby/image.h +0 -1
- data/include/rays/ruby/matrix.h +0 -1
- data/include/rays/ruby/painter.h +0 -1
- data/include/rays/ruby/point.h +0 -2
- data/include/rays/ruby/polygon.h +0 -1
- data/include/rays/ruby/polyline.h +0 -1
- data/include/rays/ruby/rays.h +0 -1
- data/include/rays/ruby/shader.h +0 -1
- data/include/rays/ruby.h +2 -0
- data/include/rays/shader.h +48 -1
- data/lib/rays/painter.rb +6 -5
- data/lib/rays/point.rb +1 -0
- data/lib/rays/shader.rb +18 -5
- data/rays.gemspec +3 -3
- data/src/exception.cpp +13 -0
- data/src/image.cpp +6 -4
- data/src/opengl.cpp +20 -7
- data/src/opengl.h +5 -3
- data/src/osx/font.mm +0 -2
- data/src/osx/opengl.mm +17 -2
- data/src/painter.cpp +181 -148
- data/src/shader.cpp +333 -53
- data/src/shader.h +53 -14
- data/src/shader_program.cpp +53 -27
- data/src/shader_program.h +8 -1
- data/src/shader_source.cpp +2 -2
- data/src/texture.cpp +80 -63
- data/test/helper.rb +1 -1
- data/test/test_point.rb +6 -5
- data/test/test_rays.rb +2 -2
- data/test/test_shader.rb +151 -14
- metadata +12 -7
data/src/opengl.cpp
CHANGED
@@ -8,10 +8,10 @@ namespace Rays
|
|
8
8
|
{
|
9
9
|
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
bool
|
12
|
+
OpenGL_has_error ()
|
13
13
|
{
|
14
|
-
return glGetError();
|
14
|
+
return glGetError() != GL_NO_ERROR;
|
15
15
|
}
|
16
16
|
|
17
17
|
static String
|
@@ -24,12 +24,12 @@ namespace Rays
|
|
24
24
|
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
|
25
25
|
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
|
26
26
|
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
|
27
|
-
#
|
27
|
+
#if !defined(GL_VERSION_3_0) && !defined(GL_ES_VERSION_2_0)
|
28
28
|
case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
|
29
29
|
case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
|
30
|
+
case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
|
31
|
+
case GL_TABLE_TOO_LARGE: return "GL_TABLE_TOO_LARGE";
|
30
32
|
#endif
|
31
|
-
case 0x506: return "GL_INVALID_FRAMEBUFFER_OPERATION";
|
32
|
-
case 0x8031: return "GL_TABLE_TOO_LARGE";
|
33
33
|
default: return "UNKNOWN ERROR";
|
34
34
|
}
|
35
35
|
}
|
@@ -37,10 +37,23 @@ namespace Rays
|
|
37
37
|
void
|
38
38
|
OpenGL_check_error (const char* file, int line)
|
39
39
|
{
|
40
|
-
GLenum e =
|
40
|
+
GLenum e = glGetError();
|
41
41
|
if (e != GL_NO_ERROR)
|
42
42
|
opengl_error(file, line, "OpenGL error %s", get_error_name(e).c_str());
|
43
43
|
}
|
44
44
|
|
45
|
+
void
|
46
|
+
OpenGL_check_error (const char* file, int line, const char* format, ...)
|
47
|
+
{
|
48
|
+
GLenum e = glGetError();
|
49
|
+
if (e != GL_NO_ERROR)
|
50
|
+
{
|
51
|
+
XOT_STRINGF(format, s);
|
52
|
+
opengl_error(
|
53
|
+
file, line,
|
54
|
+
"OpenGL error %s: %s", get_error_name(e).c_str(), s.c_str());
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
45
58
|
|
46
59
|
}// Rays
|
data/src/opengl.h
CHANGED
@@ -22,13 +22,15 @@ namespace Rays
|
|
22
22
|
{
|
23
23
|
|
24
24
|
|
25
|
-
void
|
25
|
+
void OpenGL_set_context (Context context);
|
26
26
|
|
27
27
|
Context OpenGL_get_context ();
|
28
28
|
|
29
|
-
|
29
|
+
bool OpenGL_has_error ();
|
30
30
|
|
31
|
-
void
|
31
|
+
void OpenGL_check_error (const char* file, int line);
|
32
|
+
|
33
|
+
void OpenGL_check_error (const char* file, int line, const char* format, ...);
|
32
34
|
|
33
35
|
|
34
36
|
}// Rays
|
data/src/osx/font.mm
CHANGED
@@ -104,8 +104,6 @@ namespace Rays
|
|
104
104
|
|
105
105
|
CGRect rect = CGRectMake(x, context_height - height - y, width, height);
|
106
106
|
CGContextClearRect(context, rect);
|
107
|
-
//CGContextSetRGBFillColor(context, 0, 0, 0, 1);
|
108
|
-
//CGContextFillRect(context, rect);
|
109
107
|
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
|
110
108
|
|
111
109
|
CGContextSaveGState(context);
|
data/src/osx/opengl.mm
CHANGED
@@ -29,8 +29,23 @@ namespace Rays
|
|
29
29
|
static Context context = NULL;
|
30
30
|
if (!context)
|
31
31
|
{
|
32
|
-
|
33
|
-
|
32
|
+
NSOpenGLPixelFormatAttribute attribs[] =
|
33
|
+
{
|
34
|
+
//NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
|
35
|
+
//NSOpenGLPFAAccelerated, NSOpenGLPFANoRecovery,
|
36
|
+
//NSOpenGLPFADoubleBuffer,
|
37
|
+
NSOpenGLPFAAllowOfflineRenderers,
|
38
|
+
NSOpenGLPFAColorSize, 32,
|
39
|
+
NSOpenGLPFADepthSize, 32,
|
40
|
+
//NSOpenGLPFAMultisample,
|
41
|
+
//NSOpenGLPFASampleBuffers, 1,
|
42
|
+
//NSOpenGLPFASamples, 4,
|
43
|
+
0
|
44
|
+
};
|
45
|
+
NSOpenGLPixelFormat* pf = [[[NSOpenGLPixelFormat alloc]
|
46
|
+
initWithAttributes: attribs] autorelease];
|
47
|
+
context = [[[NSOpenGLContext alloc]
|
48
|
+
initWithFormat: pf shareContext: nil] autorelease];
|
34
49
|
}
|
35
50
|
return context;
|
36
51
|
}
|
data/src/painter.cpp
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
#include <memory>
|
7
7
|
#include <vector>
|
8
8
|
#include <algorithm>
|
9
|
+
#include <functional>
|
9
10
|
#include <glm/gtc/matrix_transform.hpp>
|
10
11
|
#include "rays/exception.h"
|
11
12
|
#include "rays/point.h"
|
@@ -93,7 +94,7 @@ namespace Rays
|
|
93
94
|
|
94
95
|
const Texture& texture;
|
95
96
|
|
96
|
-
|
97
|
+
Point texcoord_min, texcoord_max;
|
97
98
|
|
98
99
|
TextureInfo (
|
99
100
|
const Texture& texture,
|
@@ -236,33 +237,6 @@ namespace Rays
|
|
236
237
|
return GL_FLOAT;
|
237
238
|
}
|
238
239
|
|
239
|
-
static const Shader&
|
240
|
-
get_default_shader_for_shape ()
|
241
|
-
{
|
242
|
-
static const Shader SHADER(
|
243
|
-
"varying vec4 " VARYING_COLOR ";"
|
244
|
-
"void main ()"
|
245
|
-
"{"
|
246
|
-
" gl_FragColor = v_Color;"
|
247
|
-
"}");
|
248
|
-
return SHADER;
|
249
|
-
}
|
250
|
-
|
251
|
-
static const Shader&
|
252
|
-
get_default_shader_for_texture ()
|
253
|
-
{
|
254
|
-
static const Shader SHADER(
|
255
|
-
"varying vec4 " VARYING_TEXCOORD ";"
|
256
|
-
"varying vec4 " VARYING_COLOR ";"
|
257
|
-
"vec4 sampleTexture(vec2);"
|
258
|
-
"void main ()"
|
259
|
-
"{"
|
260
|
-
" vec4 color = sampleTexture(" VARYING_TEXCOORD ".xy);"
|
261
|
-
" gl_FragColor = v_Color * color;"
|
262
|
-
"}");
|
263
|
-
return SHADER;
|
264
|
-
}
|
265
|
-
|
266
240
|
|
267
241
|
struct Painter::Data
|
268
242
|
{
|
@@ -338,7 +312,7 @@ namespace Rays
|
|
338
312
|
const Coord3* points, size_t npoints,
|
339
313
|
const uint* indices = NULL, size_t nindices = 0,
|
340
314
|
const Coord3* texcoords = NULL,
|
341
|
-
const Shader& default_shader =
|
315
|
+
const Shader& default_shader = Shader_get_default_shader_for_shape(),
|
342
316
|
const TextureInfo* texinfo = NULL)
|
343
317
|
{
|
344
318
|
if (!points || npoints <= 0)
|
@@ -347,175 +321,234 @@ namespace Rays
|
|
347
321
|
if (!painting)
|
348
322
|
invalid_state_error(__FILE__, __LINE__, "'painting' should be true.");
|
349
323
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
indices = default_indices.get();
|
354
|
-
nindices = npoints;
|
355
|
-
}
|
356
|
-
|
357
|
-
if (!texcoords)
|
358
|
-
texcoords = points;
|
359
|
-
|
360
|
-
const ShaderProgram* program = Shader_get_program(state.shader);
|
361
|
-
if (!program || !*program)
|
362
|
-
{
|
363
|
-
program = Shader_get_program(default_shader);
|
364
|
-
if (!program || !*program) return;
|
365
|
-
}
|
324
|
+
const Shader& shader = state.shader ? state.shader : default_shader;
|
325
|
+
const ShaderProgram* program = Shader_get_program(shader);
|
326
|
+
if (!program || !*program) return;
|
366
327
|
|
367
328
|
ShaderProgram_activate(*program);
|
368
|
-
apply_builtin_uniforms(*program, texinfo);
|
369
|
-
|
370
|
-
GLint a_position = glGetAttribLocation(program->id(), ATTRIB_POSITION);
|
371
|
-
GLint a_texcoord = glGetAttribLocation(program->id(), ATTRIB_TEXCOORD);
|
372
|
-
GLint a_color = glGetAttribLocation(program->id(), ATTRIB_COLOR);
|
373
|
-
if (a_position < 0 || a_texcoord < 0 || a_color < 0)
|
374
|
-
opengl_error(__FILE__, __LINE__);
|
375
|
-
|
376
|
-
setup_vertices(
|
377
|
-
points, npoints, texcoords, color, a_position, a_texcoord, a_color);
|
378
|
-
//activate_texture(texture);
|
379
|
-
|
380
|
-
glDrawElements(mode, (GLsizei) nindices, GL_UNSIGNED_INT, indices);
|
381
|
-
OpenGL_check_error(__FILE__, __LINE__);
|
382
329
|
|
383
|
-
|
384
|
-
|
330
|
+
const auto& names = Shader_get_builtin_variable_names(shader);
|
331
|
+
apply_builtin_uniforms(*program, names, texinfo);
|
332
|
+
apply_attributes(*program, names, points, npoints, texcoords, color);
|
333
|
+
draw_indices(mode, indices, nindices, npoints);
|
334
|
+
cleanup();
|
385
335
|
|
386
336
|
ShaderProgram_deactivate();
|
387
337
|
}
|
388
338
|
|
389
339
|
private:
|
390
340
|
|
341
|
+
std::vector<GLint> locations;
|
342
|
+
|
343
|
+
std::vector<GLuint> buffers;
|
344
|
+
|
391
345
|
void apply_builtin_uniforms (
|
392
|
-
const ShaderProgram& program, const
|
346
|
+
const ShaderProgram& program, const ShaderBuiltinVariableNames& names,
|
347
|
+
const TextureInfo* texinfo)
|
393
348
|
{
|
394
|
-
|
395
|
-
|
396
|
-
|
349
|
+
const Texture* texture = texinfo ? &texinfo->texture : NULL;
|
350
|
+
|
351
|
+
Matrix texcoord_matrix(1);
|
352
|
+
if (texture && *texture)
|
397
353
|
{
|
398
|
-
|
399
|
-
|
400
|
-
|
354
|
+
texcoord_matrix.scale(
|
355
|
+
1.0 / texture->reserved_width(),
|
356
|
+
1.0 / texture->reserved_height());
|
401
357
|
}
|
402
358
|
|
403
|
-
|
404
|
-
glGetUniformLocation(program.id(), UNIFORM_TEXCOORD_MATRIX);
|
405
|
-
if (texcoord_matrix_loc >= 0)
|
359
|
+
for (const auto& name : names.uniform_position_matrix_names)
|
406
360
|
{
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
361
|
+
apply_uniform(program, name, [&](GLint loc) {
|
362
|
+
glUniformMatrix4fv(loc, 1, GL_FALSE, position_matrix.array);
|
363
|
+
});
|
364
|
+
}
|
365
|
+
for (const auto& name : names.uniform_texcoord_matrix_names)
|
366
|
+
{
|
367
|
+
apply_uniform(program, name, [&](GLint loc) {
|
368
|
+
glUniformMatrix4fv(loc, 1, GL_FALSE, texcoord_matrix.array);
|
369
|
+
});
|
411
370
|
}
|
412
371
|
|
413
|
-
|
414
|
-
}
|
415
|
-
|
416
|
-
void apply_texture_uniforms (
|
417
|
-
const ShaderProgram& program, const TextureInfo* texinfo)
|
418
|
-
{
|
419
|
-
if (!texinfo || !*texinfo) return;
|
420
|
-
|
421
|
-
const Texture& texture = texinfo->texture;
|
372
|
+
if (!texinfo || !texture || !*texture) return;
|
422
373
|
|
423
|
-
|
424
|
-
glGetUniformLocation(program.id(), UNIFORM_TEXTURE);
|
425
|
-
if (texture_loc >= 0)
|
374
|
+
for (const auto& name : names.uniform_texcoord_min_names)
|
426
375
|
{
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
OpenGL_check_error(__FILE__, __LINE__);
|
376
|
+
apply_uniform(program, name, [&](GLint loc) {
|
377
|
+
Point min = texcoord_matrix * texinfo->texcoord_min;
|
378
|
+
glUniform3fv(loc, 1, min.array);
|
379
|
+
});
|
432
380
|
}
|
433
|
-
|
434
|
-
GLint size_loc =
|
435
|
-
glGetUniformLocation(program.id(), UNIFORM_TEXTURE_SIZE);
|
436
|
-
if (size_loc >= 0)
|
381
|
+
for (const auto& name : names.uniform_texcoord_max_names)
|
437
382
|
{
|
438
|
-
|
439
|
-
|
440
|
-
|
383
|
+
apply_uniform(program, name, [&](GLint loc) {
|
384
|
+
Point max = texcoord_matrix * texinfo->texcoord_max;
|
385
|
+
glUniform3fv(loc, 1, max.array);
|
386
|
+
});
|
441
387
|
}
|
442
|
-
|
443
|
-
GLint min_loc =
|
444
|
-
glGetUniformLocation(program.id(), UNIFORM_TEXCOORD_MIN);
|
445
|
-
if (min_loc >= 0)
|
388
|
+
for (const auto& name : names.uniform_texcoord_offset_names)
|
446
389
|
{
|
447
|
-
|
448
|
-
|
390
|
+
apply_uniform(program, name, [&](GLint loc) {
|
391
|
+
Point offset(1.0 / texture->width(), 1.0 / texture->height());
|
392
|
+
glUniform3fv(loc, 1, offset.array);
|
393
|
+
});
|
394
|
+
}
|
395
|
+
for (const auto& name : names.uniform_texture_names)
|
396
|
+
{
|
397
|
+
apply_uniform(program, name, [&](GLint loc) {
|
398
|
+
glActiveTexture(GL_TEXTURE0);
|
399
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
400
|
+
|
401
|
+
glBindTexture(GL_TEXTURE_2D, texture->id());
|
402
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
403
|
+
|
404
|
+
glUniform1i(loc, 0);
|
405
|
+
});
|
449
406
|
}
|
407
|
+
}
|
450
408
|
|
451
|
-
|
452
|
-
|
453
|
-
|
409
|
+
void apply_attributes (
|
410
|
+
const ShaderProgram& program, const ShaderBuiltinVariableNames& names,
|
411
|
+
const Coord3* points, size_t npoints, const Coord3* texcoords,
|
412
|
+
const Color& color)
|
413
|
+
{
|
414
|
+
assert(points && npoints > 0);
|
415
|
+
|
416
|
+
apply_attribute(
|
417
|
+
program, names.attribute_position_names,
|
418
|
+
points, npoints);
|
419
|
+
|
420
|
+
apply_attribute(
|
421
|
+
program, names.attribute_texcoord_names,
|
422
|
+
texcoords ? texcoords : points, npoints);
|
423
|
+
|
424
|
+
#if defined(GL_VERSION_2_1) && !defined(GL_VERSION_3_0)
|
425
|
+
// to fix that GL 2.1 with glVertexAttrib4fv() draws nothing
|
426
|
+
// with specific glsl 'attribute' name.
|
427
|
+
std::vector<Color> colors(npoints, color);
|
428
|
+
apply_attribute(
|
429
|
+
program, names.attribute_color_names,
|
430
|
+
(const Coord4*) &colors[0], npoints);
|
431
|
+
#else
|
432
|
+
for (const auto& name : names.attribute_color_names)
|
454
433
|
{
|
455
|
-
|
456
|
-
|
434
|
+
apply_attribute(program, name, [&](GLint loc) {
|
435
|
+
glVertexAttrib4fv(loc, color.array);
|
436
|
+
});
|
457
437
|
}
|
438
|
+
#endif
|
458
439
|
}
|
459
440
|
|
460
|
-
|
461
|
-
|
462
|
-
const
|
463
|
-
|
441
|
+
template <typename CoordN>
|
442
|
+
void apply_attribute(
|
443
|
+
const ShaderProgram& program, const auto& names,
|
444
|
+
const CoordN* values, size_t nvalues)
|
464
445
|
{
|
465
|
-
|
446
|
+
GLuint buffer = 0;
|
447
|
+
for (const auto& name : names)
|
448
|
+
{
|
449
|
+
#ifndef IOS
|
450
|
+
if (buffer == 0)
|
451
|
+
{
|
452
|
+
buffer = create_and_bind_buffer(
|
453
|
+
GL_ARRAY_BUFFER, values, sizeof(CoordN) * nvalues);
|
454
|
+
values = 0;
|
455
|
+
}
|
456
|
+
#endif
|
457
|
+
|
458
|
+
apply_attribute(program, name, [&](GLint loc) {
|
459
|
+
glEnableVertexAttribArray(loc);
|
460
|
+
OpenGL_check_error(
|
461
|
+
__FILE__, __LINE__, "loc: %d %s\n", loc, name.c_str());
|
462
|
+
|
463
|
+
glVertexAttribPointer(
|
464
|
+
loc, CoordN::SIZE, get_gl_type<coord>(), GL_FALSE, 0, values);
|
465
|
+
|
466
|
+
locations.push_back(loc);
|
467
|
+
});
|
468
|
+
}
|
466
469
|
|
467
|
-
|
468
|
-
glVertexAttribPointer(
|
469
|
-
a_position, Coord3::SIZE, get_gl_type<coord>(),
|
470
|
-
GL_FALSE, sizeof(Coord3), points);
|
470
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
471
471
|
OpenGL_check_error(__FILE__, __LINE__);
|
472
|
+
}
|
472
473
|
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
474
|
+
void apply_attribute (
|
475
|
+
const ShaderProgram& program, const char* name,
|
476
|
+
std::function<void(GLint)> apply_fun)
|
477
|
+
{
|
478
|
+
GLint loc = glGetAttribLocation(program.id(), name);
|
479
|
+
if (loc < 0) return;
|
478
480
|
|
479
|
-
|
481
|
+
apply_fun(loc);
|
482
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
480
483
|
}
|
481
484
|
|
482
|
-
void
|
485
|
+
void apply_uniform (
|
486
|
+
const ShaderProgram& program, const char* name,
|
487
|
+
std::function<void(GLint)> apply_fun)
|
483
488
|
{
|
484
|
-
|
485
|
-
|
489
|
+
GLint loc = glGetUniformLocation(program.id(), name);
|
490
|
+
if (loc < 0) return;
|
491
|
+
|
492
|
+
apply_fun(loc);
|
486
493
|
OpenGL_check_error(__FILE__, __LINE__);
|
487
494
|
}
|
488
495
|
|
489
|
-
void
|
496
|
+
void draw_indices (
|
497
|
+
GLenum mode, const uint* indices, size_t nindices, size_t npoints)
|
490
498
|
{
|
491
|
-
if (!
|
499
|
+
if (!indices || nindices <= 0)
|
492
500
|
{
|
493
|
-
|
494
|
-
|
501
|
+
default_indices.resize(npoints);
|
502
|
+
indices = default_indices.get();
|
503
|
+
nindices = npoints;
|
495
504
|
}
|
496
505
|
|
497
|
-
|
498
|
-
|
506
|
+
#ifdef IOS
|
507
|
+
glDrawElements(mode, (GLsizei) nindices, GL_UNSIGNED_INT, indices);
|
508
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
509
|
+
#else
|
510
|
+
create_and_bind_buffer(
|
511
|
+
GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(uint) * nindices);
|
499
512
|
|
500
|
-
|
501
|
-
|
502
|
-
glBindTexture(GL_TEXTURE_2D, id);
|
513
|
+
glDrawElements(mode, (GLsizei) nindices, GL_UNSIGNED_INT, 0);
|
514
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
503
515
|
|
504
|
-
|
516
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
517
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
518
|
+
#endif
|
505
519
|
}
|
506
520
|
|
507
|
-
GLuint
|
521
|
+
GLuint create_and_bind_buffer (
|
522
|
+
GLenum target, const void* data, GLsizeiptr size)
|
508
523
|
{
|
509
|
-
|
510
|
-
|
511
|
-
|
524
|
+
GLuint id = 0;
|
525
|
+
glGenBuffers(1, &id);
|
526
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
527
|
+
|
528
|
+
buffers.push_back(id);
|
529
|
+
|
530
|
+
glBindBuffer(target, id);
|
531
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
532
|
+
|
533
|
+
glBufferData(target, size, data, GL_STREAM_DRAW);
|
534
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
535
|
+
|
536
|
+
return id;
|
512
537
|
}
|
513
538
|
|
514
|
-
void
|
539
|
+
void cleanup ()
|
515
540
|
{
|
516
|
-
|
541
|
+
for (auto loc : locations)
|
542
|
+
{
|
543
|
+
glDisableVertexAttribArray(loc);
|
544
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
545
|
+
}
|
546
|
+
|
547
|
+
glDeleteBuffers((GLsizei) buffers.size(), &buffers[0]);
|
548
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
517
549
|
|
518
|
-
|
550
|
+
locations.clear();
|
551
|
+
buffers.clear();
|
519
552
|
}
|
520
553
|
|
521
554
|
};// Painter::Data
|
@@ -530,7 +563,7 @@ namespace Rays
|
|
530
563
|
const Coord3* points, size_t npoints,
|
531
564
|
const uint* indices = NULL, size_t nindices = 0,
|
532
565
|
const Coord3* texcoords = NULL,
|
533
|
-
const Shader& default_shader =
|
566
|
+
const Shader& default_shader = Shader_get_default_shader_for_shape(),
|
534
567
|
const TextureInfo* texinfo = NULL)
|
535
568
|
{
|
536
569
|
assert(painter);
|
@@ -958,7 +991,7 @@ namespace Rays
|
|
958
991
|
TextureInfo texinfo(texture, src_x, src_y, src_x + src_w, src_y + src_h);
|
959
992
|
|
960
993
|
if (!shader)
|
961
|
-
shader = &
|
994
|
+
shader = &Shader_get_default_shader_for_texture();
|
962
995
|
|
963
996
|
draw_polygon(
|
964
997
|
painter, MODES, 0, 0, false, nostroke, points, 4, NULL, 0, texcoords,
|
@@ -1135,7 +1168,7 @@ namespace Rays
|
|
1135
1168
|
painter, self->text_image,
|
1136
1169
|
0, 0, str_w, str_h,
|
1137
1170
|
x, y, str_w, str_h,
|
1138
|
-
true, &
|
1171
|
+
true, &Shader_get_shader_for_text());
|
1139
1172
|
|
1140
1173
|
debug_draw_text(painter, font, x, y, str_w / density, str_h / density);
|
1141
1174
|
}
|