client/runtime/gl_renderer.h (4028B)
1 #ifndef GL_RENDERER_H 2 #define GL_RENDERER_H 3 #include <stdint.h> 4 5 /* These are host objects. Guest addresses are translated by the API adapter. */ 6 struct gl_target; 7 struct gl_depth; 8 struct gl_vertex_buffer; 9 struct gl_vertex { 10 float position[4]; /* D3D clip coordinates, or object coordinates with GPU transforms. */ 11 float color[4]; 12 float uv[2]; 13 float fog; 14 float uv_second[2]; 15 float specular[3]; /* Specular RGB, or the normal with GPU transforms. */ 16 }; 17 struct gl_texture_state { 18 struct gl_target *image; 19 int min_linear, mag_linear, clamp_u, clamp_v, alpha, color_op, alpha_op, mip_point; 20 int color_arg2, alpha_arg2; 21 int color_arg1, alpha_arg1; 22 uint32_t factor; 23 }; 24 25 /* vec4-sized fields match the shader's std140 uniform block. */ 26 struct gl_vertex_transform { 27 float world_view[16], projection[16], normal[12]; 28 float viewport[4], material_diffuse[4], material_ambient[4], material_emissive[4]; 29 float ambient[4]; 30 struct { 31 float vector[4]; /* Camera-space xyz; w is the D3D type, or zero for the end. */ 32 float diffuse[4], ambient[4]; 33 float attenuation[4]; /* constant, linear, quadratic, range */ 34 } lights[8]; 35 float fog[4]; /* start, end, linear fog enabled, padding */ 36 float flags[4]; /* lighting, normalize normals, vertex diffuse, vertex emissive */ 37 }; 38 void gl_renderer_set_vertex_transform(const struct gl_vertex_transform *state); 39 int gl_renderer_initialize(void); 40 void gl_renderer_shutdown(void); 41 void gl_renderer_restore(void); 42 struct gl_target *gl_target_create(unsigned width, unsigned height, int with_depth); 43 void gl_target_destroy(struct gl_target *target); 44 void gl_target_set_mip(struct gl_target *target, struct gl_target *mip); 45 /* NULL preserves the GPU contents without an existing CPU copy. */ 46 void gl_target_evict(struct gl_target *target, const unsigned char *rgba); 47 struct gl_depth *gl_depth_create(unsigned width, unsigned height, unsigned bits); 48 void gl_depth_destroy(struct gl_depth *depth); 49 void gl_target_set_depth(struct gl_target *target, struct gl_depth *depth); 50 void gl_target_clear(struct gl_target *target, uint32_t argb, float depth); 51 void gl_target_clear_rect(struct gl_target *target, uint32_t flags, uint32_t argb, float depth, const int32_t rectangle[4]); 52 /* Primitive is D3D line list (2) or triangle list (4); clip is guest top-down x, y, width, height. */ 53 void gl_target_draw(struct gl_target *target, unsigned primitive, const struct gl_vertex *vertices, 54 unsigned vertex_count, const uint16_t *indices, unsigned index_count, const int32_t clip[4]); 55 void gl_target_draw_fvf(struct gl_target *target, unsigned primitive, const void *vertices, 56 unsigned fvf, const unsigned coordinates[2], const float color[4], unsigned vertex_count, 57 const uint16_t *indices, unsigned index_count, const int32_t clip[4], 58 struct gl_vertex_buffer *buffer, unsigned offset); 59 struct gl_vertex_buffer *gl_vertex_buffer_create(const void *vertices, unsigned size); 60 /* CPU bytes remain owned by the caller; mark writes before the next draw. */ 61 void gl_vertex_buffer_invalidate(struct gl_vertex_buffer *buffer); 62 void gl_vertex_buffer_destroy(struct gl_vertex_buffer *buffer); 63 void gl_target_read(struct gl_target *target, unsigned char *rgba); 64 void gl_target_write(struct gl_target *target, const unsigned char *rgba); 65 void gl_target_blit(struct gl_target *source, struct gl_target *target, const int32_t source_rect[4], const int32_t target_rect[4]); 66 void gl_target_present(struct gl_target *target, const int32_t rectangle[4], int width, int height); 67 void gl_renderer_set_texture(unsigned stage, const struct gl_texture_state *state); 68 void gl_renderer_set_fog(int enabled, uint32_t color); 69 void gl_renderer_set_alpha_test(int enabled, uint32_t function, uint32_t reference); 70 void gl_renderer_set_blend(int enabled, uint32_t source, uint32_t destination); 71 void gl_renderer_set_depth(int enabled, int write, uint32_t function, uint32_t bias); 72 void gl_renderer_set_cull(uint32_t mode); 73 74 #endif