Search
lxdream.org :: lxdream/src/pvr2/scene.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/scene.h
changeset 639:162ee7614b60
prev636:2ccf94f966fc
next645:a7392098299c
author nkeynes
date Mon Feb 18 09:21:43 2008 +0000 (12 years ago)
branchlxdream-render
permissions -rw-r--r--
last change More render WIP - initial glrender.c
file annotate diff log raw
nkeynes@635
     1
/**
nkeynes@636
     2
 * $Id$
nkeynes@635
     3
 *
nkeynes@635
     4
 * PVR2 rendering functions (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@635
    19
#ifndef lxdream_render_H
nkeynes@635
    20
#define lxdream_render_H 1
nkeynes@635
    21
nkeynes@635
    22
/************************* Intermediate vertex buffer ************************/
nkeynes@635
    23
nkeynes@635
    24
typedef enum { 
nkeynes@635
    25
    SORT_NEVER = 0, 
nkeynes@635
    26
    SORT_BYFLAG = 1, /* In this mode, sorting is controlled by the per-segment flag */
nkeynes@635
    27
    SORT_ALWAYS = 2 
nkeynes@635
    28
} tile_sort_mode_t;
nkeynes@635
    29
nkeynes@635
    30
struct vertex_struct {
nkeynes@635
    31
    float u,v;
nkeynes@635
    32
    uint32_t rgba;
nkeynes@639
    33
    float x,y,z;
nkeynes@635
    34
    uint32_t offset_rgba;
nkeynes@635
    35
};
nkeynes@635
    36
nkeynes@635
    37
struct polygon_struct {
nkeynes@635
    38
    uint32_t *context;
nkeynes@635
    39
    int cull;             // culling mode
nkeynes@635
    40
    uint32_t vertex_count; // number of vertexes in polygon
nkeynes@635
    41
    int32_t vertex_index; // index of first vertex in vertex buffer
nkeynes@635
    42
    int32_t mod_vertex_index; // index of first modified vertex in vertex buffer
nkeynes@635
    43
    float center_z;
nkeynes@635
    44
    struct polygon_struct *next; // chain for tri/quad arrays
nkeynes@635
    45
};
nkeynes@635
    46
nkeynes@635
    47
void pvr2_scene_init(void);
nkeynes@635
    48
void pvr2_scene_read(void);
nkeynes@635
    49
void pvr2_scene_shutdown();
nkeynes@635
    50
nkeynes@635
    51
extern char *video_base;
nkeynes@635
    52
nkeynes@635
    53
/**
nkeynes@635
    54
 * Maximum possible size of the vertex buffer. This is figured as follows:
nkeynes@635
    55
 * PVR2 polygon buffer is limited to 4MB. The tightest polygon format 
nkeynes@635
    56
 * is 3 vertexes in 48 bytes = 16 bytes/vertex, (shadow triangle) 
nkeynes@635
    57
 * (the next tightest is 8 vertex in 140 bytes (6-strip colour-only)).
nkeynes@635
    58
 * giving a theoretical maximum of 262144 vertexes.
nkeynes@635
    59
 * The expanded structure is 44 bytes/vertex, giving 
nkeynes@635
    60
 * 11534336 bytes...
nkeynes@635
    61
 */
nkeynes@635
    62
#define MAX_VERTEXES 262144
nkeynes@635
    63
#define MAX_VERTEX_BUFFER_SIZE (MAX_VERTEXES*sizeof(struct vertex_struct))
nkeynes@635
    64
nkeynes@635
    65
/**
nkeynes@635
    66
 * Maximum polygons - smallest is 1 polygon in 48 bytes, giving
nkeynes@635
    67
 * 87381
nkeynes@635
    68
 * 
nkeynes@635
    69
 */
nkeynes@635
    70
#define MAX_POLYGONS 87382
nkeynes@635
    71
#define MAX_POLY_BUFFER_SIZE (MAX_POLYGONS*sizeof(struct polygon_struct))
nkeynes@635
    72
#define BUF_POLY_MAP_SIZE (4 MB)
nkeynes@635
    73
nkeynes@635
    74
