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
|
# File 'ext/nuklear_renderer_opengl2/nuklear_renderer_opengl2.c', line 152
VALUE renderer_draw_gl(VALUE self, VALUE cmd) {
VALUE window_size = rb_funcall(self, rb_intern("window_size"), 0);
VALUE drawable_size = rb_funcall(self, rb_intern("drawable_size"), 0);
VALUE window_width = rb_ary_entry(window_size, 0);
VALUE window_height = rb_ary_entry(window_size, 1);
VALUE drawable_width = rb_ary_entry(drawable_size, 0);
VALUE drawable_height = rb_ary_entry(drawable_size, 1);
int width = FIX2INT(window_width),
height = FIX2INT(window_height);
int display_width = FIX2INT(drawable_width),
display_height = FIX2INT(drawable_height);
struct nk_vec2 scale;
scale.x = (float)display_width/(float)width;
scale.y = (float)display_height/(float)height;
VALUE clip_rect = rb_hash_aref(cmd, ID2SYM(rb_intern("clip_rect")));
float x = (float) NUM2DBL(RARRAY_AREF(clip_rect, 0));
float y = (float) NUM2DBL(RARRAY_AREF(clip_rect, 1));
float w = (float) NUM2DBL(RARRAY_AREF(clip_rect, 2));
float h = (float) NUM2DBL(RARRAY_AREF(clip_rect, 3));
glBindTexture(GL_TEXTURE_2D, (GLuint) NUM2UINT(rb_hash_aref(cmd, ID2SYM(rb_intern("texture_handle")))));
glScissor((GLint)(x * scale.x),
(GLint)((height - (GLint)(y + h)) * scale.y),
(GLint)(w * scale.x),
(GLint)(h * scale.y));
unsigned int num_elements = NUM2UINT(rb_hash_aref(cmd, ID2SYM(rb_intern("element_count"))));
struct nk_buffer *element_buffer = NULL;
Data_Get_Struct(rb_funcall(self, rb_intern("vertex_indices"), 0), struct nk_buffer, element_buffer);
const nk_draw_index *offset = (const nk_draw_index *) nk_buffer_memory_const(element_buffer);
offset += NUM2UINT(rb_hash_aref(cmd, ID2SYM(rb_intern("offset"))));
glDrawElements(GL_TRIANGLES, (GLsizei)num_elements, GL_UNSIGNED_SHORT, (void *) offset);
return self;
}
|