nkeynes@635: /** nkeynes@636: * $Id$ nkeynes@635: * nkeynes@736: * PVR2 scene description structure (pvr2-private) nkeynes@635: * nkeynes@635: * Copyright (c) 2005 Nathan Keynes. nkeynes@635: * nkeynes@635: * This program is free software; you can redistribute it and/or modify nkeynes@635: * it under the terms of the GNU General Public License as published by nkeynes@635: * the Free Software Foundation; either version 2 of the License, or nkeynes@635: * (at your option) any later version. nkeynes@635: * nkeynes@635: * This program is distributed in the hope that it will be useful, nkeynes@635: * but WITHOUT ANY WARRANTY; without even the implied warranty of nkeynes@635: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nkeynes@635: * GNU General Public License for more details. nkeynes@635: */ nkeynes@635: nkeynes@736: #ifndef lxdream_scene_H nkeynes@736: #define lxdream_scene_H 1 nkeynes@736: nkeynes@736: #ifdef __cplusplus nkeynes@736: extern "C" { nkeynes@736: #endif nkeynes@635: nkeynes@635: /************************* Intermediate vertex buffer ************************/ nkeynes@635: nkeynes@635: typedef enum { nkeynes@635: SORT_NEVER = 0, nkeynes@645: SORT_TILEFLAG = 1, /* In this mode, sorting is controlled by the per-segment flag */ nkeynes@635: SORT_ALWAYS = 2 nkeynes@635: } tile_sort_mode_t; nkeynes@635: nkeynes@863: typedef enum { SHADOW_NONE=0, SHADOW_CHEAP=1, SHADOW_FULL=2 } shadow_mode_t; nkeynes@863: nkeynes@863: nkeynes@635: struct vertex_struct { nkeynes@1140: float u,v,r,tex_mode; /* tex-coord quad */ nkeynes@639: float x,y,z; nkeynes@687: float rgba[4]; nkeynes@687: float offset_rgba[4]; nkeynes@635: }; nkeynes@635: nkeynes@635: struct polygon_struct { nkeynes@635: uint32_t *context; nkeynes@635: uint32_t vertex_count; // number of vertexes in polygon nkeynes@645: uint32_t tex_id; nkeynes@635: int32_t vertex_index; // index of first vertex in vertex buffer nkeynes@645: uint32_t mod_tex_id; nkeynes@635: int32_t mod_vertex_index; // index of first modified vertex in vertex buffer nkeynes@635: struct polygon_struct *next; // chain for tri/quad arrays nkeynes@1133: struct polygon_struct *sub_next; // chain for internal sub-polygons nkeynes@635: }; nkeynes@635: nkeynes@635: void pvr2_scene_init(void); nkeynes@635: void pvr2_scene_read(void); nkeynes@635: void pvr2_scene_shutdown(); nkeynes@635: 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@635: nkeynes@635: /** nkeynes@635: * Maximum possible size of the vertex buffer. This is figured as follows: nkeynes@635: * PVR2 polygon buffer is limited to 4MB. The tightest polygon format nkeynes@635: * is 3 vertexes in 48 bytes = 16 bytes/vertex, (shadow triangle) nkeynes@635: * (the next tightest is 8 vertex in 140 bytes (6-strip colour-only)). nkeynes@635: * giving a theoretical maximum of 262144 vertexes. nkeynes@635: * The expanded structure is 44 bytes/vertex, giving nkeynes@635: * 11534336 bytes... nkeynes@635: */ nkeynes@635: #define MAX_VERTEXES 262144 nkeynes@635: #define MAX_VERTEX_BUFFER_SIZE (MAX_VERTEXES*sizeof(struct vertex_struct)) nkeynes@635: nkeynes@635: /** nkeynes@635: * Maximum polygons - smallest is 1 polygon in 48 bytes, giving nkeynes@1133: * 87381, plus 1 for the background. Allow the same amount again nkeynes@1133: * for split polygons (worst case) nkeynes@635: * nkeynes@635: */ nkeynes@1133: #define MAX_POLYGONS (87382*2) nkeynes@635: #define MAX_POLY_BUFFER_SIZE (MAX_POLYGONS*sizeof(struct polygon_struct)) nkeynes@635: #define BUF_POLY_MAP_SIZE (4 MB) nkeynes@1151: #define POLY_NO(poly) (poly - pvr2_scene.poly_array) nkeynes@635: nkeynes@635: /*************************************************************************/ nkeynes@635: nkeynes@635: /* Scene data - this structure holds all the intermediate data used during nkeynes@635: * the rendering process. nkeynes@635: * nkeynes@635: * Special note: if vbo_supported == FALSE, then vertex_array points to a nkeynes@635: * malloced chunk of system RAM. Otherwise, vertex_array will be either NULL nkeynes@635: * (if the VBO is unmapped), or a pointer into a chunk of GL managed RAM nkeynes@635: * (possibly direct-mapped VRAM). nkeynes@635: */ nkeynes@635: struct pvr2_scene_struct { nkeynes@635: /** GL ID of the VBO used by the scene (or 0 if VBOs are not in use). */ nkeynes@635: GLuint vbo_id; nkeynes@635: /** Pointer to the vertex array data, or NULL for unmapped VBOs */ nkeynes@635: struct vertex_struct *vertex_array; nkeynes@635: /** Current allocated size (in bytes) of the vertex array */ nkeynes@635: uint32_t vertex_array_size; nkeynes@635: /** Total number of vertexes in the scene (note modified vertexes nkeynes@635: * count for 2 vertexes */ nkeynes@635: uint32_t vertex_count; nkeynes@635: nkeynes@635: /** Pointer to the polygon data for the scene (main ram). nkeynes@635: * This will always have room for at least MAX_POLYGONS */ nkeynes@635: struct polygon_struct *poly_array; nkeynes@687: /** Pointer to the background polygon. This is always a quad, and nkeynes@687: * normally the last member of poly_array */ nkeynes@687: struct polygon_struct *bkgnd_poly; nkeynes@635: /** Total number of polygons in the scene */ nkeynes@635: uint32_t poly_count; nkeynes@635: nkeynes@635: /** Image bounds in 3D - x1,x2,y1,y2,z1,z2 nkeynes@635: * x and y values are determined by the clip planes, while z values are nkeynes@635: * determined from the vertex data itself. nkeynes@635: */ nkeynes@635: float bounds[6]; nkeynes@635: nkeynes@635: /* Total size of the image buffer, determined by the tile map used to nkeynes@635: * render the scene */ nkeynes@635: uint32_t buffer_width, buffer_height; nkeynes@635: nkeynes@635: /** Specifies the translucency auto-sort mode for the scene */ nkeynes@635: tile_sort_mode_t sort_mode; nkeynes@863: nkeynes@863: shadow_mode_t shadow_mode; nkeynes@635: nkeynes@847: float fog_lut_colour[4]; nkeynes@847: float fog_vert_colour[4]; nkeynes@847: nkeynes@635: /** Pointer to the start of the tile segment list in PVR2 VRAM (32-bit) */ nkeynes@635: struct tile_segment *segment_list; nkeynes@639: /** Map from PVR2 polygon address to an element of poly_array. */ nkeynes@635: struct polygon_struct **buf_to_poly_map; nkeynes@635: /** Pointer to the start of the raw polygon buffer in PVR2 VRAM (32-bit). nkeynes@635: * Also only used during parsing */ nkeynes@635: uint32_t *pvr2_pbuf; nkeynes@635: /** Current vertex index during parsing */ nkeynes@635: uint32_t vertex_index; nkeynes@635: }; nkeynes@635: nkeynes@635: /** nkeynes@635: * Current scene structure. Note this should only be written to by vertex bufer nkeynes@635: * functions nkeynes@635: */ nkeynes@635: extern struct pvr2_scene_struct pvr2_scene; nkeynes@635: nkeynes@736: #ifdef __cplusplus nkeynes@736: } nkeynes@736: #endif nkeynes@635: nkeynes@736: #endif /* !lxdream_scene_H */