/*************************************************************************/
nkeynes@635
    75
nkeynes@635
    76
/* Scene data - this structure holds all the intermediate data used during
nkeynes@635
    77
 * the rendering process. 
nkeynes@635
    78
 *
nkeynes@635
    79
 * Special note: if vbo_supported == FALSE, then vertex_array points to a
nkeynes@635
    80
 * malloced chunk of system RAM. Otherwise, vertex_array will be either NULL
nkeynes@635
    81
 * (if the VBO is unmapped), or a pointer into a chunk of GL managed RAM
nkeynes@635
    82
 * (possibly direct-mapped VRAM).
nkeynes@635
    83
 */
nkeynes@635
    84
struct pvr2_scene_struct {
nkeynes@635
    85
    /** GL ID of the VBO used by the scene (or 0 if VBOs are not in use). */
nkeynes@635
    86
    GLuint vbo_id;
nkeynes@635
    87
    /** Pointer to the vertex array data, or NULL for unmapped VBOs */
nkeynes@635
    88
    struct vertex_struct *vertex_array;
nkeynes@635
    89
    /** Current allocated size (in bytes) of the vertex array */
nkeynes@635
    90
    uint32_t vertex_array_size;
nkeynes@635
    91
    /** Total number of vertexes in the scene (note modified vertexes
nkeynes@635
    92
     * count for 2 vertexes */
nkeynes@635
    93
    uint32_t vertex_count;
nkeynes@635
    94
nkeynes@635
    95
    /** Pointer to the polygon data for the scene (main ram). 
nkeynes@635
    96
     * This will always have room for at least MAX_POLYGONS */
nkeynes@635
    97
    struct polygon_struct *poly_array;
nkeynes@635
    98
    /** Total number of polygons in the scene */
nkeynes@635
    99
    uint32_t poly_count;
nkeynes@635
   100
nkeynes@635
   101
    /** Image bounds in 3D - x1,x2,y1,y2,z1,z2 
nkeynes@635
   102
     * x and y values are determined by the clip planes, while z values are
nkeynes@635
   103
     * determined from the vertex data itself.
nkeynes@635
   104
     */
nkeynes@635
   105
    float bounds[6];
nkeynes@635
   106
nkeynes@635
   107
    /* Total size of the image buffer, determined by the tile map used to
nkeynes@635
   108
     * render the scene */
nkeynes@635
   109
    uint32_t buffer_width, buffer_height;
nkeynes@635
   110
nkeynes@635
   111
    /** True if modifier volumes use the two-parameter form, False if they
nkeynes@635
   112
     * use the cheap-shadow option.
nkeynes@635
   113
     */
nkeynes@635
   114
    gboolean full_shadow;
nkeynes@635
   115
    /** Specifies the translucency auto-sort mode for the scene */
nkeynes@635
   116
    tile_sort_mode_t sort_mode;
nkeynes@635
   117
nkeynes@635
   118
    /** Pointer to the start of the tile segment list in PVR2 VRAM (32-bit) */
nkeynes@635
   119
    struct tile_segment *segment_list;
nkeynes@639
   120
    /** Map from PVR2 polygon address to an element of poly_array. */
nkeynes@635
   121
    struct polygon_struct **buf_to_poly_map;
nkeynes@635
   122
    /** Pointer to the start of the raw polygon buffer in PVR2 VRAM (32-bit).
nkeynes@635
   123
     * Also only used during parsing */
nkeynes@635
   124
    uint32_t *pvr2_pbuf;
nkeynes@635
   125
    /** Current vertex index during parsing */
nkeynes@635
   126
    uint32_t vertex_index;
nkeynes@635
   127
};
nkeynes@635
   128
nkeynes@635
   129
/**
nkeynes@635
   130
 * Current scene structure. Note this should only be written to by vertex bufer
nkeynes@635
   131
 * functions
nkeynes@635
   132
 */
nkeynes@635
   133
extern struct pvr2_scene_struct pvr2_scene;
nkeynes@635
   134
nkeynes@635
   135
nkeynes@635
   136
#endif /* !lxdream_render_H */
.