1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Alexander Medvednikov 2019-08-04 09:46:49 +02:00
parent ee437de8d3
commit 4bc1f73fd0

View File

@ -64,12 +64,12 @@ struct GG {
// use_ortho bool // use_ortho bool
width int width int
height int height int
VAO u32 vao u32
rect_vao u32 rect_vao u32
rect_vbo u32 rect_vbo u32
line_vao u32 line_vao u32
line_vbo u32 line_vbo u32
VBO u32 vbo u32
scale int // retina = 2 , normal = 1 scale int // retina = 2 , normal = 1
pub mut: pub mut:
window *glfw.Window window *glfw.Window
@ -147,8 +147,8 @@ pub fn new_context(cfg Cfg) *GG {
shader: shader shader: shader
width: cfg.width width: cfg.width
height: cfg.height height: cfg.height
VAO: vao vao: vao
VBO: vbo vbo: vbo
window: window window: window
// /line_vao: gl.gen_vertex_array() // /line_vao: gl.gen_vertex_array()
@ -193,8 +193,8 @@ pub fn (ctx &GG) draw_triangle(x1, y1, x2, y2, x3, y3 f32, c gx.Color) {
] ! ] !
// bind the Vertex Array Object first, then bind and set vertex buffer(s), // bind the Vertex Array Object first, then bind and set vertex buffer(s),
// and then configure vertex attributes(s). // and then configure vertex attributes(s).
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.set_vbo(ctx.VBO, vertices, GL_STATIC_DRAW) gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW)
gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0) gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0)
gl.enable_vertex_attrib_array(0) gl.enable_vertex_attrib_array(0)
// gl.bind_buffer(GL_ARRAY_BUFFER, uint(0)) // gl.bind_buffer(GL_ARRAY_BUFFER, uint(0))
@ -216,8 +216,8 @@ pub fn (ctx &GG) draw_triangle_tex(x1, y1, x2, y2, x3, y3 f32, c gx.Color) {
x2, y2, 0, 0, 0, 0, 1, 0, x2, y2, 0, 0, 0, 0, 1, 0,
x3, y3, 0, 0, 0, 0, 0, 0, x3, y3, 0, 0, 0, 0, 0, 0,
] ! ] !
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.set_vbo(ctx.VBO, vertices, GL_STATIC_DRAW) gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW)
// position attribute // position attribute
gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0) gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0)
gl.enable_vertex_attrib_array(0) gl.enable_vertex_attrib_array(0)
@ -266,8 +266,8 @@ fn (ctx mut GG) init_rect_vao() {
} }
*/ */
pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) { pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) {
C.glDeleteBuffers(1, &ctx.VAO) C.glDeleteBuffers(1, &ctx.vao)
C.glDeleteBuffers(1, &ctx.VBO) C.glDeleteBuffers(1, &ctx.vbo)
ctx.shader.use() ctx.shader.use()
ctx.shader.set_color('color', c) ctx.shader.set_color('color', c)
ctx.shader.set_int('has_texture', 0) ctx.shader.set_int('has_texture', 0)
@ -286,8 +286,8 @@ pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) {
0, 1, 3,// first triangle 0, 1, 3,// first triangle
1, 2, 3// second triangle 1, 2, 3// second triangle
] ! ] !
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.set_vbo(ctx.VBO, vertices, GL_STATIC_DRAW) gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW)
ebo := gl.gen_buffer() ebo := gl.gen_buffer()
// /////// // ///////
gl.set_ebo(ebo, indices, GL_STATIC_DRAW)// !!! LEAKS gl.set_ebo(ebo, indices, GL_STATIC_DRAW)// !!! LEAKS
@ -295,7 +295,7 @@ pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) {
gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0) gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0)
gl.enable_vertex_attrib_array(0) gl.enable_vertex_attrib_array(0)
// gl.bind_vao(ctx.rect_vao) // gl.bind_vao(ctx.rect_vao)
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0)
C.glDeleteBuffers(1, &ebo) C.glDeleteBuffers(1, &ebo)
} }
@ -408,16 +408,16 @@ pub fn create_image(file string) u32 {
} }
pub fn (ctx &GG) draw_line_c(x, y, x2, y2 f32, color gx.Color) { pub fn (ctx &GG) draw_line_c(x, y, x2, y2 f32, color gx.Color) {
C.glDeleteBuffers(1, &ctx.VAO) C.glDeleteBuffers(1, &ctx.vao)
C.glDeleteBuffers(1, &ctx.VBO) C.glDeleteBuffers(1, &ctx.vbo)
ctx.shader.use() ctx.shader.use()
ctx.shader.set_color('color', color) ctx.shader.set_color('color', color)
vertices := [f32(x), f32(y), f32(x2), f32(y2)] ! vertices := [f32(x), f32(y), f32(x2), f32(y2)] !
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.set_vbo(ctx.VBO, vertices, GL_STATIC_DRAW) gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW)
gl.vertex_attrib_pointer(0, 2, GL_FLOAT, false, 2, 0) gl.vertex_attrib_pointer(0, 2, GL_FLOAT, false, 2, 0)
gl.enable_vertex_attrib_array(0) gl.enable_vertex_attrib_array(0)
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.draw_arrays(GL_LINES, 0, 2) gl.draw_arrays(GL_LINES, 0, 2)
} }
@ -453,8 +453,8 @@ pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) {
] ! ] !
// VAO := gl.gen_vertex_array() // VAO := gl.gen_vertex_array()
// VBO := gl.gen_buffer() // VBO := gl.gen_buffer()
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.set_vbo(ctx.VBO, vertices, GL_STATIC_DRAW) gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW)
ebo := gl.gen_buffer() ebo := gl.gen_buffer()
gl.set_ebo(ebo, indices, GL_STATIC_DRAW) gl.set_ebo(ebo, indices, GL_STATIC_DRAW)
gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 8, 0) gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 8, 0)
@ -464,7 +464,7 @@ pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) {
gl.vertex_attrib_pointer(2, 2, GL_FLOAT, false, 8, 6) gl.vertex_attrib_pointer(2, 2, GL_FLOAT, false, 8, 6)
gl.enable_vertex_attrib_array(2) gl.enable_vertex_attrib_array(2)
gl.bind_2d_texture(u32(tex_id)) gl.bind_2d_texture(u32(tex_id))
gl.bind_vao(ctx.VAO) gl.bind_vao(ctx.vao)
gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0)
} }