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