rays 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -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
@@ -0,0 +1,158 @@
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 (Polygon* result, coord width) const
93
+ {
94
+ return Polyline_expand(result, *this, width);
95
+ }
96
+
97
+ Bounds
98
+ Polyline::bounds () const
99
+ {
100
+ if (empty()) return Bounds(-1, -1, -1);
101
+
102
+ auto it = begin();
103
+ Bounds b(*it++, 0);
104
+ for (auto end = this->end(); it != end; ++it)
105
+ b |= *it;
106
+ return b;
107
+ }
108
+
109
+ bool
110
+ Polyline::loop () const
111
+ {
112
+ return self->loop;
113
+ }
114
+
115
+ size_t
116
+ Polyline::size () const
117
+ {
118
+ return self->points.size();
119
+ }
120
+
121
+ bool
122
+ Polyline::empty () const
123
+ {
124
+ return size() <= 0;
125
+ }
126
+
127
+ Polyline::const_iterator
128
+ Polyline::begin () const
129
+ {
130
+ return self->points.begin();
131
+ }
132
+
133
+ Polyline::const_iterator
134
+ Polyline::end () const
135
+ {
136
+ return self->points.end();
137
+ }
138
+
139
+ const Point&
140
+ Polyline::operator [] (size_t index) const
141
+ {
142
+ return self->points[index];
143
+ }
144
+
145
+ Polyline::operator bool () const
146
+ {
147
+ size_t s = size();
148
+ return !((s == 1 || s == 2) && self->loop);
149
+ }
150
+
151
+ bool
152
+ Polyline::operator ! () const
153
+ {
154
+ return !operator bool();
155
+ }
156
+
157
+
158
+ }// Rays
@@ -0,0 +1,67 @@
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 (Polygon* result, const Polyline& polyline, coord width);
62
+
63
+
64
+ }// Rays
65
+
66
+
67
+ #endif//EOH
@@ -41,15 +41,22 @@ namespace Rays
41
41
 
42
42
  GLuint id_ = 0;
43
43
  glGenRenderbuffers(1, &id_);
44
- check_error(__FILE__, __LINE__);
44
+ OpenGL_check_error(__FILE__, __LINE__);
45
45
 
46
46
  id = id_;
47
47
  glBindRenderbuffer(GL_RENDERBUFFER, id_);
48
- check_error(__FILE__, __LINE__);
48
+ OpenGL_check_error(__FILE__, __LINE__);
49
49
 
50
50
  glRenderbufferStorage(
51
- GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
52
- check_error(__FILE__, __LINE__);
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_;
@@ -6,7 +6,7 @@
6
6
 
7
7
  #include <xot/pimpl.h>
8
8
  #include <rays/defs.h>
9
- #include <rays/opengl.h>
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::PImpl<Data, true> self;
39
+ Xot::PSharedImpl<Data> self;
40
40
 
41
41
  };// RenderBuffer
42
42
 
@@ -1,187 +1,244 @@
1
- #include "rays/shader.h"
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
- struct Shader::Data
21
- {
22
-
23
- int id;
24
-
25
- Data ()
26
- : id(-1)
27
- {
28
- }
29
-
30
- ~Data ()
31
- {
32
- clear();
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
- id = -1;
40
- }
65
+ struct Shader::Data
66
+ {
41
67
 
42
- bool is_valid () const
43
- {
44
- return id >= 0;
45
- }
68
+ std::unique_ptr<ShaderProgram> program;
46
69
 
47
70
  };// Shader::Data
48
71
 
49
72
 
50
- void
51
- compile_shader (Shader* this_, const char* source)
73
+ const ShaderProgram*
74
+ Shader_get_program (const Shader& shader)
52
75
  {
53
- if (!this_ || !source)
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
- compile_shader(this, source);
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
- GLuint
96
- Shader::id () const
93
+ void
94
+ Shader::set_uniform (const char* name, int arg1)
97
95
  {
98
- return self->id;
96
+ if (!self->program)
97
+ invalid_state_error(__FILE__, __LINE__);
98
+
99
+ self->program->set_uniform(name, arg1);
99
100
  }
100
101
 
101
- bool
102
- Shader::operator == (const Shader& rhs) const
102
+ void
103
+ Shader::set_uniform (const char* name, int arg1, int arg2)
103
104
  {
104
- return self->id == rhs.self->id;
105
+ if (!self->program)
106
+ invalid_state_error(__FILE__, __LINE__);
107
+
108
+ self->program->set_uniform(name, arg1, arg2);
105
109
  }
106
110
 
107
- bool
108
- Shader::operator != (const Shader& rhs) const
111
+ void
112
+ Shader::set_uniform (const char* name, int arg1, int arg2, int arg3)
109
113
  {
110
- return !operator==(rhs);
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
- Shader::operator bool () const
120
+ void
121
+ Shader::set_uniform (const char* name, int arg1, int arg2, int arg3, int arg4)
114
122
  {
115
- return self->is_valid();
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
- bool
119
- Shader::operator ! () const
129
+ void
130
+ Shader::set_uniform (const char* name, const int* args, size_t size)
120
131
  {
121
- return !operator bool();
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
- }// Rays
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
- #else// USE_SHADER
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
- #include "rays/exception.h"
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
- namespace Rays
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
- struct Shader::Data {};
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
- Shader::Shader ()
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
- Shader::Shader (const char* source)
193
+ void
194
+ Shader::set_uniform (const char* name, const Coord3& vec3)
146
195
  {
147
- not_implemented_error(__FILE__, __LINE__);
196
+ if (!self->program)
197
+ invalid_state_error(__FILE__, __LINE__);
198
+
199
+ self->program->set_uniform(name, vec3);
148
200
  }
149
201
 
150
- Shader::~Shader ()
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
- GLuint
155
- Shader::id () const
211
+ void
212
+ Shader::set_uniform (const char* name, const Image& texture)
156
213
  {
157
- return 0;
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 false;
222
+ return self->program && *self->program;
164
223
  }
165
224
 
166
225
  bool
167
- Shader::operator != (const Shader& rhs) const
226
+ Shader::operator ! () const
168
227
  {
169
- return !operator==(rhs);
228
+ return !operator bool();
170
229
  }
171
230
 
172
- Shader::operator bool () const
231
+ bool
232
+ operator == (const Shader& lhs, const Shader& rhs)
173
233
  {
174
- return false;
234
+ return (!lhs && !rhs) || lhs.self->program == rhs.self->program;
175
235
  }
176
236
 
177
237
  bool
178
- Shader::operator ! () const
238
+ operator != (const Shader& lhs, const Shader& rhs)
179
239
  {
180
- return !operator bool();
240
+ return !operator==(lhs, rhs);
181
241
  }
182
242
 
183
243
 
184
244
  }// Rays
185
-
186
-
187
- #endif// USE_SHADER