11 #include "zfeatures.h"
18 #define ADD_OP(a,b,c) OP_ ## a ,
24 /* initially # of allocated GLVertexes (will grow when necessary) */
25 #define POLYGON_MAX_VERTEX 16
27 /* Max # of specular light pow buffers */
28 #define MAX_SPECULAR_BUFFERS 8
29 /* # of entries in specular buffer */
30 #define SPECULAR_BUFFER_SIZE 1024
31 /* specular buffer granularity */
32 #define SPECULAR_BUFFER_RESOLUTION 1024
35 #define MAX_MODELVIEW_STACK_DEPTH 32
36 #define MAX_PROJECTION_STACK_DEPTH 8
37 #define MAX_TEXTURE_STACK_DEPTH 8
38 #define MAX_NAME_STACK_DEPTH 64
39 #define MAX_TEXTURE_LEVELS 11
42 #define VERTEX_HASH_SIZE 1031
44 #define MAX_DISPLAY_LISTS 1024
45 #define OP_BUFFER_MAX_SIZE 512
47 #define TGL_OFFSET_FILL 0x1
48 #define TGL_OFFSET_LINE 0x2
49 #define TGL_OFFSET_POINT 0x4
51 typedef struct GLSpecBuf
{
54 float buf
[SPECULAR_BUFFER_SIZE
+1];
55 struct GLSpecBuf
*next
;
58 typedef struct GLLight
{
67 /* precomputed values */
68 float cos_spot_cutoff
;
69 V3 norm_spot_direction
;
71 /* we use a linked list to know which are the enabled lights */
73 struct GLLight
*next
,*prev
;
76 typedef struct GLMaterial
{
89 typedef struct GLViewport
{
90 int xmin
,ymin
,xsize
,ysize
;
104 typedef struct GLParamBuffer
{
105 GLParam ops
[OP_BUFFER_MAX_SIZE
];
106 struct GLParamBuffer
*next
;
109 typedef struct GLList
{
110 GLParamBuffer
*first_op_buffer
;
111 /* TODO: extensions for an hash table or a better allocating scheme */
114 typedef struct GLVertex
{
121 /* computed values */
122 V4 ec
; /* eye coordinates */
123 V4 pc
; /* coordinates in the normalized volume */
124 int clip_code
; /* clip code */
125 ZBufferPoint zp
; /* integer coordinates for the rasterization */
128 typedef struct GLImage
{
135 #define TEXTURE_HASH_TABLE_SIZE 256
137 typedef struct GLTexture
{
138 GLImage images
[MAX_TEXTURE_LEVELS
];
140 struct GLTexture
*next
,*prev
;
146 typedef struct GLSharedState
{
148 GLTexture
**texture_hash_table
;
153 typedef void (*gl_draw_triangle_func
)(struct GLContext
*c
,
154 GLVertex
*p0
,GLVertex
*p1
,GLVertex
*p2
);
156 /* display context */
158 typedef struct GLContext
{
163 GLLight lights
[MAX_LIGHTS
];
164 GLLight
*first_light
;
165 V4 ambient_light_model
;
166 int local_light_model
;
167 int lighting_enabled
;
168 int light_model_two_side
;
171 GLMaterial materials
[2];
172 int color_material_enabled
;
173 int current_color_material_mode
;
174 int current_color_material_type
;
177 GLTexture
*current_texture
;
178 int texture_2d_enabled
;
181 GLSharedState shared_state
;
184 GLParamBuffer
*current_op_buffer
;
185 int current_op_buffer_index
;
186 int exec_flag
,compile_flag
,print_flag
;
192 M4
*matrix_stack_ptr
[3];
193 int matrix_stack_depth_max
[3];
195 M4 matrix_model_view_inv
;
196 M4 matrix_model_projection
;
197 int matrix_model_projection_updated
;
198 int matrix_model_projection_no_w_transform
;
199 int apply_texture_matrix
;
205 int polygon_mode_back
;
206 int polygon_mode_front
;
208 int current_front_face
;
209 int current_shade_model
;
210 int current_cull_face
;
211 int cull_face_enabled
;
212 int normalize_enabled
;
213 gl_draw_triangle_func draw_triangle_front
,draw_triangle_back
;
217 unsigned int *select_buffer
;
219 unsigned int *select_ptr
,*select_hit
;
224 unsigned int name_stack
[MAX_NAME_STACK_DEPTH
];
231 /* current vertex state */
233 unsigned int longcurrent_color
[3]; /* precomputed integer color */
235 V4 current_tex_coord
;
236 int current_edge_flag
;
238 /* glBegin / glEnd */
241 int vertex_n
,vertex_cnt
;
245 /* opengl 1.1 arrays */
247 int vertex_array_size
;
248 int vertex_array_stride
;
250 int normal_array_stride
;
252 int color_array_size
;
253 int color_array_stride
;
254 float *texcoord_array
;
255 int texcoord_array_size
;
256 int texcoord_array_stride
;
259 /* opengl 1.1 polygon offset */
264 /* specular buffer. could probably be shared between contexts,
265 but that wouldn't be 100% thread safe */
266 GLSpecBuf
*specbuf_first
;
267 int specbuf_used_counter
;
268 int specbuf_num_buffers
;
270 /* opaque structure for user's use */
272 /* resize viewport function */
273 int (*gl_resize_viewport
)(struct GLContext
*c
,int *xsize
,int *ysize
);
279 extern GLContext
*gl_ctx
;
281 void gl_add_op(GLParam
*p
);
284 void gl_transform_to_viewport(GLContext
*c
,GLVertex
*v
);
285 void gl_draw_triangle(GLContext
*c
,GLVertex
*p0
,GLVertex
*p1
,GLVertex
*p2
);
286 void gl_draw_line(GLContext
*c
,GLVertex
*p0
,GLVertex
*p1
);
287 void gl_draw_point(GLContext
*c
,GLVertex
*p0
);
289 void gl_draw_triangle_point(GLContext
*c
,
290 GLVertex
*p0
,GLVertex
*p1
,GLVertex
*p2
);
291 void gl_draw_triangle_line(GLContext
*c
,
292 GLVertex
*p0
,GLVertex
*p1
,GLVertex
*p2
);
293 void gl_draw_triangle_fill(GLContext
*c
,
294 GLVertex
*p0
,GLVertex
*p1
,GLVertex
*p2
);
295 void gl_draw_triangle_select(GLContext
*c
,
296 GLVertex
*p0
,GLVertex
*p1
,GLVertex
*p2
);
299 void gl_print_matrix(const float *m
);
301 void glopLoadIdentity(GLContext *c,GLParam *p);
302 void glopTranslate(GLContext *c,GLParam *p);*/
305 void gl_add_select(GLContext
*c
,unsigned int zmin
,unsigned int zmax
);
306 void gl_enable_disable_light(GLContext
*c
,int light
,int v
);
307 void gl_shade_vertex(GLContext
*c
,GLVertex
*v
);
309 void glInitTextures(GLContext
*c
);
310 void glEndTextures(GLContext
*c
);
311 GLTexture
*alloc_texture(GLContext
*c
,int h
);
314 void gl_convertRGB_to_5R6G5B(unsigned short *pixmap
,unsigned char *rgb
,
315 int xsize
,int ysize
);
316 void gl_convertRGB_to_8A8R8G8B(unsigned int *pixmap
, unsigned char *rgb
,
317 int xsize
, int ysize
);
318 void gl_resizeImage(unsigned char *dest
,int xsize_dest
,int ysize_dest
,
319 unsigned char *src
,int xsize_src
,int ysize_src
);
320 void gl_resizeImageNoInterpolate(unsigned char *dest
,int xsize_dest
,int ysize_dest
,
321 unsigned char *src
,int xsize_src
,int ysize_src
);
323 GLContext
*gl_get_context(void);
325 void gl_fatal_error(char *format
, ...);
328 /* specular buffer "api" */
329 GLSpecBuf
*specbuf_get_buffer(GLContext
*c
, const int shininess_i
,
330 const float shininess
);
333 void dprintf(const char *, ...);
339 #define dprintf(format, args...) \
340 fprintf(stderr,"In '%s': " format "\n",__FUNCTION__, ##args);
344 #define dprintf(format, args...)
349 /* glopXXX functions */
351 #define ADD_OP(a,b,c) void glop ## a (GLContext *,GLParam *);
354 /* this clip epsilon is needed to avoid some rounding errors after
355 several clipping stages */
357 #define CLIP_EPSILON (1E-5)
359 static inline int gl_clipcode(float x
,float y
,float z
,float w1
)
363 w
=w1
* (1.0 + CLIP_EPSILON
);
372 #endif /* _tgl_zgl_h_ */