rays 0.1.11 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +88 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +94 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +49 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +21 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +21 -0
- data/src/ios/bitmap.mm +129 -110
- data/src/ios/camera.mm +236 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +21 -0
- data/src/osx/bitmap.mm +129 -110
- data/src/osx/camera.mm +236 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/src/polygon.h
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_POLYGON_H__
|
4
|
+
#define __RAYS_SRC_POLYGON_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <vector>
|
8
|
+
#include <rays/polygon.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class Painter;
|
16
|
+
struct Color;
|
17
|
+
|
18
|
+
|
19
|
+
void Polygon_fill (
|
20
|
+
const Polygon& polygon, Painter* painter, const Color& color);
|
21
|
+
|
22
|
+
void Polygon_stroke (
|
23
|
+
const Polygon& polygon, Painter* painter, const Color& color);
|
24
|
+
|
25
|
+
bool Polygon_triangulate (
|
26
|
+
Polygon::TrianglePointList* triangles, const Polygon& polygon);
|
27
|
+
|
28
|
+
|
29
|
+
}// Rays
|
30
|
+
|
31
|
+
|
32
|
+
#endif//EOH
|
data/src/polyline.cpp
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
#include "polyline.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <assert.h>
|
5
|
+
#include "rays/debug.h"
|
6
|
+
|
7
|
+
|
8
|
+
using namespace ClipperLib;
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
struct Polyline::Data
|
16
|
+
{
|
17
|
+
|
18
|
+
PointList points;
|
19
|
+
|
20
|
+
bool loop = false;
|
21
|
+
|
22
|
+
template <typename I, typename FUN>
|
23
|
+
void reset (I begin, I end, bool loop_, FUN to_point_fun)
|
24
|
+
{
|
25
|
+
size_t size = end - begin;
|
26
|
+
if (0 < size && size < 3 && loop_)
|
27
|
+
argument_error(__FILE__, __LINE__);
|
28
|
+
|
29
|
+
points.clear();
|
30
|
+
points.reserve(size);
|
31
|
+
for (auto it = begin; it != end; ++it)
|
32
|
+
points.emplace_back(to_point_fun(*it));
|
33
|
+
|
34
|
+
loop = loop_ && size > 0;
|
35
|
+
}
|
36
|
+
|
37
|
+
};// Polyline::Data
|
38
|
+
|
39
|
+
|
40
|
+
void
|
41
|
+
Polyline_create (
|
42
|
+
Polyline* polyline, const Path& path, bool loop, bool reverse)
|
43
|
+
{
|
44
|
+
assert(polyline);
|
45
|
+
|
46
|
+
Path cleaned;
|
47
|
+
ClipperLib::CleanPolygon(path, cleaned);
|
48
|
+
|
49
|
+
auto to_point = [](const IntPoint& point) {return from_clipper(point);};
|
50
|
+
if (reverse)
|
51
|
+
polyline->self->reset(cleaned.rbegin(), cleaned.rend(), loop, to_point);
|
52
|
+
else
|
53
|
+
polyline->self->reset(cleaned. begin(), cleaned. end(), loop, to_point);
|
54
|
+
}
|
55
|
+
|
56
|
+
template <typename I>
|
57
|
+
static void
|
58
|
+
reset_path (Path* path, I begin, I end)
|
59
|
+
{
|
60
|
+
path->clear();
|
61
|
+
for (auto it = begin; it != end; ++it)
|
62
|
+
path->emplace_back(to_clipper(*it));
|
63
|
+
}
|
64
|
+
|
65
|
+
void
|
66
|
+
Polyline_get_path (Path* path, const Polyline& polyline, bool reverse)
|
67
|
+
{
|
68
|
+
assert(path);
|
69
|
+
|
70
|
+
const auto& points = polyline.self->points;
|
71
|
+
if (reverse)
|
72
|
+
reset_path(path, points.rbegin(), points.rend());
|
73
|
+
else
|
74
|
+
reset_path(path, points. begin(), points. end());
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
Polyline::Polyline ()
|
79
|
+
{
|
80
|
+
}
|
81
|
+
|
82
|
+
Polyline::Polyline (const Point* points, size_t size, bool loop)
|
83
|
+
{
|
84
|
+
self->reset(points, points + size, loop, [](const Point& p) {return p;});
|
85
|
+
}
|
86
|
+
|
87
|
+
Polyline::~Polyline ()
|
88
|
+
{
|
89
|
+
}
|
90
|
+
|
91
|
+
bool
|
92
|
+
Polyline::expand (
|
93
|
+
Polygon* result,
|
94
|
+
coord width, CapType cap, JoinType join, coord miter_limit) const
|
95
|
+
{
|
96
|
+
return Polyline_expand(result, *this, width, cap, join, miter_limit);
|
97
|
+
}
|
98
|
+
|
99
|
+
Bounds
|
100
|
+
Polyline::bounds () const
|
101
|
+
{
|
102
|
+
if (empty()) return Bounds(-1, -1, -1);
|
103
|
+
|
104
|
+
auto it = begin();
|
105
|
+
Bounds b(*it++, 0);
|
106
|
+
for (auto end = this->end(); it != end; ++it)
|
107
|
+
b |= *it;
|
108
|
+
return b;
|
109
|
+
}
|
110
|
+
|
111
|
+
bool
|
112
|
+
Polyline::loop () const
|
113
|
+
{
|
114
|
+
return self->loop;
|
115
|
+
}
|
116
|
+
|
117
|
+
size_t
|
118
|
+
Polyline::size () const
|
119
|
+
{
|
120
|
+
return self->points.size();
|
121
|
+
}
|
122
|
+
|
123
|
+
bool
|
124
|
+
Polyline::empty () const
|
125
|
+
{
|
126
|
+
return size() <= 0;
|
127
|
+
}
|
128
|
+
|
129
|
+
Polyline::const_iterator
|
130
|
+
Polyline::begin () const
|
131
|
+
{
|
132
|
+
return self->points.begin();
|
133
|
+
}
|
134
|
+
|
135
|
+
Polyline::const_iterator
|
136
|
+
Polyline::end () const
|
137
|
+
{
|
138
|
+
return self->points.end();
|
139
|
+
}
|
140
|
+
|
141
|
+
const Point&
|
142
|
+
Polyline::operator [] (size_t index) const
|
143
|
+
{
|
144
|
+
return self->points[index];
|
145
|
+
}
|
146
|
+
|
147
|
+
Polyline::operator bool () const
|
148
|
+
{
|
149
|
+
size_t s = size();
|
150
|
+
return !((s == 1 || s == 2) && self->loop);
|
151
|
+
}
|
152
|
+
|
153
|
+
bool
|
154
|
+
Polyline::operator ! () const
|
155
|
+
{
|
156
|
+
return !operator bool();
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
}// Rays
|
data/src/polyline.h
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_POLYLINE_H__
|
4
|
+
#define __RAYS_SRC_POLYLINE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <float.h>
|
8
|
+
#include <clipper.hpp>
|
9
|
+
#include <rays/polyline.h>
|
10
|
+
#include <rays/exception.h>
|
11
|
+
|
12
|
+
|
13
|
+
namespace Rays
|
14
|
+
{
|
15
|
+
|
16
|
+
|
17
|
+
static const double CLIPPER_SCALE = 1000;
|
18
|
+
|
19
|
+
|
20
|
+
inline ClipperLib::cInt
|
21
|
+
to_clipper (coord value)
|
22
|
+
{
|
23
|
+
return (ClipperLib::cInt) (value * CLIPPER_SCALE);
|
24
|
+
}
|
25
|
+
|
26
|
+
inline coord
|
27
|
+
from_clipper (ClipperLib::cInt value)
|
28
|
+
{
|
29
|
+
double v = value / CLIPPER_SCALE;
|
30
|
+
if (v <= -FLT_MAX || FLT_MAX <= v)
|
31
|
+
argument_error(__FILE__, __LINE__);
|
32
|
+
|
33
|
+
return (coord) v;
|
34
|
+
}
|
35
|
+
|
36
|
+
inline ClipperLib::IntPoint
|
37
|
+
to_clipper (const Point& point)
|
38
|
+
{
|
39
|
+
return ClipperLib::IntPoint(
|
40
|
+
to_clipper(point.x),
|
41
|
+
to_clipper(point.y));
|
42
|
+
}
|
43
|
+
|
44
|
+
inline Point
|
45
|
+
from_clipper (const ClipperLib::IntPoint& point)
|
46
|
+
{
|
47
|
+
return Point(
|
48
|
+
from_clipper(point.X),
|
49
|
+
from_clipper(point.Y));
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
void Polyline_create (
|
54
|
+
Polyline* polyline, const ClipperLib::Path& path, bool loop,
|
55
|
+
bool reverse = false);
|
56
|
+
|
57
|
+
void Polyline_get_path (
|
58
|
+
ClipperLib::Path* path, const Polyline& polyline,
|
59
|
+
bool reverse = false);
|
60
|
+
|
61
|
+
bool Polyline_expand (
|
62
|
+
Polygon* result, const Polyline& polyline,
|
63
|
+
coord width, CapType cap, JoinType join, coord miter_limit);
|
64
|
+
|
65
|
+
|
66
|
+
}// Rays
|
67
|
+
|
68
|
+
|
69
|
+
#endif//EOH
|
data/src/render_buffer.cpp
CHANGED
@@ -41,15 +41,22 @@ namespace Rays
|
|
41
41
|
|
42
42
|
GLuint id_ = 0;
|
43
43
|
glGenRenderbuffers(1, &id_);
|
44
|
-
|
44
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
45
45
|
|
46
46
|
id = id_;
|
47
47
|
glBindRenderbuffer(GL_RENDERBUFFER, id_);
|
48
|
-
|
48
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
49
49
|
|
50
50
|
glRenderbufferStorage(
|
51
|
-
GL_RENDERBUFFER,
|
52
|
-
|
51
|
+
GL_RENDERBUFFER,
|
52
|
+
#ifdef IOS
|
53
|
+
GL_DEPTH_COMPONENT16,
|
54
|
+
#else
|
55
|
+
GL_DEPTH_COMPONENT24,
|
56
|
+
#endif
|
57
|
+
width,
|
58
|
+
height);
|
59
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
53
60
|
|
54
61
|
width = width_;
|
55
62
|
height = height_;
|
data/src/render_buffer.h
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
#include <xot/pimpl.h>
|
8
8
|
#include <rays/defs.h>
|
9
|
-
#include
|
9
|
+
#include "opengl.h"
|
10
10
|
|
11
11
|
|
12
12
|
namespace Rays
|
@@ -36,7 +36,7 @@ namespace Rays
|
|
36
36
|
|
37
37
|
struct Data;
|
38
38
|
|
39
|
-
Xot::
|
39
|
+
Xot::PSharedImpl<Data> self;
|
40
40
|
|
41
41
|
};// RenderBuffer
|
42
42
|
|
data/src/shader.cpp
CHANGED
@@ -1,187 +1,244 @@
|
|
1
|
-
#include "
|
1
|
+
#include "shader.h"
|
2
2
|
|
3
3
|
|
4
|
-
#ifndef IOS
|
5
|
-
#define USE_SHADER
|
6
|
-
#endif
|
7
|
-
|
8
|
-
|
9
|
-
#ifdef USE_SHADER
|
10
|
-
|
11
|
-
|
12
|
-
#include <boost/scoped_array.hpp>
|
13
4
|
#include "rays/exception.h"
|
5
|
+
#include "opengl.h"
|
6
|
+
#include "image.h"
|
7
|
+
#include "shader_program.h"
|
8
|
+
#include "shader_source.h"
|
14
9
|
|
15
10
|
|
16
11
|
namespace Rays
|
17
12
|
{
|
18
13
|
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
15
|
+
static const ShaderSource&
|
16
|
+
get_vertex_shader_source ()
|
17
|
+
{
|
18
|
+
static const ShaderSource SOURCE(
|
19
|
+
GL_VERTEX_SHADER,
|
20
|
+
"attribute vec3 " ATTRIB_POSITION ";"
|
21
|
+
"varying vec4 " VARYING_POSITION ";"
|
22
|
+
"uniform mat4 " UNIFORM_POSITION_MATRIX ";"
|
23
|
+
"attribute vec3 " ATTRIB_TEXCOORD ";"
|
24
|
+
"varying vec4 " VARYING_TEXCOORD ";"
|
25
|
+
"uniform mat4 " UNIFORM_TEXCOORD_MATRIX ";"
|
26
|
+
"attribute vec4 " ATTRIB_COLOR ";"
|
27
|
+
"varying vec4 " VARYING_COLOR ";"
|
28
|
+
"void main ()"
|
29
|
+
"{"
|
30
|
+
" vec4 pos = vec4(" ATTRIB_POSITION ", 1.0);"
|
31
|
+
" vec4 texcoord = vec4(" ATTRIB_TEXCOORD ", 1.0);"
|
32
|
+
VARYING_POSITION " = pos;"
|
33
|
+
VARYING_TEXCOORD " = " UNIFORM_TEXCOORD_MATRIX " * texcoord;"
|
34
|
+
VARYING_COLOR " = " ATTRIB_COLOR ";"
|
35
|
+
" gl_Position = " UNIFORM_POSITION_MATRIX " * pos;"
|
36
|
+
"}");
|
37
|
+
return SOURCE;
|
38
|
+
}
|
39
|
+
|
40
|
+
static ShaderSource
|
41
|
+
make_fragment_shader_source (const char* source)
|
42
|
+
{
|
43
|
+
static String SHARED_HEADER =
|
44
|
+
"#ifdef GL_ES\n"
|
45
|
+
"precision mediump float;\n"
|
46
|
+
"#endif\n"
|
47
|
+
"uniform sampler2D " UNIFORM_TEXTURE ";"
|
48
|
+
"uniform vec2 " UNIFORM_TEXTURE_SIZE ";"
|
49
|
+
"uniform vec2 " UNIFORM_TEXCOORD_MIN ";"
|
50
|
+
"uniform vec2 " UNIFORM_TEXCOORD_MAX ";"
|
51
|
+
"vec2 normalizeTexCoord(vec2 texcoord)"
|
52
|
+
"{"
|
53
|
+
" vec2 min = " UNIFORM_TEXCOORD_MIN ";"
|
54
|
+
" vec2 len = " UNIFORM_TEXCOORD_MAX " - min;"
|
55
|
+
" return (mod(texcoord - min, len) + min) / " UNIFORM_TEXTURE_SIZE ";"
|
56
|
+
"}"
|
57
|
+
"vec4 sampleTexture(vec2 texcoord)"
|
58
|
+
"{"
|
59
|
+
" return texture2D(" UNIFORM_TEXTURE ", normalizeTexCoord(texcoord));"
|
60
|
+
"}\n";
|
61
|
+
return ShaderSource(GL_FRAGMENT_SHADER, SHARED_HEADER + source);
|
62
|
+
}
|
34
63
|
|
35
|
-
void clear ()
|
36
|
-
{
|
37
|
-
if (id >= 0) glDeleteShader((GLuint) id);
|
38
64
|
|
39
|
-
|
40
|
-
|
65
|
+
struct Shader::Data
|
66
|
+
{
|
41
67
|
|
42
|
-
|
43
|
-
{
|
44
|
-
return id >= 0;
|
45
|
-
}
|
68
|
+
std::unique_ptr<ShaderProgram> program;
|
46
69
|
|
47
70
|
};// Shader::Data
|
48
71
|
|
49
72
|
|
50
|
-
|
51
|
-
|
73
|
+
const ShaderProgram*
|
74
|
+
Shader_get_program (const Shader& shader)
|
52
75
|
{
|
53
|
-
|
54
|
-
argument_error(__FILE__, __LINE__);
|
55
|
-
|
56
|
-
Shader::Data* self = this_->self.get();
|
57
|
-
if (self->is_valid())
|
58
|
-
invalid_state_error(__FILE__, __LINE__);
|
59
|
-
|
60
|
-
self->id = glCreateShader(GL_FRAGMENT_SHADER);
|
61
|
-
glShaderSource(self->id, 1, &source, NULL);
|
62
|
-
glCompileShader(self->id);
|
63
|
-
|
64
|
-
GLint status = GL_FALSE;
|
65
|
-
glGetShaderiv(self->id, GL_COMPILE_STATUS, &status);
|
66
|
-
if (status == GL_FALSE)
|
67
|
-
{
|
68
|
-
int len = 0;
|
69
|
-
glGetShaderiv(self->id, GL_INFO_LOG_LENGTH, &len);
|
70
|
-
|
71
|
-
boost::scoped_array<char> buffer(new char[len]);
|
72
|
-
int written = 0;
|
73
|
-
glGetShaderInfoLog(self->id, len, &written, &buffer[0]);
|
74
|
-
|
75
|
-
opengl_error(__FILE__, __LINE__, &buffer[0]);
|
76
|
-
}
|
77
|
-
|
78
|
-
check_error(__FILE__, __LINE__);
|
76
|
+
return shader.self->program ? shader.self->program.get() : NULL;
|
79
77
|
}
|
80
78
|
|
81
79
|
|
82
|
-
Shader::Shader ()
|
83
|
-
{
|
84
|
-
}
|
85
|
-
|
86
80
|
Shader::Shader (const char* source)
|
87
81
|
{
|
88
|
-
|
82
|
+
if (!source) return;
|
83
|
+
|
84
|
+
self->program.reset(new ShaderProgram(
|
85
|
+
get_vertex_shader_source(),
|
86
|
+
make_fragment_shader_source(source)));
|
89
87
|
}
|
90
88
|
|
91
89
|
Shader::~Shader ()
|
92
90
|
{
|
93
91
|
}
|
94
92
|
|
95
|
-
|
96
|
-
Shader::
|
93
|
+
void
|
94
|
+
Shader::set_uniform (const char* name, int arg1)
|
97
95
|
{
|
98
|
-
|
96
|
+
if (!self->program)
|
97
|
+
invalid_state_error(__FILE__, __LINE__);
|
98
|
+
|
99
|
+
self->program->set_uniform(name, arg1);
|
99
100
|
}
|
100
101
|
|
101
|
-
|
102
|
-
Shader::
|
102
|
+
void
|
103
|
+
Shader::set_uniform (const char* name, int arg1, int arg2)
|
103
104
|
{
|
104
|
-
|
105
|
+
if (!self->program)
|
106
|
+
invalid_state_error(__FILE__, __LINE__);
|
107
|
+
|
108
|
+
self->program->set_uniform(name, arg1, arg2);
|
105
109
|
}
|
106
110
|
|
107
|
-
|
108
|
-
Shader::
|
111
|
+
void
|
112
|
+
Shader::set_uniform (const char* name, int arg1, int arg2, int arg3)
|
109
113
|
{
|
110
|
-
|
114
|
+
if (!self->program)
|
115
|
+
invalid_state_error(__FILE__, __LINE__);
|
116
|
+
|
117
|
+
self->program->set_uniform(name, arg1, arg2, arg3);
|
111
118
|
}
|
112
119
|
|
113
|
-
|
120
|
+
void
|
121
|
+
Shader::set_uniform (const char* name, int arg1, int arg2, int arg3, int arg4)
|
114
122
|
{
|
115
|
-
|
123
|
+
if (!self->program)
|
124
|
+
invalid_state_error(__FILE__, __LINE__);
|
125
|
+
|
126
|
+
self->program->set_uniform(name, arg1, arg2, arg3, arg4);
|
116
127
|
}
|
117
128
|
|
118
|
-
|
119
|
-
Shader::
|
129
|
+
void
|
130
|
+
Shader::set_uniform (const char* name, const int* args, size_t size)
|
120
131
|
{
|
121
|
-
|
122
|
-
|
132
|
+
if (!self->program)
|
133
|
+
invalid_state_error(__FILE__, __LINE__);
|
123
134
|
|
135
|
+
self->program->set_uniform(name, args, size);
|
136
|
+
}
|
124
137
|
|
125
|
-
|
138
|
+
void
|
139
|
+
Shader::set_uniform (const char* name, float arg1)
|
140
|
+
{
|
141
|
+
if (!self->program)
|
142
|
+
invalid_state_error(__FILE__, __LINE__);
|
126
143
|
|
144
|
+
self->program->set_uniform(name, arg1);
|
145
|
+
}
|
127
146
|
|
128
|
-
|
147
|
+
void
|
148
|
+
Shader::set_uniform (const char* name, float arg1, float arg2)
|
149
|
+
{
|
150
|
+
if (!self->program)
|
151
|
+
invalid_state_error(__FILE__, __LINE__);
|
129
152
|
|
153
|
+
self->program->set_uniform(name, arg1, arg2);
|
154
|
+
}
|
130
155
|
|
131
|
-
|
156
|
+
void
|
157
|
+
Shader::set_uniform (const char* name, float arg1, float arg2, float arg3)
|
158
|
+
{
|
159
|
+
if (!self->program)
|
160
|
+
invalid_state_error(__FILE__, __LINE__);
|
132
161
|
|
162
|
+
self->program->set_uniform(name, arg1, arg2, arg3);
|
163
|
+
}
|
133
164
|
|
134
|
-
|
135
|
-
|
165
|
+
void
|
166
|
+
Shader::set_uniform (
|
167
|
+
const char* name, float arg1, float arg2, float arg3, float arg4)
|
168
|
+
{
|
169
|
+
if (!self->program)
|
170
|
+
invalid_state_error(__FILE__, __LINE__);
|
136
171
|
|
172
|
+
self->program->set_uniform(name, arg1, arg2, arg3, arg4);
|
173
|
+
}
|
137
174
|
|
138
|
-
|
175
|
+
void
|
176
|
+
Shader::set_uniform (const char* name, const float* args, size_t size)
|
177
|
+
{
|
178
|
+
if (!self->program)
|
179
|
+
invalid_state_error(__FILE__, __LINE__);
|
139
180
|
|
181
|
+
self->program->set_uniform(name, args, size);
|
182
|
+
}
|
140
183
|
|
141
|
-
|
184
|
+
void
|
185
|
+
Shader::set_uniform (const char* name, const Coord2& vec2)
|
142
186
|
{
|
187
|
+
if (!self->program)
|
188
|
+
invalid_state_error(__FILE__, __LINE__);
|
189
|
+
|
190
|
+
self->program->set_uniform(name, vec2);
|
143
191
|
}
|
144
192
|
|
145
|
-
|
193
|
+
void
|
194
|
+
Shader::set_uniform (const char* name, const Coord3& vec3)
|
146
195
|
{
|
147
|
-
|
196
|
+
if (!self->program)
|
197
|
+
invalid_state_error(__FILE__, __LINE__);
|
198
|
+
|
199
|
+
self->program->set_uniform(name, vec3);
|
148
200
|
}
|
149
201
|
|
150
|
-
|
202
|
+
void
|
203
|
+
Shader::set_uniform (const char* name, const Coord4& vec4)
|
151
204
|
{
|
205
|
+
if (!self->program)
|
206
|
+
invalid_state_error(__FILE__, __LINE__);
|
207
|
+
|
208
|
+
self->program->set_uniform(name, vec4);
|
152
209
|
}
|
153
210
|
|
154
|
-
|
155
|
-
Shader::
|
211
|
+
void
|
212
|
+
Shader::set_uniform (const char* name, const Image& texture)
|
156
213
|
{
|
157
|
-
|
214
|
+
if (!self->program)
|
215
|
+
invalid_state_error(__FILE__, __LINE__);
|
216
|
+
|
217
|
+
self->program->set_uniform(name, Image_get_texture(texture));
|
158
218
|
}
|
159
219
|
|
160
|
-
bool
|
161
|
-
Shader::operator == (const Shader& rhs) const
|
220
|
+
Shader::operator bool () const
|
162
221
|
{
|
163
|
-
return
|
222
|
+
return self->program && *self->program;
|
164
223
|
}
|
165
224
|
|
166
225
|
bool
|
167
|
-
Shader::operator
|
226
|
+
Shader::operator ! () const
|
168
227
|
{
|
169
|
-
return !operator
|
228
|
+
return !operator bool();
|
170
229
|
}
|
171
230
|
|
172
|
-
|
231
|
+
bool
|
232
|
+
operator == (const Shader& lhs, const Shader& rhs)
|
173
233
|
{
|
174
|
-
return
|
234
|
+
return (!lhs && !rhs) || lhs.self->program == rhs.self->program;
|
175
235
|
}
|
176
236
|
|
177
237
|
bool
|
178
|
-
|
238
|
+
operator != (const Shader& lhs, const Shader& rhs)
|
179
239
|
{
|
180
|
-
return !operator
|
240
|
+
return !operator==(lhs, rhs);
|
181
241
|
}
|
182
242
|
|
183
243
|
|
184
244
|
}// Rays
|
185
|
-
|
186
|
-
|
187
|
-
#endif// USE_SHADER
|