nkeynes@653: /** nkeynes@653: * $Id$ nkeynes@653: * nkeynes@653: * PVR2 rendering functions (private) nkeynes@653: * nkeynes@653: * Copyright (c) 2005 Nathan Keynes. nkeynes@653: * nkeynes@653: * This program is free software; you can redistribute it and/or modify nkeynes@653: * it under the terms of the GNU General Public License as published by nkeynes@653: * the Free Software Foundation; either version 2 of the License, or nkeynes@653: * (at your option) any later version. nkeynes@653: * nkeynes@653: * This program is distributed in the hope that it will be useful, nkeynes@653: * but WITHOUT ANY WARRANTY; without even the implied warranty of nkeynes@653: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nkeynes@653: * GNU General Public License for more details. nkeynes@653: */ nkeynes@653: nkeynes@653: #ifndef lxdream_render_H nkeynes@653: #define lxdream_render_H 1 nkeynes@653: nkeynes@653: /************************* Intermediate vertex buffer ************************/ nkeynes@653: nkeynes@653: typedef enum { nkeynes@653: SORT_NEVER = 0, nkeynes@653: SORT_TILEFLAG = 1, /* In this mode, sorting is controlled by the per-segment flag */ nkeynes@653: SORT_ALWAYS = 2 nkeynes@653: } tile_sort_mode_t; nkeynes@653: nkeynes@653: struct vertex_struct { nkeynes@653: float u,v; nkeynes@653: uint32_t rgba; nkeynes@653: float x,y,z; nkeynes@653: uint32_t offset_rgba; nkeynes@653: }; nkeynes@653: nkeynes@653: struct polygon_struct { nkeynes@653: uint32_t *context; nkeynes@653: int cull; // culling mode nkeynes@653: uint32_t vertex_count; // number of vertexes in polygon nkeynes@653: uint32_t tex_id; nkeynes@653: int32_t vertex_index; // index of first vertex in vertex buffer nkeynes@653: uint32_t mod_tex_id; nkeynes@653: int32_t mod_vertex_index; // index of first modified vertex in vertex buffer nkeynes@653: float center_z; nkeynes@653: struct polygon_struct *next; // chain for tri/quad arrays nkeynes@653: }; nkeynes@653: nkeynes@653: void pvr2_scene_init(void); nkeynes@653: void pvr2_scene_read(void); nkeynes@653: void pvr2_scene_shutdown(); nkeynes@653: nkeynes@669: uint32_t pvr2_scene_buffer_width(); nkeynes@669: uint32_t pvr2_scene_buffer_height(); nkeynes@669: nkeynes@669: extern unsigned char *video_base; nkeynes@653: nkeynes@653: /** nkeynes@653: * Maximum possible size of the vertex buffer. This is figured as follows: nkeynes@653: * PVR2 polygon buffer is limited to 4MB. The tightest polygon format nkeynes@653: * is 3 vertexes in 48 bytes = 16 bytes/vertex, (shadow triangle) nkeynes@653: * (the next tightest is 8 vertex in 140 bytes (6-strip colour-only)). nkeynes@653: * giving a theoretical maximum of 262144 vertexes. nkeynes@653: * The expanded structure is 44 bytes/vertex, giving nkeynes@653: * 11534336 bytes... nkeynes@653: */ nkeynes@653: #define MAX_VERTEXES 262144 nkeynes@653: #define MAX_VERTEX_BUFFER_SIZE (MAX_VERTEXES*sizeof(struct vertex_struct)) nkeynes@653: nkeynes@653: /** nkeynes@653: * Maximum polygons - smallest is 1 polygon in 48 bytes, giving nkeynes@653: * 87381 nkeynes@653: * nkeynes@653: */ nkeynes@653: #define MAX_POLYGONS 87382 nkeynes@653: #define MAX_POLY_BUFFER_SIZE (MAX_POLYGONS*sizeof(struct polygon_struct)) nkeynes@653: #define BUF_POLY_MAP_SIZE (4 MB) nkeynes@653: nkeynes@653: /*************************************************************************/ nkeynes@653: nkeynes@653: /* Scene data - this structure holds all the intermediate data used during nkeynes@653: * the rendering process. nkeynes@653: * nkeynes@653: * Special note: if vbo_supported == FALSE, then vertex_array points to a nkeynes@653: * malloced chunk of system RAM. Otherwise, vertex_array will be either NULL nkeynes@653: * (if the VBO is unmapped), or a pointer into a chunk of GL managed RAM nkeynes@653: * (possibly direct-mapped VRAM). nkeynes@653: */ nkeynes@653: struct pvr2_scene_struct { nkeynes@653: /** GL ID of the VBO used by the scene (or 0 if VBOs are not in use). */ nkeynes@653: GLuint vbo_id; nkeynes@653: /** Pointer to the vertex array data, or NULL for unmapped VBOs */ nkeynes@653: struct vertex_struct *vertex_array; nkeynes@653: /** Current allocated size (in bytes) of the vertex array */ nkeynes@653: uint32_t vertex_array_size; nkeynes@653: /** Total number of vertexes in the scene (note modified vertexes nkeynes@653: * count for 2 vertexes */ nkeynes@653: uint32_t vertex_count; nkeynes@653: nkeynes@653: /** Pointer to the polygon data for the scene (main ram). nkeynes@653: * This will always have room for at least MAX_POLYGONS */ nkeynes@653: struct polygon_struct *poly_array; nkeynes@653: /** Total number of polygons in the scene */ nkeynes@653: uint32_t poly_count; nkeynes@653: nkeynes@653: /** Image bounds in 3D - x1,x2,y1,y2,z1,z2 nkeynes@653: * x and y values are determined by the clip planes, while z values are nkeynes@653: * determined from the vertex data itself. nkeynes@653: */ nkeynes@653: float bounds[6]; nkeynes@653: nkeynes@653: /* Total size of the image buffer, determined by the tile map used to nkeynes@653: * render the scene */ nkeynes@653: uint32_t buffer_width, buffer_height; nkeynes@653: nkeynes@653: /** True if modifier volumes use the two-parameter form, False if they nkeynes@653: * use the cheap-shadow option. nkeynes@653: */ nkeynes@653: gboolean full_shadow; nkeynes@653: /** Specifies the translucency auto-sort mode for the scene */ nkeynes@653: tile_sort_mode_t sort_mode; nkeynes@653: nkeynes@653: /** Pointer to the start of the tile segment list in PVR2 VRAM (32-bit) */ nkeynes@653: struct tile_segment *segment_list; nkeynes@653: /** Map from PVR2 polygon address to an element of poly_array. */ nkeynes@653: struct polygon_struct **buf_to_poly_map; nkeynes@653: /** Pointer to the start of the raw polygon buffer in PVR2 VRAM (32-bit). nkeynes@653: * Also only used during parsing */ nkeynes@653: uint32_t *pvr2_pbuf; nkeynes@653: /** Current vertex index during parsing */ nkeynes@653: uint32_t vertex_index; nkeynes@653: }; nkeynes@653: nkeynes@653: /** nkeynes@653: * Current scene structure. Note this should only be written to by vertex bufer nkeynes@653: * functions nkeynes@653: */ nkeynes@653: extern struct pvr2_scene_struct pvr2_scene; nkeynes@653: nkeynes@653: nkeynes@653: #endif /* !lxdream_render_H */