added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / 3dengfx / 3denginefx.hpp
1 /*
2 This file is part of the 3dengfx, realtime visualization system.
3
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
5
6 3dengfx is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 3dengfx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with 3dengfx; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 /* main 3dengfx state control, and low level OpenGL interaction
22  *
23  * Author: John Tsiombikas 2004
24  * Modified: John Tsiombikas 2005
25  */
26
27 #ifndef _3DENGINEFX_HPP_
28 #define _3DENGINEFX_HPP_
29
30 #include "opengl.h"
31 #include "3denginefx_types.hpp"
32 #include "textures.hpp"
33 #include "material.hpp"
34 #include "gfx/3dgeom.hpp"
35 #include "gfx/image.h"
36 #include "light.hpp"
37
38 class Camera;
39
40 namespace engfx_state {
41         extern SysCaps sys_caps;
42         extern Matrix4x4 world_matrix, view_matrix, inv_view_matrix;
43         extern const Camera *view_mat_camera;
44         extern Matrix4x4 proj_matrix;
45         extern const Light *bump_light;
46         extern int light_count;
47 }
48
49 bool create_graphics_context(const GraphicsInitParameters &gip);
50 bool create_graphics_context(int x, int y, bool fullscreen);
51 bool start_gl();
52 void destroy_graphics_context();
53 void set_default_states();
54 const GraphicsInitParameters *get_graphics_init_parameters();
55
56 void clear(const Color &color);
57 void clear_zbuffer(scalar_t zval);
58 void clear_stencil(unsigned char sval);
59 void clear_zbuffer_stencil(scalar_t zval, unsigned char sval);
60
61 void flip();
62
63 void load_xform_matrices();
64 void draw(const VertexArray &varray);
65 void draw(const VertexArray &varray, const IndexArray &iarray);
66 void draw_line(const Vertex &v1, const Vertex &v2, scalar_t w1, scalar_t w2 = -1.0, const Color &col = 1.0);
67 void draw_point(const Vertex &pt, scalar_t size);
68 void draw_scr_quad(const Vector2 &corner1, const Vector2 &corner2, const Color &color = Color(1.0), bool reset_xform = true);
69
70 int get_texture_unit_count();
71
72 ////// render states //////
73 void set_primitive_type(PrimitiveType pt);
74 void set_backface_culling(bool enable);
75 void set_front_face(FaceOrder order);
76 void set_auto_normalize(bool enable);
77 //void set_billboarding(bool enable);
78 void set_color_write(bool red, bool green, bool blue, bool alpha);
79 void set_wireframe(bool enable);
80
81 // blending states
82 void set_alpha_blending(bool enable);
83 void set_blend_func(BlendingFactor src, BlendingFactor dest);
84
85 // zbuffer states
86 void set_zbuffering(bool enable);
87 void set_zwrite(bool enable);
88 void set_zfunc(CmpFunc func);
89
90 // set stencil buffer states
91 void set_stencil_buffering(bool enable);
92 void set_stencil_pass_op(StencilOp sop);
93 void set_stencil_fail_op(StencilOp sop);
94 void set_stencil_pass_zfail_op(StencilOp sop);
95 void set_stencil_op(StencilOp fail, StencilOp spass_zfail, StencilOp pass);
96 void set_stencil_func(CmpFunc func);
97 void set_stencil_reference(unsigned int ref);
98
99 // texture & material states
100 void set_point_sprites(bool enable);
101 void set_texture_filtering(int tex_unit, TextureFilteringType tex_filter);
102 void set_texture_addressing(int tex_unit, TextureAddressing uaddr, TextureAddressing vaddr);
103 void set_texture_border_color(int tex_unit, const Color &color);
104 void set_texture(int tex_unit, const Texture *tex);
105 //void set_texture_factor(unsigned int factor);
106 void set_mip_mapping(bool enable);
107 void set_material(const Material &mat);
108 void use_vertex_colors(bool enable);
109
110 void set_render_target(Texture *tex, CubeMapFace cube_map_face = CUBE_MAP_PX);
111 void copy_texture(Texture *tex, bool full_screen = false);
112
113 // multitexturing interface
114 void select_texture_unit(int tex_unit);
115 void enable_texture_unit(int tex_unit);
116 void disable_texture_unit(int tex_unit);
117 void set_texture_unit_color(int tex_unit, TextureBlendFunction op, TextureBlendArgument arg1, TextureBlendArgument arg2, TextureBlendArgument arg3 = TARG_NONE);
118 void set_texture_unit_alpha(int tex_unit, TextureBlendFunction op, TextureBlendArgument arg1, TextureBlendArgument arg2, TextureBlendArgument arg3 = TARG_NONE);
119 void set_texture_coord_index(int tex_unit, int index);
120 void set_texture_constant(int tex_unit, const Color &col);
121 //void set_texture_transform_state(int tex_unit, TexTransformState TexXForm);
122 //void set_texture_coord_generator(int stage, TexGen tgen);
123 void set_point_sprite_coords(int tex_unit, bool enable);
124
125 // programmable interface
126 void set_gfx_program(GfxProg *prog);
127
128 // lighting states
129 void set_lighting(bool enable);
130 //void set_color_vertex(bool enable);
131 void set_ambient_light(const Color &ambient_color);
132 void set_shading_mode(ShadeMode mode);
133 //void set_specular(bool enable);
134
135 void set_bump_light(const Light *light);
136
137 // Transformation Matrices
138 void set_matrix(TransformType xform_type, const Matrix4x4 &mat, int num = 0);
139 Matrix4x4 get_matrix(TransformType xform_type, int num = 0);
140
141 // viewport
142 void set_viewport(unsigned int x, unsigned int y, unsigned int xsize, unsigned int ysize);
143 // normalized set_viewport()
144 void set_viewport_norm(float x, float y, float xsize, float ysize);
145
146 Matrix4x4 create_projection_matrix(scalar_t vfov, scalar_t aspect, scalar_t near, scalar_t far);
147
148 // misc
149 bool screen_capture(char *fname = 0, enum image_file_format fmt = IMG_FMT_TGA);
150
151
152 GraphicsInitParameters *load_graphics_context_config(const char *fname);
153 void engine_log(const char *log_data, const char *subsys = 0);
154 SysCaps get_system_capabilities();
155 const char *get_glerror_string(GLenum error);
156 extern void (*load_matrix_gl)(const Matrix4x4 &mat);
157
158 #endif  // _3DENGINEFX_HPP_