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 Tue Mar 20 08:29:38 2012 +1000 (12 years ago)
permissions -rw-r--r--
last change More android WIP
- Implement onPause/onResume (although resume is not actually working yet)
- Implement BGRA => RGBA texture conversion (BGRA doesn't seem to work on the TFP)

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