Search
lxdream.org :: lxdream/src/pvr2/scene.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/scene.h
changeset 1159:580436b01b6c
prev1153:00e507e4025c
author nkeynes
date Mon Mar 05 15:00:14 2012 +1000 (12 years ago)
permissions -rw-r--r--
last change Revert to using GL_QUADS when available, fallback to fan-strip when it's not
(GLES)
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * PVR2 scene description structure (pvr2-private)
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #ifndef lxdream_scene_H
    20 #define lxdream_scene_H 1
    22 #ifdef __cplusplus
    23 extern "C" {
    24 #endif
    26 /************************* Intermediate vertex buffer ************************/
    28 typedef enum { 
    29     SORT_NEVER = 0, 
    30     SORT_TILEFLAG = 1, /* In this mode, sorting is controlled by the per-segment flag */
    31     SORT_ALWAYS = 2 
    32 } tile_sort_mode_t;
    34 typedef enum { SHADOW_NONE=0, SHADOW_CHEAP=1, SHADOW_FULL=2 } shadow_mode_t;
    37 struct vertex_struct {
    38     float u,v,r,tex_mode; /* tex-coord quad */
    39     float x,y,z,w;
    40     float rgba[4];
    41     float offset_rgba[4];
    42 };
    44 struct polygon_struct {
    45     uint32_t *context;
    46     uint32_t vertex_count; // number of vertexes in polygon
    47     uint32_t tex_id;
    48     int32_t vertex_index; // index of first vertex in vertex buffer
    49     uint32_t mod_tex_id;
    50     int32_t mod_vertex_index; // index of first modified vertex in vertex buffer
    51     struct polygon_struct *next; // chain for tri/quad arrays
    52     struct polygon_struct *sub_next; // chain for internal sub-polygons
    53 };
    55 void pvr2_scene_init(void);
    56 void pvr2_scene_read(void);
    57 void pvr2_scene_finished(void);
    58 void pvr2_scene_shutdown();
    60 uint32_t pvr2_scene_buffer_width();
    61 uint32_t pvr2_scene_buffer_height();
    63 extern unsigned char *video_base;
    65 /**
    66  * Maximum possible size of the vertex buffer. This is figured as follows:
    67  * PVR2 polygon buffer is limited to 4MB. The tightest polygon format 
    68  * is 3 vertexes in 48 bytes = 16 bytes/vertex, (shadow triangle) 
    69  * (the next tightest is 8 vertex in 140 bytes (6-strip colour-only)).
    70  * giving a theoretical maximum of 262144 vertexes.
    71  * The expanded structure is 44 bytes/vertex, giving 
    72  * 11534336 bytes...
    73  */
    74 #define MAX_VERTEXES 262144
    75 #define MAX_VERTEX_BUFFER_SIZE (MAX_VERTEXES*sizeof(struct vertex_struct))
    76 #define MIN_VERTEX_BUFFER_SIZE (2024*1024)
    78 /**
    79  * Maximum polygons - smallest is 1 polygon in 48 bytes, giving
    80  * 87381, plus 1 for the background. Allow the same amount again
    81  * for split polygons (worst case)
    82  * 
    83  */
    84 #define MAX_POLYGONS (87382*2)
    85 #define MAX_POLY_BUFFER_SIZE (MAX_POLYGONS*sizeof(struct polygon_struct))
    86 #define BUF_POLY_MAP_SIZE (4 MB)
    88 /*************************************************************************/
    90 /* Scene data - this structure holds all the intermediate data used during
    91  * the rendering process. 
    92  *
    93  * Special note: if vbo_supported == FALSE, then vertex_array points to a
    94  * malloced chunk of system RAM. Otherwise, vertex_array will be either NULL
    95  * (if the VBO is unmapped), or a pointer into a chunk of GL managed RAM
    96  * (possibly direct-mapped VRAM).
    97  */
    98 struct pvr2_scene_struct {
    99     /** GL ID of the VBO used by the scene (or 0 if VBOs are not in use). */
   100     GLuint vbo_id;
   101     /** Pointer to the vertex array data, or NULL for unmapped VBOs */
   102     struct vertex_struct *vertex_array;
   103     /** Current allocated size (in bytes) of the vertex array */
   104     uint32_t vertex_array_size;
   105     /** Total number of vertexes in the scene (note modified vertexes
   106      * count for 2 vertexes */
   107     uint32_t vertex_count;
   109     /** Pointer to the polygon data for the scene (main ram). 
   110      * This will always have room for at least MAX_POLYGONS */
   111     struct polygon_struct *poly_array;
   112     /** Pointer to the background polygon. This is always a quad, and
   113      * normally the last member of poly_array */
   114     struct polygon_struct *bkgnd_poly;
   115     /** Total number of polygons in the scene */
   116     uint32_t poly_count;
   118     /** Image bounds in 3D - x1,x2,y1,y2,z1,z2 
   119      * x and y values are determined by the clip planes, while z values are
   120      * determined from the vertex data itself.
   121      */
   122     float bounds[6];
   124     /* Total size of the image buffer, determined by the tile map used to
   125      * render the scene */
   126     uint32_t buffer_width, buffer_height;
   128     /** Specifies the translucency auto-sort mode for the scene */
   129     tile_sort_mode_t sort_mode;
   131     shadow_mode_t shadow_mode;
   133     float fog_lut_colour[4];
   134     float fog_vert_colour[4];
   136     /** Pointer to the start of the tile segment list in PVR2 VRAM (32-bit) */
   137     struct tile_segment *segment_list;
   138     /** Map from PVR2 polygon address to an element of poly_array. */
   139     struct polygon_struct **buf_to_poly_map;
   140     /** Pointer to the start of the raw polygon buffer in PVR2 VRAM (32-bit).
   141      * Also only used during parsing */
   142     uint32_t *pvr2_pbuf;
   143     /** Current vertex index during parsing */
   144     uint32_t vertex_index;
   145 };
   147 /**
   148  * Current scene structure. Note this should only be written to by vertex bufer
   149  * functions
   150  */
   151 extern struct pvr2_scene_struct pvr2_scene;
   153 #ifdef __cplusplus
   154 }
   155 #endif
   157 #endif /* !lxdream_scene_H */
.