static void set_vertex_shader( void ) { void *handle; const char *text = "VERT\n" "DCL IN[0]\n" "DCL IN[1]\n" "DCL OUT[0], POSITION\n" "DCL OUT[1], COLOR\n" " 0: MOV OUT[1], IN[1]\n" " 1: MOV OUT[0], IN[0]\n" " 2: END\n"; handle = graw_parse_vertex_shader(ctx, text); ctx->bind_vs_state(ctx, handle); }
static void set_vertex_shader( void ) { void *handle; const char *text = "VERT\n" "DCL IN[0]\n" "DCL IN[1]\n" "DCL IN[2]\n" "DCL IN[3]\n" "DCL OUT[0], POSITION\n" "DCL OUT[1], COLOR[0]\n" "DCL OUT[2], GENERIC[0]\n" "DCL OUT[3], GENERIC[1]\n" " MOV OUT[0], IN[0]\n" " MOV OUT[1], IN[1]\n" " MOV OUT[2], IN[2]\n" " MOV OUT[3], IN[3]\n" " END\n"; handle = graw_parse_vertex_shader(ctx, text); ctx->bind_vs_state(ctx, handle); }
static void set_vertex_shader( void ) { FILE *f; char buf[50000]; void *handle; int sz; if ((f = fopen(filename, "r")) == NULL) { fprintf(stderr, "Couldn't open %s\n", filename); exit(1); } sz = fread(buf, 1, sizeof(buf), f); if (!feof(f)) { printf("file too long\n"); exit(1); } printf("%.*s\n", sz, buf); buf[sz] = 0; handle = graw_parse_vertex_shader(ctx, buf); ctx->bind_vs_state(ctx, handle); fclose(f); }
}); pipe->set_scissor_state(pipe, &(struct pipe_scissor_state){ .minx = 0, .miny = 0, .maxx = 65535, .maxy = 65535 }); pipe->set_viewport_state(pipe, &(struct pipe_viewport_state){ .scale = {width/2.0f, height/2.0f, 0.5f, 1.0f}, .translate = {width/2.0f, height/2.0f, 0.5f, 1.0f} }); pipe->set_fragment_sampler_views(pipe, 1, &sampler_view); pipe->set_vertex_buffers(pipe, 0, 1, &vertex_buffer_desc); pipe->set_index_buffer(pipe, NULL); void *vtx_shader = graw_parse_vertex_shader(pipe, particle_system_vert); void *frag_shader = graw_parse_fragment_shader(pipe, particle_system_frag); pipe->bind_vs_state(pipe, vtx_shader); pipe->bind_fs_state(pipe, frag_shader); /* Fill in particle data array */ struct pipe_transfer *vtx_transfer = 0; float *vtx_logical = pipe_buffer_map(pipe, vtx_resource, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_UNSYNCHRONIZED, &vtx_transfer); srand(0); for(int i = 0; i < NUM_PARTICLES; i++) { float *particleData = &vtx_logical[i * PARTICLE_SIZE]; // Lifetime of particle (*particleData++) = ( (float)(rand() % 10000) / 10000.0f );
}); pipe->set_scissor_states(pipe, 0, 1, &(struct pipe_scissor_state){ .minx = 0, .miny = 0, .maxx = 65535, .maxy = 65535 }); pipe->set_viewport_states(pipe, 0, 1, &(struct pipe_viewport_state){ .scale = {width/2.0f, height/2.0f, 0.5f, 1.0f}, .translate = {width/2.0f, height/2.0f, 0.5f, 1.0f} }); pipe->set_vertex_buffers(pipe, 0, 1, &vertex_buf_desc); pipe->set_index_buffer(pipe, &index_buf_desc); void *vtx_shader = graw_parse_vertex_shader(pipe, stencil_test_vert); void *frag_shader = graw_parse_fragment_shader(pipe, stencil_test_frag); pipe->bind_vs_state(pipe, vtx_shader); pipe->bind_fs_state(pipe, frag_shader); /* create depth stencil alpha states for the different test phases. * except the stencil_ref, which is set separately */ void *dsa_test0 = pipe->create_depth_stencil_alpha_state(pipe, &(struct pipe_depth_stencil_alpha_state){ .depth = { .enabled = 1, .writemask = 1, .func = PIPE_FUNC_LESS /* GL default */ }, .stencil[0] = { /* single-sided stencil */ .enabled = 1,
.maxy = 65535 }); pipe->set_viewport_states(pipe, 0, 1, &(struct pipe_viewport_state) { .scale = {width/2.0f, height/2.0f, 0.5f, 1.0f}, .translate = {width/2.0f, height/2.0f, 0.5f, 1.0f} }); pipe->set_vertex_buffers(pipe, 0, 1, &vertex_buf_desc); pipe->set_index_buffer(pipe, NULL);/*&(struct pipe_index_buffer){ .index_size = 0, .offset = 0, .buffer = 0, .user_buffer = 0 });*/ /* non-indexed rendering */ void *vtx_shader = graw_parse_vertex_shader(pipe, alpha_blend_vert); void *frag_shader = graw_parse_fragment_shader(pipe, alpha_blend_frag); pipe->bind_vs_state(pipe, vtx_shader); pipe->bind_fs_state(pipe, frag_shader); for(int frame=0; frame<1000; ++frame) { if(frame%50 == 0) printf("*** FRAME %i ****\n", frame); /* Compute transform matrices in the same way as cube egl demo */ ESMatrix projection; float aspect = (float)(height) / (float)(width); esMatrixLoadIdentity(&projection); esFrustum(&projection, -1.8f, +1.8f, -1.8f * aspect, +1.8f * aspect, 5.0f, 10.0f);
.zsbuf = zsbuf }); pipe->set_scissor_states(pipe, 0, 1, &(struct pipe_scissor_state){ .minx = 0, .miny = 0, .maxx = 65535, .maxy = 65535 }); pipe->set_viewport_states(pipe, 0, 1, &(struct pipe_viewport_state){ .scale = {width/2.0f, height/2.0f, 0.5f, 1.0f}, .translate = {width/2.0f, height/2.0f, 0.5f, 1.0f} }); pipe->set_vertex_buffers(pipe, 0, 1, &vertex_buffer_desc); pipe->set_index_buffer(pipe, NULL); void *vtx_shader = graw_parse_vertex_shader(pipe, cube_vert); void *frag_shader = graw_parse_fragment_shader(pipe, cube_frag); pipe->bind_vs_state(pipe, vtx_shader); pipe->bind_fs_state(pipe, frag_shader); for(int frame=0; frame<1000; ++frame) { float vs_const[12*4]; if(frame%50 == 0) printf("*** FRAME %i ****\n", frame); /* Compute transform matrices in the same way as cube egl demo */ ESMatrix modelview, projection, modelviewprojection; ESMatrix inverse, normal; esMatrixLoadIdentity(&modelview); esTranslate(&modelview, 0.0f, 0.0f, -8.0f); esRotate(&modelview, 45.0f, 1.0f, 0.0f, 0.0f);