/* * Copyright (c) 2012-2013 Etnaviv Project * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sub license, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ /* Rotating, animated cube. * Adapted to work on gc600 (4 bit per tile, no supertiling) as well as gc800. */ #include #include #include #include #include #include #include #include #include #include #include "common.xml.h" #include "state.xml.h" #include "state_3d.xml.h" #include "cmdstream.xml.h" #include "write_bmp.h" #include "viv.h" #include "etna.h" #include "etna_state.h" #include "etna_rs.h" #include "etna_fb.h" #include "etna_bo.h" #include "etna_util.h" #include "esTransform.h" #define VERTEX_BUFFER_SIZE 0x60000 float vVertices[] = { // front -1.0f, -1.0f, +1.0f, // point blue +1.0f, -1.0f, +1.0f, // point magenta -1.0f, +1.0f, +1.0f, // point cyan +1.0f, +1.0f, +1.0f, // point white // back +1.0f, -1.0f, -1.0f, // point red -1.0f, -1.0f, -1.0f, // point black +1.0f, +1.0f, -1.0f, // point yellow -1.0f, +1.0f, -1.0f, // point green // right +1.0f, -1.0f, +1.0f, // point magenta +1.0f, -1.0f, -1.0f, // point red +1.0f, +1.0f, +1.0f, // point white +1.0f, +1.0f, -1.0f, // point yellow // left -1.0f, -1.0f, -1.0f, // point black -1.0f, -1.0f, +1.0f, // point blue -1.0f, +1.0f, -1.0f, // point green -1.0f, +1.0f, +1.0f, // point cyan // top -1.0f, +1.0f, +1.0f, // point cyan +1.0f, +1.0f, +1.0f, // point white -1.0f, +1.0f, -1.0f, // point green +1.0f, +1.0f, -1.0f, // point yellow // bottom -1.0f, -1.0f, -1.0f, // point black +1.0f, -1.0f, -1.0f, // point red -1.0f, -1.0f, +1.0f, // point blue +1.0f, -1.0f, +1.0f // point magenta }; float vColors[] = { // front 0.0f, 0.0f, 1.0f, // blue 1.0f, 0.0f, 1.0f, // magenta 0.0f, 1.0f, 1.0f, // cyan 1.0f, 1.0f, 1.0f, // white // back 1.0f, 0.0f, 0.0f, // red 0.0f, 0.0f, 0.0f, // black 1.0f, 1.0f, 0.0f, // yellow 0.0f, 1.0f, 0.0f, // green // right 1.0f, 0.0f, 1.0f, // magenta 1.0f, 0.0f, 0.0f, // red 1.0f, 1.0f, 1.0f, // white 1.0f, 1.0f, 0.0f, // yellow // left 0.0f, 0.0f, 0.0f, // black 0.0f, 0.0f, 1.0f, // blue 0.0f, 1.0f, 0.0f, // green 0.0f, 1.0f, 1.0f, // cyan // top 0.0f, 1.0f, 1.0f, // cyan 1.0f, 1.0f, 1.0f, // white 0.0f, 1.0f, 0.0f, // green 1.0f, 1.0f, 0.0f, // yellow // bottom 0.0f, 0.0f, 0.0f, // black 1.0f, 0.0f, 0.0f, // red 0.0f, 0.0f, 1.0f, // blue 1.0f, 0.0f, 1.0f // magenta }; float vNormals[] = { // front +0.0f, +0.0f, +1.0f, // forward +0.0f, +0.0f, +1.0f, // forward +0.0f, +0.0f, +1.0f, // forward +0.0f, +0.0f, +1.0f, // forward // back +0.0f, +0.0f, -1.0f, // backbard +0.0f, +0.0f, -1.0f, // backbard +0.0f, +0.0f, -1.0f, // backbard +0.0f, +0.0f, -1.0f, // backbard // right +1.0f, +0.0f, +0.0f, // right +1.0f, +0.0f, +0.0f, // right +1.0f, +0.0f, +0.0f, // right +1.0f, +0.0f, +0.0f, // right // left -1.0f, +0.0f, +0.0f, // left -1.0f, +0.0f, +0.0f, // left -1.0f, +0.0f, +0.0f, // left -1.0f, +0.0f, +0.0f, // left // top +0.0f, +1.0f, +0.0f, // up +0.0f, +1.0f, +0.0f, // up +0.0f, +1.0f, +0.0f, // up +0.0f, +1.0f, +0.0f, // up // bottom +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f, // down +0.0f, -1.0f, +0.0f // down }; #define COMPONENTS_PER_VERTEX (3) #define NUM_VERTICES (6*4) uint32_t vs[] = { 0x01831009, 0x00000000, 0x00000000, 0x203fc048, 0x02031009, 0x00000000, 0x00000000, 0x203fc058, 0x07841003, 0x39000800, 0x00000050, 0x00000000, 0x07841002, 0x39001800, 0x00aa0050, 0x00390048, 0x07841002, 0x39002800, 0x01540050, 0x00390048, 0x07841002, 0x39003800, 0x01fe0050, 0x00390048, 0x03851003, 0x29004800, 0x000000d0, 0x00000000, 0x03851002, 0x29005800, 0x00aa00d0, 0x00290058, 0x03811002, 0x29006800, 0x015400d0, 0x00290058, 0x07851003, 0x39007800, 0x00000050, 0x00000000, 0x07851002, 0x39008800, 0x00aa0050, 0x00390058, 0x07851002, 0x39009800, 0x01540050, 0x00390058, 0x07801002, 0x3900a800, 0x01fe0050, 0x00390058, 0x0401100c, 0x00000000, 0x00000000, 0x003fc008, 0x03801002, 0x69000800, 0x01fe00c0, 0x00290038, 0x03831005, 0x29000800, 0x01480040, 0x00000000, 0x0383100d, 0x00000000, 0x00000000, 0x00000038, 0x03801003, 0x29000800, 0x014801c0, 0x00000000, 0x00801005, 0x29001800, 0x01480040, 0x00000000, 0x0080108f, 0x3fc06800, 0x00000050, 0x203fc068, 0x03801003, 0x00000800, 0x01480140, 0x00000000, 0x04001009, 0x00000000, 0x00000000, 0x200000b8, 0x02041001, 0x2a804800, 0x00000000, 0x003fc048, 0x02041003, 0x2a804800, 0x00aa05c0, 0x00000002, }; uint32_t ps[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; size_t vs_size = sizeof(vs); size_t ps_size = sizeof(ps); int main(int argc, char **argv) { int rv; int width = 256; int height = 256; int padded_width, padded_height; int backbuffer = 0; struct fb_info fb; rv = fb_open(0, &fb); if(rv!=0) { exit(1); } width = fb.fb_var.xres; height = fb.fb_var.yres; padded_width = etna_align_up(width, 64); padded_height = etna_align_up(height, 64); printf("padded_width %i padded_height %i\n", padded_width, padded_height); struct viv_conn *conn = 0; rv = viv_open(VIV_HW_3D, &conn); if(rv!=0) { fprintf(stderr, "Error opening device\n"); exit(1); } printf("Succesfully opened device\n"); bool supertiled = VIV_FEATURE(conn, chipMinorFeatures0,SUPER_TILED); unsigned bits_per_tile = VIV_FEATURE(conn, chipMinorFeatures0,2BITPERTILE)?2:4; printf("supertiled: %i bits per tile: %i\n", supertiled, bits_per_tile); struct etna_bo *rt = 0; /* main render target */ struct etna_bo *rt_ts = 0; /* tile status for main render target */ struct etna_bo *z = 0; /* depth for main render target */ struct etna_bo *z_ts = 0; /* depth ts for main render target */ struct etna_bo *vtx = 0; /* vertex buffer */ struct etna_bo *aux_rt = 0; /* auxilary render target */ struct etna_bo *aux_rt_ts = 0; /* tile status for auxilary render target */ struct etna_bo *bmp = 0; /* bitmap */ size_t rt_size = padded_width * padded_height * 4; size_t rt_ts_size = etna_align_up((padded_width * padded_height * 4)*bits_per_tile/0x80, 0x100); size_t z_size = padded_width * padded_height * 2; size_t z_ts_size = etna_align_up((padded_width * padded_height * 2)*bits_per_tile/0x80, 0x100); size_t bmp_size = width * height * 4; if(etna_bo_new(conn, &rt, rt_size, gcvSURF_RENDER_TARGET, gcvPOOL_DEFAULT, true)!=ETNA_OK || etna_bo_new(conn, &rt_ts, rt_ts_size, gcvSURF_TILE_STATUS, gcvPOOL_DEFAULT, true)!=ETNA_OK || etna_bo_new(conn, &z, z_size, gcvSURF_DEPTH, gcvPOOL_DEFAULT, true)!=ETNA_OK || etna_bo_new(conn, &z_ts, z_ts_size, gcvSURF_TILE_STATUS, gcvPOOL_DEFAULT, true)!=ETNA_OK || etna_bo_new(conn, &vtx, VERTEX_BUFFER_SIZE, gcvSURF_VERTEX, gcvPOOL_DEFAULT, true)!=ETNA_OK || etna_bo_new(conn, &aux_rt, 0x4000, gcvSURF_RENDER_TARGET, gcvPOOL_SYSTEM, true)!=ETNA_OK || etna_bo_new(conn, &aux_rt_ts, 0x80*bits_per_tile, gcvSURF_TILE_STATUS, gcvPOOL_DEFAULT, true)!=ETNA_OK || etna_bo_new(conn, &bmp, bmp_size, gcvSURF_BITMAP, gcvPOOL_DEFAULT, true)!=ETNA_OK ) { fprintf(stderr, "Error allocating video memory\n"); exit(1); } /* Phew, now we got all the memory we need. * Write interleaved attribute vertex stream. * Unlike the GL example we only do this once, not every time glDrawArrays is called, the same would be accomplished * from GL by using a vertex buffer object. */ float *vtx_map = (float*)etna_bo_map(vtx); for(int vert=0; vert