mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
remove "import const" everywhere
This commit is contained in:
@@ -9,15 +9,6 @@ import gx
|
||||
import glm
|
||||
|
||||
// import darwin
|
||||
import const (
|
||||
GL_VERTEX_SHADER
|
||||
GL_FRAGMENT_SHADER
|
||||
GL_ARRAY_BUFFER
|
||||
GL_TRIANGLES
|
||||
GL_CULL_FACE
|
||||
GL_BLEND
|
||||
GL_LINES
|
||||
)
|
||||
|
||||
struct Shader {
|
||||
program_id int
|
||||
@@ -43,7 +34,7 @@ uniform sampler2D text;
|
||||
uniform vec3 textColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
|
||||
color = vec4(textColor, 1.0) * sampled;
|
||||
} '
|
||||
@@ -51,11 +42,11 @@ void main()
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
|
||||
|
||||
out vec3 ourColor;
|
||||
out vec2 TexCoord;
|
||||
out vec2 TexCoord;
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
@@ -64,8 +55,8 @@ void main() {
|
||||
// gl_Position = vec4(aPos, 1.0);
|
||||
|
||||
ourColor = aColor;
|
||||
//TexCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||
TexCoord = aTexCoord;
|
||||
//TexCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||
TexCoord = aTexCoord;
|
||||
}
|
||||
'
|
||||
SIMPLE_FRAG = '#version 330 core
|
||||
@@ -73,30 +64,30 @@ void main() {
|
||||
out vec4 FragColor;
|
||||
uniform vec3 color;
|
||||
|
||||
uniform bool has_texture;
|
||||
uniform bool has_texture;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D ourTexture;
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
// FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
// FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
if (has_texture) {
|
||||
if (has_texture) {
|
||||
FragColor = texture(ourTexture, TexCoord);
|
||||
|
||||
} else {
|
||||
|
||||
} else {
|
||||
FragColor = vec4(color, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
)
|
||||
|
||||
pub fn new_shader(name string) Shader {
|
||||
// TODO This is not used, remove
|
||||
mut dir := ''
|
||||
// TODO This is not used, remove
|
||||
mut dir := ''
|
||||
// Already have absolute path
|
||||
if name.starts_with('/') {
|
||||
dir = ''
|
||||
@@ -118,7 +109,7 @@ pub fn new_shader(name string) Shader {
|
||||
fragment_src = SIMPLE_FRAG
|
||||
}
|
||||
// ////////////////////////////////////////
|
||||
vertex_shader := gl.create_shader(GL_VERTEX_SHADER)
|
||||
vertex_shader := gl.create_shader(C.GL_VERTEX_SHADER)
|
||||
gl.shader_source(vertex_shader, 1, vertex_src, 0)
|
||||
gl.compile_shader(vertex_shader)
|
||||
if gl.shader_compile_status(vertex_shader) == 0 {
|
||||
@@ -130,7 +121,7 @@ pub fn new_shader(name string) Shader {
|
||||
}
|
||||
// fragment shader
|
||||
// fragment_src := os.read_file(fragment_path.trim_space())
|
||||
fragment_shader := gl.create_shader(GL_FRAGMENT_SHADER)
|
||||
fragment_shader := gl.create_shader(C.GL_FRAGMENT_SHADER)
|
||||
gl.shader_source(fragment_shader, 1, fragment_src, 0)
|
||||
gl.compile_shader(fragment_shader)
|
||||
if gl.shader_compile_status(fragment_shader) == 0 {
|
||||
|
||||
47
vlib/gl/gl.v
47
vlib/gl/gl.v
@@ -4,24 +4,9 @@
|
||||
|
||||
module gl
|
||||
|
||||
import const (
|
||||
GL_TEXTURE_2D
|
||||
GL_TEXTURE0
|
||||
GL_FLOAT
|
||||
GL_VERTEX_SHADER
|
||||
GL_ELEMENT_ARRAY_BUFFER
|
||||
GL_DEPTH_TEST
|
||||
GL_COLOR_BUFFER_BIT
|
||||
GL_DEPTH_BUFFER_BIT
|
||||
GL_STENCIL_BUFFER_BIT
|
||||
GL_COMPILE_STATUS
|
||||
GL_LINK_STATUS
|
||||
GL_ARRAY_BUFFER
|
||||
)
|
||||
|
||||
#flag -I @VROOT/thirdparty/glad
|
||||
#include "glad.h"
|
||||
#flag @VROOT/thirdparty/glad/glad.o
|
||||
#flag @VROOT/thirdparty/glad/glad.o
|
||||
|
||||
pub fn init_glad() {
|
||||
ok := C.gladLoadGL()
|
||||
@@ -40,7 +25,7 @@ pub fn clear_color(r, g, b, a int) {
|
||||
}
|
||||
|
||||
pub fn clear() {
|
||||
C.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
|
||||
C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT | C.GL_STENCIL_BUFFER_BIT)
|
||||
}
|
||||
|
||||
pub fn create_shader(typ int) int {
|
||||
@@ -61,7 +46,7 @@ pub fn compile_shader(shader int) {
|
||||
|
||||
pub fn shader_compile_status(shader int) int {
|
||||
success := 0
|
||||
C.glGetShaderiv(shader, GL_COMPILE_STATUS, &success)
|
||||
C.glGetShaderiv(shader, C.GL_COMPILE_STATUS, &success)
|
||||
return success
|
||||
}
|
||||
|
||||
@@ -76,7 +61,7 @@ pub fn link_program(program int) {
|
||||
|
||||
pub fn get_program_link_status(program int) int {
|
||||
success := 0
|
||||
C.glGetProgramiv(program, GL_LINK_STATUS, &success)
|
||||
C.glGetProgramiv(program, C.GL_LINK_STATUS, &success)
|
||||
return success
|
||||
}
|
||||
|
||||
@@ -115,7 +100,7 @@ pub fn active_texture(t int) {
|
||||
}
|
||||
|
||||
pub fn bind_2d_texture(texture u32) {
|
||||
C.glBindTexture(GL_TEXTURE_2D, texture)
|
||||
C.glBindTexture(C.GL_TEXTURE_2D, texture)
|
||||
}
|
||||
|
||||
pub fn delete_texture(texture u32) {
|
||||
@@ -137,14 +122,14 @@ pub fn buffer_data_f32(typ int, vertices []f32, draw_typ int) {
|
||||
}
|
||||
|
||||
pub fn set_vbo(vbo u32, vertices []f32, draw_typ int) {
|
||||
gl.bind_buffer(GL_ARRAY_BUFFER, vbo)
|
||||
gl.buffer_data_f32(GL_ARRAY_BUFFER, vertices, draw_typ)
|
||||
gl.bind_buffer(C.GL_ARRAY_BUFFER, vbo)
|
||||
gl.buffer_data_f32(C.GL_ARRAY_BUFFER, vertices, draw_typ)
|
||||
}
|
||||
|
||||
pub fn set_ebo(ebo u32, indices []int, draw_typ int) {
|
||||
gl.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, ebo)
|
||||
gl.bind_buffer(C.GL_ELEMENT_ARRAY_BUFFER, ebo)
|
||||
// gl.buffer_data_int(GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ)
|
||||
gl.buffer_data_int(GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ)
|
||||
gl.buffer_data_int(C.GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ)
|
||||
}
|
||||
|
||||
// /////////////////////
|
||||
@@ -166,7 +151,7 @@ pub fn use_program(program int) {
|
||||
pub fn gen_vertex_array() u32 {
|
||||
vao := u32(0)
|
||||
C.glGenVertexArrays(1, &vao)
|
||||
return vao
|
||||
return vao
|
||||
}
|
||||
|
||||
pub fn enable_vertex_attrib_array(n int) {
|
||||
@@ -176,13 +161,13 @@ pub fn enable_vertex_attrib_array(n int) {
|
||||
pub fn gen_buffer() u32 {
|
||||
vbo := u32(0)
|
||||
C.glGenBuffers(1, &vbo)
|
||||
return vbo
|
||||
return vbo
|
||||
}
|
||||
|
||||
pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride int, _ptr int) {
|
||||
mut stride := _stride
|
||||
mut ptr := _ptr
|
||||
if typ == GL_FLOAT {
|
||||
pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride int, _ptr int) {
|
||||
mut stride := _stride
|
||||
mut ptr := _ptr
|
||||
if typ == C.GL_FLOAT {
|
||||
stride *= sizeof(f32)
|
||||
ptr *= sizeof(f32)
|
||||
}
|
||||
@@ -190,7 +175,7 @@ pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride
|
||||
}
|
||||
|
||||
pub fn tex_param(key, val int) {
|
||||
C.glTexParameteri(GL_TEXTURE_2D, key, val)
|
||||
C.glTexParameteri(C.GL_TEXTURE_2D, key, val)
|
||||
}
|
||||
|
||||
pub fn enable(val int) {
|
||||
|
||||
Reference in New Issue
Block a user