njin
Engine 2D gọn nhẹ để tự tay làm game theo ý mình. Vibe coding cũng ổn luôn
Loading...
Searching...
No Matches
njin_render.h
1#pragma once
2#include "_types.h"
3
4namespace njin {
5// Opaque, see njin_ctx.h.
6struct context;
7
10
19shader_handle shader_load(context &ctx, const char *vspath,
20 const char *fspath);
21
25void shader_unload(context &ctx, shader_handle handle);
26
33void shader_begin(const context &ctx, shader_handle handle);
34
37void shader_end(const context &ctx);
38
45void shader_set_i32(context &ctx, shader_handle handle, const char *name,
46 i32 value);
47
53void shader_set_f32(context &ctx, shader_handle handle, const char *name,
54 f32 value);
55
61void shader_set_vec2(context &ctx, shader_handle handle, const char *name,
62 vec2 value);
63
69void shader_set_vec3(context &ctx, shader_handle handle, const char *name,
70 vec3 value);
71
77void shader_set_vec4(context &ctx, shader_handle handle, const char *name,
78 vec4 value);
79
90void shader_set_vec4_array(context &ctx, shader_handle handle, const char *name,
91 const vec4 *values, u32 count);
92
113void shader_set_texture(context &ctx, shader_handle handle, const char *name, texture_handle texture);
114
124void shader_set_texture(context &ctx, shader_handle handle, const char *name,
125 render_texture_handle texture);
127
130
137bool instancing_available(const context &ctx);
138
149instance_buffer_handle instance_buffer_create(context &ctx, u32 floats_per_instance);
150
155
164void instance_buffer_upload(context &ctx, instance_buffer_handle handle, const f32 *data,
165 u32 count);
166
188void draw_instanced(context &ctx, instance_buffer_handle handle, shader_handle shader, u32 first,
189 u32 count);
190
202void draw_instanced(context &ctx, instance_buffer_handle handle, shader_handle shader, u32 first,
203 u32 count, texture_handle texture);
204
217void draw_instanced(context &ctx, instance_buffer_handle handle, shader_handle shader, u32 first,
218 u32 count, render_texture_handle texture);
220
223
230texture_handle texture_load(context &ctx, const char *path);
231
235void texture_unload(context &ctx, texture_handle handle);
236
241vec2 texture_size(const context &ctx, texture_handle handle);
242
251void texture_draw(const context &ctx, texture_handle handle, vec2 pos,
252 rgba tint);
254
257
267 u32 height);
268
273
279
290void render_texture_begin(const context &ctx, render_texture_handle handle);
291
296void render_texture_begin(const context &ctx, render_texture_handle handle,
297 rgba clear);
298
301void render_texture_end(const context &ctx);
302
318bool render_texture_save(context &ctx, render_texture_handle handle, const char *path);
319
325void render_texture_draw(const context &ctx, render_texture_handle handle,
326 vec2 pos, rgba tint);
328} // namespace njin
void instance_buffer_upload(context &ctx, instance_buffer_handle handle, const f32 *data, u32 count)
Ghi count instance vào bộ đệm, thay toàn bộ nội dung cũ.
instance_buffer_handle instance_buffer_create(context &ctx, u32 floats_per_instance)
Tạo một bộ đệm instance trên GPU: mỗi instance là floats_per_instance số thực, do game tự quyết định ...
void draw_instanced(context &ctx, instance_buffer_handle handle, shader_handle shader, u32 first, u32 count)
Vẽ count hình vuông, bắt đầu từ instance first, bằng một lệnh vẽ.
bool instancing_available(const context &ctx)
Máy này có vẽ instanced được không: cần OpenGL 3.3 trở lên (hoặc ES 3.0).
void instance_buffer_destroy(context &ctx, instance_buffer_handle handle)
Hủy bộ đệm instance.
void render_texture_end(const context &ctx)
Kết thúc vẽ vào render texture.
bool render_texture_save(context &ctx, render_texture_handle handle, const char *path)
Lưu nội dung render texture ra file ảnh, ngay lập tức.
vec2 render_texture_size(const context &ctx, render_texture_handle handle)
Kích thước render texture (pixel).
void render_texture_begin(const context &ctx, render_texture_handle handle)
Bắt đầu vẽ vào render texture, giữ nguyên nội dung cũ.
void render_texture_unload(context &ctx, render_texture_handle handle)
Giải phóng render texture.
void render_texture_draw(const context &ctx, render_texture_handle handle, vec2 pos, rgba tint)
Vẽ nội dung render texture theo đúng chiều, góc trên trái tại pos.
render_texture_handle render_texture_load(context &ctx, u32 width, u32 height)
Tạo một render texture: ảnh ngoài màn hình để vẽ vào, rồi vẽ lại như một texture.
void shader_set_vec4_array(context &ctx, shader_handle handle, const char *name, const vec4 *values, u32 count)
Đặt uniform kiểu mảng vec4, ví dụ uniform vec4 lights[8];.
void shader_unload(context &ctx, shader_handle handle)
Giải phóng shader.
void shader_set_vec3(context &ctx, shader_handle handle, const char *name, vec3 value)
Đặt uniform kiểu vec3.
void shader_set_vec4(context &ctx, shader_handle handle, const char *name, vec4 value)
Đặt uniform kiểu vec4.
void shader_begin(const context &ctx, shader_handle handle)
Bật shader cho mọi thứ vẽ sau đó, cho đến shader_end().
void shader_end(const context &ctx)
Tắt shader đã bật bằng shader_begin().
void shader_set_texture(context &ctx, shader_handle handle, const char *name, texture_handle texture)
Gắn một texture vào uniform sampler2D của shader, ngoài texture0.
void shader_set_f32(context &ctx, shader_handle handle, const char *name, f32 value)
Đặt uniform kiểu float.
void shader_set_i32(context &ctx, shader_handle handle, const char *name, i32 value)
Đặt uniform kiểu int.
void shader_set_vec2(context &ctx, shader_handle handle, const char *name, vec2 value)
Đặt uniform kiểu vec2.
shader_handle shader_load(context &ctx, const char *vspath, const char *fspath)
Nạp và biên dịch một shader.
vec2 texture_size(const context &ctx, texture_handle handle)
Kích thước texture (pixel).
void texture_draw(const context &ctx, texture_handle handle, vec2 pos, rgba tint)
Vẽ texture với góc trên trái tại pos.
void texture_unload(context &ctx, texture_handle handle)
Giải phóng texture.
texture_handle texture_load(context &ctx, const char *path)
Nạp một texture từ file ảnh.
std::int32_t i32
Số nguyên có dấu 32 bit.
Definition _types.h:14
float f32
Số thực 32 bit.
Definition _types.h:28
std::uint32_t u32
Số nguyên không dấu 32 bit.
Definition _types.h:22
Định danh của một bộ đệm instance, tạo bởi instance_buffer_create().
Definition _types.h:109
Định danh của một render texture, tạo bởi render_texture_load().
Definition _types.h:307
Màu gồm đỏ, xanh lá, xanh dương và alpha.
Definition _types.h:64
Định danh của một shader, tạo bởi shader_load().
Definition _types.h:101
Định danh của một texture, tạo bởi texture_load().
Definition _types.h:146
Vector 2 chiều. Dùng cho vị trí, kích thước, độ dời.
Definition _types.h:39
Vector 3 chiều.
Definition _types.h:47
Vector 4 chiều. Dùng để truyền giá trị vec4 vào uniform của shader.
Definition _types.h:54