rays 0.1.12 → 0.1.13
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/color.cpp +224 -45
- data/.doc/ext/rays/color_space.cpp +137 -45
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +39 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +12 -6
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +120 -308
- data/.doc/ext/rays/point.cpp +82 -77
- data/.doc/ext/rays/polygon.cpp +287 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +161 -0
- data/.doc/ext/rays/rays.cpp +0 -13
- data/.doc/ext/rays/shader.cpp +83 -9
- data/README.md +1 -1
- data/Rakefile +21 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/color.cpp +232 -51
- data/ext/rays/color_space.cpp +140 -46
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +1 -2
- data/ext/rays/font.cpp +39 -22
- data/ext/rays/image.cpp +27 -39
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +12 -6
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +129 -315
- data/ext/rays/point.cpp +89 -81
- data/ext/rays/polygon.cpp +301 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +170 -0
- data/ext/rays/rays.cpp +0 -14
- 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/color.h +25 -14
- data/include/rays/color_space.h +11 -8
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +3 -0
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +11 -17
- 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 +57 -99
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +164 -0
- data/include/rays/polyline.h +65 -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/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/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +6 -1
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +2 -6
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +60 -97
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +50 -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 +50 -32
- 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 +171 -97
- data/src/image.h +25 -0
- data/src/ios/bitmap.mm +107 -105
- data/src/ios/font.mm +48 -60
- 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.mm +111 -106
- data/src/osx/font.mm +48 -61
- 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 +780 -696
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1100 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +158 -0
- data/src/polyline.h +67 -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_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +92 -46
- data/test/test_painter_shape.rb +57 -0
- data/test/test_point.rb +21 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +145 -0
- data/test/test_shader.rb +9 -9
- metadata +88 -67
- 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
@@ -1,34 +1,33 @@
|
|
1
1
|
// -*- c++ -*-
|
2
2
|
#pragma once
|
3
|
-
#ifndef
|
4
|
-
#define
|
3
|
+
#ifndef __RAYS_SRC_SHADER_PROGRAM_H__
|
4
|
+
#define __RAYS_SRC_SHADER_PROGRAM_H__
|
5
5
|
|
6
6
|
|
7
7
|
#include <xot/pimpl.h>
|
8
|
-
#include <rays/
|
8
|
+
#include <rays/defs.h>
|
9
|
+
#include <rays/coord.h>
|
10
|
+
#include "opengl.h"
|
9
11
|
|
10
12
|
|
11
13
|
namespace Rays
|
12
14
|
{
|
13
15
|
|
14
16
|
|
15
|
-
class
|
17
|
+
class ShaderSource;
|
18
|
+
class Texture;
|
16
19
|
|
17
20
|
|
18
|
-
class
|
21
|
+
class ShaderProgram
|
19
22
|
{
|
20
23
|
|
21
|
-
typedef
|
24
|
+
typedef ShaderProgram This;
|
22
25
|
|
23
26
|
public:
|
24
27
|
|
25
|
-
|
28
|
+
ShaderProgram (const ShaderSource& vertex, const ShaderSource& fragment);
|
26
29
|
|
27
|
-
~
|
28
|
-
|
29
|
-
void attach (const Shader& shader);
|
30
|
-
|
31
|
-
void detach (const Shader& shader);
|
30
|
+
~ShaderProgram ();
|
32
31
|
|
33
32
|
void set_uniform (const char* name, int arg1);
|
34
33
|
|
@@ -50,9 +49,13 @@ namespace Rays
|
|
50
49
|
|
51
50
|
void set_uniform (const char* name, const float* args, size_t size);
|
52
51
|
|
53
|
-
void
|
52
|
+
void set_uniform (const char* name, const Coord2& vec2);
|
53
|
+
|
54
|
+
void set_uniform (const char* name, const Coord3& vec3);
|
54
55
|
|
55
|
-
void
|
56
|
+
void set_uniform (const char* name, const Coord4& vec4);
|
57
|
+
|
58
|
+
void set_uniform (const char* name, const Texture& texture);
|
56
59
|
|
57
60
|
GLuint id () const;
|
58
61
|
|
@@ -60,11 +63,20 @@ namespace Rays
|
|
60
63
|
|
61
64
|
bool operator ! () const;
|
62
65
|
|
66
|
+
friend bool operator == (const This& lhs, const This& rhs);
|
67
|
+
|
68
|
+
friend bool operator != (const This& lhs, const This& rhs);
|
69
|
+
|
63
70
|
struct Data;
|
64
71
|
|
65
|
-
Xot::
|
72
|
+
Xot::PSharedImpl<Data> self;
|
73
|
+
|
74
|
+
};// ShaderProgram
|
75
|
+
|
76
|
+
|
77
|
+
void ShaderProgram_activate (const ShaderProgram& program);
|
66
78
|
|
67
|
-
|
79
|
+
void ShaderProgram_deactivate ();
|
68
80
|
|
69
81
|
|
70
82
|
}// Rays
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#include "shader_source.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include "rays/exception.h"
|
5
|
+
#include "rays/debug.h"
|
6
|
+
|
7
|
+
|
8
|
+
namespace Rays
|
9
|
+
{
|
10
|
+
|
11
|
+
|
12
|
+
struct ShaderSource::Data
|
13
|
+
{
|
14
|
+
|
15
|
+
GLuint id = 0;
|
16
|
+
|
17
|
+
GLenum type = 0;
|
18
|
+
|
19
|
+
String source;
|
20
|
+
|
21
|
+
Data ()
|
22
|
+
{
|
23
|
+
}
|
24
|
+
|
25
|
+
~Data ()
|
26
|
+
{
|
27
|
+
clear();
|
28
|
+
}
|
29
|
+
|
30
|
+
void compile (GLenum type_, const char* source_)
|
31
|
+
{
|
32
|
+
if (!is_valid_type(type_) || !source_ || !*source_)
|
33
|
+
argument_error(__FILE__, __LINE__);
|
34
|
+
|
35
|
+
if (is_valid())
|
36
|
+
invalid_state_error(__FILE__, __LINE__);
|
37
|
+
|
38
|
+
id = glCreateShader(type_);
|
39
|
+
glShaderSource(id, 1, &source_, NULL);
|
40
|
+
glCompileShader(id);
|
41
|
+
|
42
|
+
GLint status = GL_FALSE;
|
43
|
+
glGetShaderiv(id, GL_COMPILE_STATUS, &status);
|
44
|
+
if (status == GL_FALSE)
|
45
|
+
opengl_error(__FILE__, __LINE__, get_compile_log().c_str());
|
46
|
+
|
47
|
+
type = type_;
|
48
|
+
source = source_;
|
49
|
+
}
|
50
|
+
|
51
|
+
String get_compile_log () const
|
52
|
+
{
|
53
|
+
GLsizei len = 0;
|
54
|
+
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &len);
|
55
|
+
if (len <= 0) return "";
|
56
|
+
|
57
|
+
std::unique_ptr<char[]> buffer(new char[len]);
|
58
|
+
int written = 0;
|
59
|
+
glGetShaderInfoLog(id, len, &written, &buffer[0]);
|
60
|
+
return buffer.get();
|
61
|
+
}
|
62
|
+
|
63
|
+
void clear ()
|
64
|
+
{
|
65
|
+
if (id > 0) glDeleteShader(id);
|
66
|
+
|
67
|
+
id = 0;
|
68
|
+
type = 0;
|
69
|
+
source.clear();
|
70
|
+
}
|
71
|
+
|
72
|
+
bool is_valid () const
|
73
|
+
{
|
74
|
+
return is_valid_type(type) && id > 0;
|
75
|
+
}
|
76
|
+
|
77
|
+
static bool is_valid_type (GLenum type)
|
78
|
+
{
|
79
|
+
return type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER;
|
80
|
+
}
|
81
|
+
|
82
|
+
};// ShaderSource::Data
|
83
|
+
|
84
|
+
|
85
|
+
ShaderSource::ShaderSource ()
|
86
|
+
{
|
87
|
+
}
|
88
|
+
|
89
|
+
ShaderSource::ShaderSource (GLenum type, const char* source)
|
90
|
+
{
|
91
|
+
self->compile(type, source);
|
92
|
+
}
|
93
|
+
|
94
|
+
ShaderSource::~ShaderSource ()
|
95
|
+
{
|
96
|
+
}
|
97
|
+
|
98
|
+
const char*
|
99
|
+
ShaderSource::source () const
|
100
|
+
{
|
101
|
+
return self->source;
|
102
|
+
}
|
103
|
+
|
104
|
+
GLenum
|
105
|
+
ShaderSource::type () const
|
106
|
+
{
|
107
|
+
return self->type;
|
108
|
+
}
|
109
|
+
|
110
|
+
GLuint
|
111
|
+
ShaderSource::id () const
|
112
|
+
{
|
113
|
+
return self->id;
|
114
|
+
}
|
115
|
+
|
116
|
+
ShaderSource::operator bool () const
|
117
|
+
{
|
118
|
+
return self->is_valid();
|
119
|
+
}
|
120
|
+
|
121
|
+
bool
|
122
|
+
ShaderSource::operator ! () const
|
123
|
+
{
|
124
|
+
return !operator bool();
|
125
|
+
}
|
126
|
+
|
127
|
+
bool
|
128
|
+
operator == (const ShaderSource& lhs, const ShaderSource& rhs)
|
129
|
+
{
|
130
|
+
return (!lhs && !rhs) || lhs.self->id == rhs.self->id;
|
131
|
+
}
|
132
|
+
|
133
|
+
bool
|
134
|
+
operator != (const ShaderSource& lhs, const ShaderSource& rhs)
|
135
|
+
{
|
136
|
+
return !operator==(lhs, rhs);
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
}// Rays
|
data/src/shader_source.h
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_SHADER_SOURCE_H__
|
4
|
+
#define __RAYS_SRC_SHADER_SOURCE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <xot/pimpl.h>
|
8
|
+
#include "opengl.h"
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class ShaderSource
|
16
|
+
{
|
17
|
+
|
18
|
+
typedef ShaderSource This;
|
19
|
+
|
20
|
+
public:
|
21
|
+
|
22
|
+
ShaderSource ();
|
23
|
+
|
24
|
+
ShaderSource (GLenum type, const char* source);
|
25
|
+
|
26
|
+
~ShaderSource ();
|
27
|
+
|
28
|
+
const char* source () const;
|
29
|
+
|
30
|
+
GLenum type () const;
|
31
|
+
|
32
|
+
GLuint id () const;
|
33
|
+
|
34
|
+
operator bool () const;
|
35
|
+
|
36
|
+
bool operator ! () const;
|
37
|
+
|
38
|
+
friend bool operator == (const This& lhs, const This& rhs);
|
39
|
+
|
40
|
+
friend bool operator != (const This& lhs, const This& rhs);
|
41
|
+
|
42
|
+
struct Data;
|
43
|
+
|
44
|
+
Xot::PSharedImpl<Data> self;
|
45
|
+
|
46
|
+
};// ShaderSource
|
47
|
+
|
48
|
+
|
49
|
+
}// Rays
|
50
|
+
|
51
|
+
|
52
|
+
#endif//EOH
|
data/src/texture.cpp
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
#include "
|
1
|
+
#include "texture.h"
|
2
2
|
|
3
3
|
|
4
|
+
#include <assert.h>
|
4
5
|
#include "rays/exception.h"
|
5
6
|
#include "rays/bitmap.h"
|
6
|
-
#include "rays/
|
7
|
+
#include "rays/debug.h"
|
8
|
+
#include "opengl.h"
|
9
|
+
#include "color_space.h"
|
7
10
|
#include "frame_buffer.h"
|
8
11
|
|
9
12
|
|
@@ -14,14 +17,17 @@ namespace Rays
|
|
14
17
|
struct Texture::Data
|
15
18
|
{
|
16
19
|
|
17
|
-
|
20
|
+
Context context = NULL;
|
21
|
+
|
22
|
+
GLuint id = 0;
|
23
|
+
|
24
|
+
int width, height, width_pow2, height_pow2;
|
18
25
|
|
19
26
|
ColorSpace color_space;
|
20
27
|
|
21
|
-
bool
|
28
|
+
bool modified;
|
22
29
|
|
23
30
|
Data ()
|
24
|
-
: id(-1)
|
25
31
|
{
|
26
32
|
clear();
|
27
33
|
}
|
@@ -33,47 +39,40 @@ namespace Rays
|
|
33
39
|
|
34
40
|
void clear ()
|
35
41
|
{
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
id = -1;
|
43
|
-
width = height = width_pow2 = height_pow2 = 0;
|
42
|
+
delete_texture();
|
43
|
+
|
44
|
+
width =
|
45
|
+
height =
|
46
|
+
width_pow2 =
|
47
|
+
height_pow2 = 0;
|
44
48
|
color_space = COLORSPACE_UNKNOWN;
|
45
|
-
|
49
|
+
modified = false;
|
46
50
|
}
|
47
51
|
|
48
|
-
|
52
|
+
void delete_texture ()
|
53
|
+
{
|
54
|
+
if (!has_id()) return;
|
49
55
|
|
56
|
+
Context current_context = OpenGL_get_context();
|
50
57
|
|
51
|
-
|
52
|
-
|
53
|
-
Texture::Data* self, const Bitmap* bitmap, GLenum format, GLenum type)
|
54
|
-
{
|
55
|
-
if (!self || (bitmap && !*bitmap))
|
56
|
-
argument_error(__FILE__, __LINE__);
|
58
|
+
assert(context);
|
59
|
+
OpenGL_set_context(context);
|
57
60
|
|
58
|
-
|
59
|
-
glGenTextures(1, &id);
|
60
|
-
glBindTexture(GL_TEXTURE_2D, id);
|
61
|
-
if (glIsTexture(id) == GL_FALSE)
|
62
|
-
opengl_error(__FILE__, __LINE__, "failed to create texture.");
|
61
|
+
glDeleteTextures(1, &id);
|
63
62
|
|
64
|
-
|
63
|
+
OpenGL_set_context(current_context);
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);//GL_LINEAR);
|
65
|
+
context = NULL;
|
66
|
+
id = 0;
|
67
|
+
}
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
bool has_id () const
|
70
|
+
{
|
71
|
+
return context && id > 0;
|
72
|
+
}
|
73
|
+
|
74
|
+
};// Texture::Data
|
74
75
|
|
75
|
-
check_error(__FILE__, __LINE__);
|
76
|
-
}
|
77
76
|
|
78
77
|
static int
|
79
78
|
min_pow2 (int num)
|
@@ -84,26 +83,35 @@ namespace Rays
|
|
84
83
|
}
|
85
84
|
|
86
85
|
static void
|
87
|
-
|
86
|
+
setup_texture (Texture::Data* self, const void* pixels = NULL)
|
88
87
|
{
|
89
|
-
|
90
|
-
argument_error(__FILE__, __LINE__);
|
88
|
+
assert(self && !self->has_id());
|
91
89
|
|
92
|
-
|
90
|
+
if (self->context)
|
91
|
+
invalid_state_error(__FILE__, __LINE__);
|
93
92
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
93
|
+
self->context = OpenGL_get_context();
|
94
|
+
if (!self->context)
|
95
|
+
opengl_error(__FILE__, __LINE__);
|
96
|
+
|
97
|
+
glGenTextures(1, &self->id);
|
98
|
+
glBindTexture(GL_TEXTURE_2D, self->id);
|
99
|
+
if (glIsTexture(self->id) == GL_FALSE)
|
100
|
+
opengl_error(__FILE__, __LINE__, "failed to create texture.");
|
101
|
+
|
102
|
+
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
103
|
+
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
104
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
105
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);//GL_LINEAR);
|
106
|
+
|
107
|
+
GLenum format, type;
|
108
|
+
ColorSpace_get_gl_format_and_type(&format, &type, self->color_space);
|
109
|
+
|
110
|
+
glTexImage2D(
|
111
|
+
GL_TEXTURE_2D, 0, format, self->width_pow2, self->height_pow2, 0,
|
112
|
+
format, type, pixels);
|
113
|
+
|
114
|
+
OpenGL_check_error(__FILE__, __LINE__);
|
107
115
|
}
|
108
116
|
|
109
117
|
template <int BytesPerPixel>
|
@@ -141,134 +149,104 @@ namespace Rays
|
|
141
149
|
static inline void
|
142
150
|
copy_pixels (
|
143
151
|
size_t width,
|
144
|
-
uchar* dest, size_t
|
152
|
+
uchar* dest, size_t dest_stride, const uchar* src, size_t src_stride)
|
145
153
|
{
|
146
|
-
if (!dest || !src ||
|
154
|
+
if (!dest || !src || dest_stride <= 0 || src_stride <= 0)
|
147
155
|
argument_error(__FILE__, __LINE__);
|
148
156
|
|
149
157
|
while (width--)
|
150
158
|
{
|
151
159
|
copy_pixel<BytesPerPixel>(dest, src);
|
152
|
-
dest +=
|
153
|
-
src +=
|
160
|
+
dest += dest_stride;
|
161
|
+
src += src_stride;
|
154
162
|
}
|
155
163
|
}
|
156
164
|
|
157
165
|
static inline void
|
158
166
|
copy_pixels (
|
159
167
|
size_t Bpp, size_t width,
|
160
|
-
uchar* dest, size_t
|
168
|
+
uchar* dest, size_t dest_stride, const uchar* src, size_t src_stride)
|
161
169
|
{
|
162
170
|
switch (Bpp)
|
163
171
|
{
|
164
|
-
case 1: copy_pixels<1>(width, dest,
|
165
|
-
case 2: copy_pixels<2>(width, dest,
|
166
|
-
case 3: copy_pixels<3>(width, dest,
|
167
|
-
case 4: copy_pixels<4>(width, dest,
|
172
|
+
case 1: copy_pixels<1>(width, dest, dest_stride, src, src_stride); break;
|
173
|
+
case 2: copy_pixels<2>(width, dest, dest_stride, src, src_stride); break;
|
174
|
+
case 3: copy_pixels<3>(width, dest, dest_stride, src, src_stride); break;
|
175
|
+
case 4: copy_pixels<4>(width, dest, dest_stride, src, src_stride); break;
|
168
176
|
}
|
169
177
|
}
|
170
178
|
|
171
179
|
static void
|
172
|
-
copy_bitmap (Bitmap* dest, const Bitmap& src
|
180
|
+
copy_bitmap (Bitmap* dest, const Bitmap& src)
|
173
181
|
{
|
174
|
-
if (!dest || !src
|
182
|
+
if (!dest || !src)
|
175
183
|
argument_error(__FILE__, __LINE__);
|
176
184
|
|
185
|
+
int width = std::min(src.width(), dest->width());
|
186
|
+
int height = std::min(src.height(), dest->height());
|
177
187
|
int src_Bpp = src.color_space().Bpp();
|
178
|
-
int src_Bpc = src.color_space().Bpc();
|
179
188
|
int dest_Bpp = dest->color_space().Bpp();
|
180
189
|
|
181
|
-
if (src_offset >= (src_Bpp / src_Bpc))
|
182
|
-
rays_error(__FILE__, __LINE__, "invalid src_offset.");
|
183
|
-
|
184
|
-
int width = std::min(src.width(), dest->width());
|
185
|
-
int height = std::min(src.height(), dest->height());
|
186
|
-
|
187
190
|
for (int y = 0; y < height; ++y)
|
188
191
|
{
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
+
copy_pixels(
|
193
|
+
src_Bpp, width,
|
194
|
+
dest->at<uchar>(0, y), dest_Bpp,
|
195
|
+
src. at<uchar>(0, y), src_Bpp);
|
192
196
|
}
|
193
197
|
}
|
194
198
|
|
195
|
-
static void
|
196
|
-
setup_texture (
|
197
|
-
Texture::Data* self, int width, int height, const ColorSpace& cs,
|
198
|
-
const Bitmap* bitmap, bool alpha_only)
|
199
|
-
{
|
200
|
-
if (!self || width <= 0 || height <= 0 || !cs || (bitmap && !*bitmap))
|
201
|
-
argument_error(__FILE__, __LINE__);
|
202
199
|
|
203
|
-
|
204
|
-
|
200
|
+
Texture::Texture ()
|
201
|
+
{
|
202
|
+
}
|
205
203
|
|
206
|
-
|
204
|
+
Texture::Texture (int width, int height, const ColorSpace& cs)
|
205
|
+
{
|
206
|
+
if (width <= 0 || height <= 0 || !cs)
|
207
|
+
argument_error(__FILE__, __LINE__);
|
207
208
|
|
208
209
|
self->width = width;
|
209
210
|
self->height = height;
|
210
211
|
self->width_pow2 = min_pow2(width);
|
211
212
|
self->height_pow2 = min_pow2(height);
|
212
213
|
self->color_space = cs;
|
213
|
-
self->
|
214
|
-
self->dirty = true;
|
215
|
-
|
216
|
-
if (alpha_only)
|
217
|
-
{
|
218
|
-
colorspace_for_alphabitmap(&self->color_space, cs);
|
219
|
-
if (!self->color_space.is_gray())
|
220
|
-
rays_error(__FILE__, __LINE__, "alpha_only takes only gray color-space.");
|
221
|
-
}
|
222
|
-
|
223
|
-
Bitmap bmp;
|
224
|
-
if (bitmap)
|
225
|
-
{
|
226
|
-
if (
|
227
|
-
self->color_space != cs ||
|
228
|
-
self->width_pow2 != self->width ||
|
229
|
-
self->height_pow2 != self->height)
|
230
|
-
{
|
231
|
-
bmp = Bitmap(self->width_pow2, self->height_pow2, self->color_space);
|
232
|
-
if (!bmp)
|
233
|
-
rays_error(__FILE__, __LINE__, "creating bitmap failed.");
|
234
|
-
|
235
|
-
copy_bitmap(&bmp, *bitmap, alpha_only ? self->color_space.alpha_pos() : 0);
|
236
|
-
bitmap = &bmp;
|
237
|
-
}
|
238
|
-
}
|
214
|
+
self->modified = true;
|
239
215
|
|
240
|
-
|
216
|
+
setup_texture(self.get());
|
241
217
|
}
|
242
218
|
|
243
|
-
|
244
|
-
Texture::Texture ()
|
219
|
+
Texture::Texture (const Bitmap& bitmap)
|
245
220
|
{
|
246
|
-
|
221
|
+
if (!bitmap)
|
222
|
+
argument_error(__FILE__, __LINE__);
|
247
223
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
224
|
+
self->width = bitmap.width();
|
225
|
+
self->height = bitmap.height();
|
226
|
+
self->width_pow2 = min_pow2(self->width);
|
227
|
+
self->height_pow2 = min_pow2(self->height);
|
228
|
+
self->color_space = bitmap.color_space();
|
229
|
+
self->modified = true;
|
230
|
+
|
231
|
+
Bitmap bmp = bitmap;
|
232
|
+
if (
|
233
|
+
self->width_pow2 != self->width ||
|
234
|
+
self->height_pow2 != self->height)
|
235
|
+
{
|
236
|
+
bmp = Bitmap(self->width_pow2, self->height_pow2, self->color_space);
|
237
|
+
if (!bmp)
|
238
|
+
rays_error(__FILE__, __LINE__);
|
254
239
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
&bitmap, alpha_only);
|
240
|
+
copy_bitmap(&bmp, bitmap);
|
241
|
+
}
|
242
|
+
|
243
|
+
setup_texture(self.get(), bmp.pixels());
|
260
244
|
}
|
261
245
|
|
262
246
|
Texture::~Texture ()
|
263
247
|
{
|
264
248
|
}
|
265
249
|
|
266
|
-
GLuint
|
267
|
-
Texture::id () const
|
268
|
-
{
|
269
|
-
return self->id;
|
270
|
-
}
|
271
|
-
|
272
250
|
int
|
273
251
|
Texture::width () const
|
274
252
|
{
|
@@ -276,62 +254,60 @@ namespace Rays
|
|
276
254
|
}
|
277
255
|
|
278
256
|
int
|
279
|
-
Texture::
|
257
|
+
Texture::reserved_width () const
|
280
258
|
{
|
281
|
-
return self->
|
259
|
+
return self->width_pow2;
|
282
260
|
}
|
283
261
|
|
284
|
-
|
285
|
-
Texture::
|
262
|
+
int
|
263
|
+
Texture::height () const
|
286
264
|
{
|
287
|
-
return self->
|
265
|
+
return self->height;
|
288
266
|
}
|
289
267
|
|
290
|
-
|
291
|
-
Texture::
|
268
|
+
int
|
269
|
+
Texture::reserved_height () const
|
292
270
|
{
|
293
|
-
return self->
|
271
|
+
return self->height_pow2;
|
294
272
|
}
|
295
273
|
|
296
|
-
|
297
|
-
Texture::
|
274
|
+
const ColorSpace&
|
275
|
+
Texture::color_space () const
|
298
276
|
{
|
299
|
-
return
|
277
|
+
return self->color_space;
|
300
278
|
}
|
301
279
|
|
302
|
-
|
303
|
-
Texture::
|
280
|
+
Context
|
281
|
+
Texture::context () const
|
304
282
|
{
|
305
|
-
return
|
283
|
+
return self->context;
|
306
284
|
}
|
307
285
|
|
308
|
-
|
309
|
-
Texture::
|
286
|
+
GLuint
|
287
|
+
Texture::id () const
|
310
288
|
{
|
311
|
-
return
|
289
|
+
return self->id;
|
312
290
|
}
|
313
291
|
|
314
|
-
|
315
|
-
Texture::
|
292
|
+
void
|
293
|
+
Texture::set_modified (bool modified)
|
316
294
|
{
|
317
|
-
|
295
|
+
self->modified = modified;
|
318
296
|
}
|
319
297
|
|
320
298
|
bool
|
321
|
-
Texture::
|
322
|
-
{
|
323
|
-
return self->dirty;
|
324
|
-
}
|
325
|
-
|
326
|
-
void
|
327
|
-
Texture::set_dirty (bool b)
|
299
|
+
Texture::modified () const
|
328
300
|
{
|
329
|
-
self->
|
301
|
+
return self->modified;
|
330
302
|
}
|
331
303
|
|
332
304
|
Texture::operator bool () const
|
333
305
|
{
|
334
|
-
return
|
306
|
+
return
|
307
|
+
self->has_id() &&
|
308
|
+
self->width > 0 &&
|
309
|
+
self->height > 0 &&
|
310
|
+
self->color_space;
|
335
311
|
}
|
336
312
|
|
337
313
|
bool
|