-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageRenderer.sj
196 lines (181 loc) · 7.9 KB
/
imageRenderer.sj
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
imageRenderer(
rect : 'rect
image : 'image
--cvar--
vertex_buffer_t* buffer;
--cvar--
render(scene : 'scene2d)'void {
glBindTexture(glTexture.GL_TEXTURE_2D, image.texture)
glUseProgram(imageShader)
glBlendFunc(glBlendFuncType.GL_SRC_ALPHA, glBlendFuncType.GL_ONE_MINUS_SRC_ALPHA)
glUniformI32(glGetUniformLocation(imageShader, "texture"), 0)
glUniformMat4(glGetUniformLocation(imageShader, "model"), scene.model)
glUniformMat4(glGetUniformLocation(imageShader, "view"), scene.view)
glUniformMat4(glGetUniformLocation(imageShader, "projection"), scene.projection)
--c--
vertex_buffer_render(_parent->buffer, GL_TRIANGLES);
--c--
void
}
) {
--c--
_this->buffer = vertex_buffer_new("vertex:3f,tex_coord:2f");
float x0 = (float)_this->rect.x;
float x1 = (float)(_this->rect.x + _this->image.margin.l);
float x2 = (float)(_this->rect.x + _this->rect.w - _this->image.margin.r);
float x3 = (float)(_this->rect.x + _this->rect.w);
float y0 = (float)_this->rect.y;
float y1 = (float)(_this->rect.y + _this->image.margin.t);
float y2 = (float)(_this->rect.y + _this->rect.h - _this->image.margin.b);
float y3 = (float)(_this->rect.y + _this->rect.h);
float s0 = (float)_this->image.rect.x / (float)_this->image.texture.size.w;
float s1 = (float)(_this->image.rect.x + _this->image.margin.l) / (float)_this->image.texture.size.w;
float s2 = (float)(_this->image.rect.x + _this->image.rect.w - _this->image.margin.r) / (float)_this->image.texture.size.w;
float s3 = (float)(_this->image.rect.x + _this->image.rect.w) / (float)_this->image.texture.size.w;
float t3 = (float)_this->image.rect.y / (float)_this->image.texture.size.h;
float t2 = (float)(_this->image.rect.y + _this->image.margin.b) / (float)_this->image.texture.size.h;
float t1 = (float)(_this->image.rect.y + _this->image.rect.h - _this->image.margin.t) / (float)_this->image.texture.size.h;
float t0 = (float)(_this->image.rect.y + _this->image.rect.h) / (float)_this->image.texture.size.h;
if (_this->image.margin.t > 0) {
if (_this->image.margin.l > 0) {
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x0, y0, 0.0f, s0, t0 },
{ x0, y1, 0.0f, s0, t1 },
{ x1, y1, 0.0f, s1, t1 },
{ x1, y0, 0.0f, s1, t0 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
{
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x1, y0, 0.0f, s1, t0 },
{ x1, y1, 0.0f, s1, t1 },
{ x2, y1, 0.0f, s2, t1 },
{ x2, y0, 0.0f, s2, t0 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
if (_this->image.margin.r > 0) {
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x2, y0, 0.0f, s2, t0 },
{ x2, y1, 0.0f, s2, t1 },
{ x3, y1, 0.0f, s3, t1 },
{ x3, y0, 0.0f, s3, t0 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
}
{
if (_this->image.margin.l > 0) {
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x0, y1, 0.0f, s0, t1 },
{ x0, y2, 0.0f, s0, t2 },
{ x1, y2, 0.0f, s1, t2 },
{ x1, y1, 0.0f, s1, t1 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
{
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x1, y1, 0.0f, s1, t1 },
{ x1, y2, 0.0f, s1, t2 },
{ x2, y2, 0.0f, s2, t2 },
{ x2, y1, 0.0f, s2, t1 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
if (_this->image.margin.r > 0) {
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x2, y1, 0.0f, s2, t1 },
{ x2, y2, 0.0f, s2, t2 },
{ x3, y2, 0.0f, s3, t2 },
{ x3, y1, 0.0f, s3, t1 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
}
if (_this->image.margin.b > 0) {
if (_this->image.margin.l > 0) {
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x0, y2, 0.0f, s0, t2 },
{ x0, y3, 0.0f, s0, t3 },
{ x1, y3, 0.0f, s1, t3 },
{ x1, y2, 0.0f, s1, t2 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
{
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x1, y2, 0.0f, s1, t2 },
{ x1, y3, 0.0f, s1, t3 },
{ x2, y3, 0.0f, s2, t3 },
{ x2, y2, 0.0f, s2, t2 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
if (_this->image.margin.r > 0) {
GLuint index = (GLuint)_this->buffer->vertices->size;
GLuint indices[] = { //
index, index+1, index+2,
index, index+2, index+3 };
vertex3_texture2_t vertices[] = { //
{ x2, y2, 0.0f, s2, t2 },
{ x2, y3, 0.0f, s2, t3 },
{ x3, y3, 0.0f, s3, t3 },
{ x3, y2, 0.0f, s3, t2 } };
vertex_buffer_push_back_indices( _this->buffer, indices, 6 );
vertex_buffer_push_back_vertices( _this->buffer, vertices, 4 );
}
}
--c--
this
} copy {
--c--
_this->buffer = _from->buffer;
ptr_retain(_this->buffer);
--c--
} destroy {
--c--
if (ptr_release(_this->buffer)) {
vertex_buffer_delete(_this->buffer);
}
--c--
}
--cstruct--
typedef struct {
float x, y, z; // position
float s, t; // texture
} vertex3_texture2_t;
--cstruct--