Graphics Device¶
Typedefs
-
typedef struct binocle_gd_gfx_t binocle_gd_gfx_t¶
-
typedef struct binocle_gd_uniform_t binocle_gd_uniform_t¶
-
typedef struct binocle_gd_command_t binocle_gd_command_t¶
-
typedef struct binocle_gd binocle_gd¶
a graphic device used to perform OpenGL calls and store the needed state
Functions
-
binocle_gd binocle_gd_new()¶
Creates a new graphic device.
- Returns
the instance of the graphic device
-
void binocle_gd_destroy(binocle_gd *gd)¶
-
void binocle_gd_init(binocle_gd *gd, struct binocle_window *win)¶
Initializes a graphic device
- Parameters
gd – the pointer to the graphics device
wind – the pointer to the window
-
void binocle_gd_setup_default_pipeline(binocle_gd *gd, uint32_t offscreen_width, uint32_t offscreen_height, sg_shader offscreen_shader, sg_shader display_shader)¶
-
void binocle_gd_render_offscreen(binocle_gd *gd)¶
-
void binocle_gd_render_screen(binocle_gd *gd, struct binocle_window *window, float design_width, float design_height, kmAABB2 viewport, kmMat4 matrix, float scale)¶
-
void binocle_gd_render(binocle_gd *gd, struct binocle_window *window, float design_width, float design_height, kmAABB2 viewport, kmMat4 matrix, float scale)¶
-
kmMat4 binocle_gd_create_model_view_matrix(float x, float y, float scale, float rotation)¶
Creates a 2D model view matrix
- Parameters
x – the horizontal position
y – the vertical position
scale – the scale
rotation – the rotation
- Returns
the model-view matrix
-
void binocle_gd_draw(binocle_gd *gd, const struct binocle_vpct *vertices, size_t vertex_count, struct binocle_material material, kmAABB2 viewport, struct binocle_camera *camera)¶
draws a vertex buffer to the screen given a material, viewport and camera
- Parameters
gd – the graphics device instance
vertices – the vertex buffer
vertex_count – the numer of vertices
material – the material to use
viewport – the viewport to apply
camera – the camera
-
void binocle_gd_apply_gl_states()¶
Applies the default OpenGL states for basic 2D drawing.
-
void binocle_gd_apply_viewport(kmAABB2 viewport)¶
Applies the given viewport.
- Parameters
viewport – the viewport to apply
-
void binocle_gd_apply_blend_mode(const struct sg_blend_state blend_mode)¶
Applies the given blend mode.
- Parameters
blend_mode – the requested blend mode
-
void binocle_gd_apply_shader(binocle_gd *gd, sg_shader shader)¶
Applies the given shader.
- Parameters
gd – the graphics device instance
shader – the shader
-
void binocle_gd_apply_texture(struct sg_image texture)¶
Applies the given texture.
- Parameters
texture – the texture to use
-
GLuint binocle_gd_factor_to_gl_constant(enum sg_blend_factor blend_factor)¶
-
GLuint binocle_gd_equation_to_gl_constant(enum sg_blend_op blend_equation)¶
Converts the given blend equation to the corresponding OpenGL one.
- Parameters
blend_equation – the blend equation
- Returns
the OpenGL blend equation constant
-
void binocle_gd_set_uniform_float(struct sg_shader *shader, const char *name, float value)¶
Sets a uniform float value for the given shader.
- Parameters
shader – the shader
name – the name of the uniform
value – the value to set
-
void binocle_gd_set_uniform_float2(sg_shader shader, const char *name, float value1, float value2)¶
Sets a uniform float2 value for the given shader.
- Parameters
shader – the shader
name – the name of the uniform
value1 – the first float value
value2 – the second float value
-
void binocle_gd_set_uniform_float3(struct sg_shader *shader, const char *name, float value1, float value2, float value3)¶
Sets a uniform float3 value for the given shader.
- Parameters
shader – the shader
name – the name of the uniform
value1 – the first float value
value2 – the second float value
value3 – the third float value
-
void binocle_gd_set_uniform_float4(struct sg_shader *shader, const char *name, float value1, float value2, float value3, float value4)¶
Sets a uniform float4 value for the given shader.
- Parameters
shader – the shader
name – the name of the uniform
value1 – the first float value
value2 – the second float value
value3 – the third float value
value4 – the fourth float value
-
void binocle_gd_set_offscreen_clear_color(binocle_gd *gd, struct sg_color color)¶
Sets the clear color for the offscreen buffer.
- Parameters
color – the color
-
void binocle_gd_set_render_target(sg_image render_target)¶
Binds the frame buffer and the render buffer of a render target.
- Parameters
render_target – the render target. If NULL, it sets both the frame buffer and render buffer to 0.
-
void binocle_gd_draw_quad(binocle_gd *gd, sg_image image)¶
Draws a quad to the current buffer using the given shader.
- Parameters
shader – the shader
-
void binocle_gd_draw_quad_to_screen(binocle_gd *gd, sg_shader shader, sg_image render_target)¶
Draws a quad to the screen buffer using the given shader and render target.
- Parameters
shader – the shader
render_target – the render target to use as source
-
void binocle_gd_set_uniform_render_target_as_texture(struct sg_shader *shader, const char *name, sg_image render_target)¶
Sets a render target as the texture for a given uniform.
- Parameters
shader – the shader
name – the name of the uniform
render_target – the render target whose texture will be set as uniform
-
void binocle_gd_set_uniform_vec3(struct sg_shader *shader, const char *name, kmVec3 vec)¶
Sets a uniform vec3 value.
- Parameters
shader – the shader
name – the name of the uniform
vec – the vec3 value
-
void binocle_gd_set_uniform_mat4(sg_shader shader, const char *name, kmMat4 mat)¶
Sets a uniform mat4 value.
- Parameters
shader – the shader
name – the name of the uniform
mat – the mat4 value
-
void binocle_gd_draw_rect(binocle_gd *gd, kmAABB2 rect, struct sg_color col, kmAABB2 viewport, struct binocle_camera *camera)¶
Draws a rectangle to the current buffer.
- Parameters
gd – the graphics device instance
rect – the rectangle to draw
col – the color to fill the rectangle with
viewport – the viewport
camera – the camera
-
void binocle_gd_draw_rect_outline(binocle_gd *gd, kmAABB2 rect, struct sg_color col, kmAABB2 viewport, struct binocle_camera *camera)¶
Draws the outline of a rectangle to the current buffer.
- Parameters
gd – the graphics device instance
rect – the rectangle to draw
col – the color to fill the rectangle with
viewport – the viewport
camera – the camera
-
void binocle_gd_draw_line(binocle_gd *gd, kmVec2 start, kmVec2 end, struct sg_color col, kmAABB2 viewport, struct binocle_camera *camera)¶
Draws a line to the current buffer.
- Parameters
gd – the graphics device
start – the starting point
end – the ending point
col – the color
viewport – the viewport
camera – the camera
-
void binocle_gd_draw_circle(binocle_gd *gd, kmVec2 center, float radius, struct sg_color col, kmAABB2 viewport, kmMat4 viewMatrix)¶
Draws a circle to the current buffer.
- Parameters
gd – the graphics device
center – the coordinates of the center of the circle
radius – the radius of the circle
col – the color
viewport – the viewport
viewMatrix – the view matrix
-
void binocle_gd_draw_with_state(binocle_gd *gd, const struct binocle_vpct *vertices, size_t vertex_count, struct binocle_render_state *render_state)¶
Draws the graphic device’s vertex buffer using the given render state.
- Parameters
gd – the graphics device instance
vertices – the buffer with the vertices to draw
vertex_count – the number of vertices
render_state – the render state
-
void binocle_gd_draw_mesh(binocle_gd *gd, const struct binocle_mesh *mesh, kmAABB2 viewport, struct binocle_camera_3d *camera)¶
-
void binocle_gd_draw_test_triangle(struct sg_shader *shader)¶
-
void binocle_gd_draw_test_cube(struct sg_shader *shader)¶
-
void binocle_gd_setup_flat_pipeline(binocle_gd *gd)¶
-
void binocle_gd_render_flat(binocle_gd *gd)¶
-
struct binocle_gd_gfx_t
-
struct binocle_gd_uniform_t
-
struct binocle_gd_command_t
Public Members
-
sg_image img¶
-
uint32_t base_vertex¶
-
uint32_t num_vertices¶
-
binocle_gd_uniform_t uniforms¶
-
sg_image img¶
-
struct binocle_gd
- #include <binocle_gd.h>
a graphic device used to perform OpenGL calls and store the needed state
Public Members
-
binocle_gd_gfx_t offscreen¶
-
binocle_gd_gfx_t display¶
-
binocle_gd_gfx_t flat¶
-
struct binocle_vpct *vertices¶
-
uint32_t num_vertices¶
-
binocle_gd_command_t *commands¶
-
uint32_t num_commands¶
-
struct binocle_vpct *flat_vertices¶
-
uint32_t flat_num_vertices¶
-
binocle_gd_command_t *flat_commands¶
-
uint32_t flat_num_commands¶
-
binocle_gd_gfx_t offscreen¶