1bf215546Sopenharmony_ci/* Display a cleared blue window.  This demo has no dependencies on
2bf215546Sopenharmony_ci * any utility code, just the graw interface and gallium.
3bf215546Sopenharmony_ci */
4bf215546Sopenharmony_ci
5bf215546Sopenharmony_ci#include "frontend/graw.h"
6bf215546Sopenharmony_ci#include "pipe/p_screen.h"
7bf215546Sopenharmony_ci#include "pipe/p_context.h"
8bf215546Sopenharmony_ci#include "pipe/p_shader_tokens.h"
9bf215546Sopenharmony_ci#include "pipe/p_state.h"
10bf215546Sopenharmony_ci#include "pipe/p_defines.h"
11bf215546Sopenharmony_ci
12bf215546Sopenharmony_ci#include "util/u_debug.h"       /* debug_dump_surface_bmp() */
13bf215546Sopenharmony_ci#include "util/u_inlines.h"
14bf215546Sopenharmony_ci#include "util/u_memory.h"      /* Offset() */
15bf215546Sopenharmony_ci#include "util/u_draw_quad.h"
16bf215546Sopenharmony_ci#include "util/u_box.h"
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ci#include <stdio.h>
19bf215546Sopenharmony_ci
20bf215546Sopenharmony_cienum pipe_format formats[] = {
21bf215546Sopenharmony_ci   PIPE_FORMAT_RGBA8888_UNORM,
22bf215546Sopenharmony_ci   PIPE_FORMAT_BGRA8888_UNORM,
23bf215546Sopenharmony_ci   PIPE_FORMAT_NONE
24bf215546Sopenharmony_ci};
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_cistatic const int WIDTH = 300;
27bf215546Sopenharmony_cistatic const int HEIGHT = 300;
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_cistatic struct pipe_screen *screen = NULL;
30bf215546Sopenharmony_cistatic struct pipe_context *ctx = NULL;
31bf215546Sopenharmony_cistatic struct pipe_resource *rttex = NULL;
32bf215546Sopenharmony_cistatic struct pipe_resource *samptex = NULL;
33bf215546Sopenharmony_cistatic struct pipe_surface *surf = NULL;
34bf215546Sopenharmony_cistatic struct pipe_sampler_view *sv = NULL;
35bf215546Sopenharmony_cistatic void *sampler = NULL;
36bf215546Sopenharmony_cistatic void *window = NULL;
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistruct vertex {
39bf215546Sopenharmony_ci   float position[4];
40bf215546Sopenharmony_ci   float color[4];
41bf215546Sopenharmony_ci};
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_cistatic struct vertex vertices[] =
44bf215546Sopenharmony_ci{
45bf215546Sopenharmony_ci   { { 0.9, -0.9, 0.0, 1.0 },
46bf215546Sopenharmony_ci     { 1, 0, 0, 1 } },
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   { { 0.9,  0.9, 0.0, 1.0 },
49bf215546Sopenharmony_ci     { 1, 1, 0, 1 } },
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   { {-0.9,  0.9, 0.0, 1.0 },
52bf215546Sopenharmony_ci     { 0, 1, 0, 1 } },
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci   { {-0.9,  -0.9, 0.0, 1.0 },
55bf215546Sopenharmony_ci     { 0, 0, 0, 1 } },
56bf215546Sopenharmony_ci};
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistatic void set_viewport( float x, float y,
62bf215546Sopenharmony_ci                          float width, float height,
63bf215546Sopenharmony_ci                          float zNear, float zFar)
64bf215546Sopenharmony_ci{
65bf215546Sopenharmony_ci   float z = zFar;
66bf215546Sopenharmony_ci   float half_width = (float)width / 2.0f;
67bf215546Sopenharmony_ci   float half_height = (float)height / 2.0f;
68bf215546Sopenharmony_ci   float half_depth = ((float)zFar - (float)zNear) / 2.0f;
69bf215546Sopenharmony_ci   struct pipe_viewport_state vp;
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci   vp.scale[0] = half_width;
72bf215546Sopenharmony_ci   vp.scale[1] = half_height;
73bf215546Sopenharmony_ci   vp.scale[2] = half_depth;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   vp.translate[0] = half_width + x;
76bf215546Sopenharmony_ci   vp.translate[1] = half_height + y;
77bf215546Sopenharmony_ci   vp.translate[2] = half_depth + z;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
80bf215546Sopenharmony_ci   vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
81bf215546Sopenharmony_ci   vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
82bf215546Sopenharmony_ci   vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci   ctx->set_viewport_states( ctx, 0, 1, &vp );
85bf215546Sopenharmony_ci}
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_cistatic void set_vertices( void )
88bf215546Sopenharmony_ci{
89bf215546Sopenharmony_ci   struct pipe_vertex_element ve[2];
90bf215546Sopenharmony_ci   struct pipe_vertex_buffer vbuf;
91bf215546Sopenharmony_ci   void *handle;
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   memset(ve, 0, sizeof ve);
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   ve[0].src_offset = Offset(struct vertex, position);
96bf215546Sopenharmony_ci   ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
97bf215546Sopenharmony_ci   ve[1].src_offset = Offset(struct vertex, color);
98bf215546Sopenharmony_ci   ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci   handle = ctx->create_vertex_elements_state(ctx, 2, ve);
101bf215546Sopenharmony_ci   ctx->bind_vertex_elements_state(ctx, handle);
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci   memset(&vbuf, 0, sizeof vbuf);
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci   vbuf.stride = sizeof( struct vertex );
106bf215546Sopenharmony_ci   vbuf.buffer_offset = 0;
107bf215546Sopenharmony_ci   vbuf.buffer.resource = pipe_buffer_create_with_data(ctx,
108bf215546Sopenharmony_ci                                              PIPE_BIND_VERTEX_BUFFER,
109bf215546Sopenharmony_ci                                              PIPE_USAGE_DEFAULT,
110bf215546Sopenharmony_ci                                              sizeof(vertices),
111bf215546Sopenharmony_ci                                              vertices);
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci   ctx->set_vertex_buffers(ctx, 0, 1, 0, false, &vbuf);
114bf215546Sopenharmony_ci}
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_cistatic void set_vertex_shader( void )
117bf215546Sopenharmony_ci{
118bf215546Sopenharmony_ci   void *handle;
119bf215546Sopenharmony_ci   const char *text =
120bf215546Sopenharmony_ci      "VERT\n"
121bf215546Sopenharmony_ci      "DCL IN[0]\n"
122bf215546Sopenharmony_ci      "DCL IN[1]\n"
123bf215546Sopenharmony_ci      "DCL OUT[0], POSITION\n"
124bf215546Sopenharmony_ci      "DCL OUT[1], GENERIC[0]\n"
125bf215546Sopenharmony_ci      "  0: MOV OUT[1], IN[1]\n"
126bf215546Sopenharmony_ci      "  1: MOV OUT[0], IN[0]\n"
127bf215546Sopenharmony_ci      "  2: END\n";
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   handle = graw_parse_vertex_shader(ctx, text);
130bf215546Sopenharmony_ci   ctx->bind_vs_state(ctx, handle);
131bf215546Sopenharmony_ci}
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_cistatic void set_fragment_shader( void )
134bf215546Sopenharmony_ci{
135bf215546Sopenharmony_ci   void *handle;
136bf215546Sopenharmony_ci   const char *text =
137bf215546Sopenharmony_ci      "FRAG\n"
138bf215546Sopenharmony_ci      "DCL IN[0], GENERIC[0], PERSPECTIVE\n"
139bf215546Sopenharmony_ci      "DCL OUT[0], COLOR\n"
140bf215546Sopenharmony_ci      "DCL TEMP[0]\n"
141bf215546Sopenharmony_ci      "DCL SAMP[0]\n"
142bf215546Sopenharmony_ci      "DCL RES[0], 2D, FLOAT\n"
143bf215546Sopenharmony_ci      "  0: SAMPLE TEMP[0], IN[0], RES[0], SAMP[0]\n"
144bf215546Sopenharmony_ci      "  1: MOV OUT[0], TEMP[0]\n"
145bf215546Sopenharmony_ci      "  2: END\n";
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci   handle = graw_parse_fragment_shader(ctx, text);
148bf215546Sopenharmony_ci   ctx->bind_fs_state(ctx, handle);
149bf215546Sopenharmony_ci}
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_cistatic void draw( void )
153bf215546Sopenharmony_ci{
154bf215546Sopenharmony_ci   union pipe_color_union clear_color = { {.5,.5,.5,1} };
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
157bf215546Sopenharmony_ci   util_draw_arrays(ctx, PIPE_PRIM_QUADS, 0, 4);
158bf215546Sopenharmony_ci   ctx->flush(ctx, NULL, 0);
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci   graw_save_surface_to_file(ctx, surf, NULL);
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci   screen->flush_frontbuffer(screen, ctx, rttex, 0, 0, window, NULL);
163bf215546Sopenharmony_ci}
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci#define SIZE 16
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_cistatic void init_tex( void )
168bf215546Sopenharmony_ci{
169bf215546Sopenharmony_ci   struct pipe_sampler_view sv_template;
170bf215546Sopenharmony_ci   struct pipe_sampler_state sampler_desc;
171bf215546Sopenharmony_ci   struct pipe_resource templat;
172bf215546Sopenharmony_ci   struct pipe_box box;
173bf215546Sopenharmony_ci   ubyte tex2d[SIZE][SIZE][4];
174bf215546Sopenharmony_ci   int s, t;
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci#if (SIZE != 2)
177bf215546Sopenharmony_ci   for (s = 0; s < SIZE; s++) {
178bf215546Sopenharmony_ci      for (t = 0; t < SIZE; t++) {
179bf215546Sopenharmony_ci         if (0) {
180bf215546Sopenharmony_ci            int x = (s ^ t) & 1;
181bf215546Sopenharmony_ci	    tex2d[t][s][0] = (x) ? 0 : 63;
182bf215546Sopenharmony_ci	    tex2d[t][s][1] = (x) ? 0 : 128;
183bf215546Sopenharmony_ci	    tex2d[t][s][2] = 0;
184bf215546Sopenharmony_ci	    tex2d[t][s][3] = 0xff;
185bf215546Sopenharmony_ci         }
186bf215546Sopenharmony_ci         else {
187bf215546Sopenharmony_ci            int x = ((s ^ t) >> 2) & 1;
188bf215546Sopenharmony_ci	    tex2d[t][s][0] = s*255/(SIZE-1);
189bf215546Sopenharmony_ci	    tex2d[t][s][1] = t*255/(SIZE-1);
190bf215546Sopenharmony_ci	    tex2d[t][s][2] = (x) ? 0 : 128;
191bf215546Sopenharmony_ci	    tex2d[t][s][3] = 0xff;
192bf215546Sopenharmony_ci         }
193bf215546Sopenharmony_ci      }
194bf215546Sopenharmony_ci   }
195bf215546Sopenharmony_ci#else
196bf215546Sopenharmony_ci   tex2d[0][0][0] = 0;
197bf215546Sopenharmony_ci   tex2d[0][0][1] = 255;
198bf215546Sopenharmony_ci   tex2d[0][0][2] = 255;
199bf215546Sopenharmony_ci   tex2d[0][0][3] = 0;
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci   tex2d[0][1][0] = 0;
202bf215546Sopenharmony_ci   tex2d[0][1][1] = 0;
203bf215546Sopenharmony_ci   tex2d[0][1][2] = 255;
204bf215546Sopenharmony_ci   tex2d[0][1][3] = 255;
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci   tex2d[1][0][0] = 255;
207bf215546Sopenharmony_ci   tex2d[1][0][1] = 255;
208bf215546Sopenharmony_ci   tex2d[1][0][2] = 0;
209bf215546Sopenharmony_ci   tex2d[1][0][3] = 255;
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci   tex2d[1][1][0] = 255;
212bf215546Sopenharmony_ci   tex2d[1][1][1] = 0;
213bf215546Sopenharmony_ci   tex2d[1][1][2] = 0;
214bf215546Sopenharmony_ci   tex2d[1][1][3] = 255;
215bf215546Sopenharmony_ci#endif
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci   memset(&templat, 0, sizeof(templat));
218bf215546Sopenharmony_ci   templat.target = PIPE_TEXTURE_2D;
219bf215546Sopenharmony_ci   templat.format = PIPE_FORMAT_B8G8R8A8_UNORM;
220bf215546Sopenharmony_ci   templat.width0 = SIZE;
221bf215546Sopenharmony_ci   templat.height0 = SIZE;
222bf215546Sopenharmony_ci   templat.depth0 = 1;
223bf215546Sopenharmony_ci   templat.last_level = 0;
224bf215546Sopenharmony_ci   templat.bind = PIPE_BIND_SAMPLER_VIEW;
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci
227bf215546Sopenharmony_ci   samptex = screen->resource_create(screen,
228bf215546Sopenharmony_ci                                 &templat);
229bf215546Sopenharmony_ci   if (samptex == NULL)
230bf215546Sopenharmony_ci      exit(4);
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci   u_box_2d(0,0,SIZE,SIZE, &box);
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_ci   ctx->texture_subdata(ctx,
235bf215546Sopenharmony_ci                        samptex,
236bf215546Sopenharmony_ci                        0,
237bf215546Sopenharmony_ci                        PIPE_MAP_WRITE,
238bf215546Sopenharmony_ci                        &box,
239bf215546Sopenharmony_ci                        tex2d,
240bf215546Sopenharmony_ci                        sizeof tex2d[0],
241bf215546Sopenharmony_ci                        sizeof tex2d);
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_ci   /* Possibly read back & compare against original data:
244bf215546Sopenharmony_ci    */
245bf215546Sopenharmony_ci   if (0)
246bf215546Sopenharmony_ci   {
247bf215546Sopenharmony_ci      struct pipe_transfer *t;
248bf215546Sopenharmony_ci      uint32_t *ptr;
249bf215546Sopenharmony_ci      ptr = pipe_texture_map(ctx, samptex,
250bf215546Sopenharmony_ci                              0, 0, /* level, layer */
251bf215546Sopenharmony_ci                              PIPE_MAP_READ,
252bf215546Sopenharmony_ci                              0, 0, SIZE, SIZE, &t); /* x, y, width, height */
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_ci      if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
255bf215546Sopenharmony_ci         assert(0);
256bf215546Sopenharmony_ci         exit(9);
257bf215546Sopenharmony_ci      }
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci      ctx->texture_unmap(ctx, t);
260bf215546Sopenharmony_ci   }
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci   memset(&sv_template, 0, sizeof sv_template);
263bf215546Sopenharmony_ci   sv_template.format = samptex->format;
264bf215546Sopenharmony_ci   sv_template.texture = samptex;
265bf215546Sopenharmony_ci   sv_template.swizzle_r = 0;
266bf215546Sopenharmony_ci   sv_template.swizzle_g = 1;
267bf215546Sopenharmony_ci   sv_template.swizzle_b = 2;
268bf215546Sopenharmony_ci   sv_template.swizzle_a = 3;
269bf215546Sopenharmony_ci   sv = ctx->create_sampler_view(ctx, samptex, &sv_template);
270bf215546Sopenharmony_ci   if (sv == NULL)
271bf215546Sopenharmony_ci      exit(5);
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_ci   ctx->set_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &sv);
274bf215546Sopenharmony_ci
275bf215546Sopenharmony_ci
276bf215546Sopenharmony_ci   memset(&sampler_desc, 0, sizeof sampler_desc);
277bf215546Sopenharmony_ci   sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT;
278bf215546Sopenharmony_ci   sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT;
279bf215546Sopenharmony_ci   sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT;
280bf215546Sopenharmony_ci   sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST;
281bf215546Sopenharmony_ci   sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
282bf215546Sopenharmony_ci   sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
283bf215546Sopenharmony_ci   sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE;
284bf215546Sopenharmony_ci   sampler_desc.compare_func = 0;
285bf215546Sopenharmony_ci   sampler_desc.normalized_coords = 1;
286bf215546Sopenharmony_ci   sampler_desc.max_anisotropy = 0;
287bf215546Sopenharmony_ci
288bf215546Sopenharmony_ci   sampler = ctx->create_sampler_state(ctx, &sampler_desc);
289bf215546Sopenharmony_ci   if (sampler == NULL)
290bf215546Sopenharmony_ci      exit(6);
291bf215546Sopenharmony_ci
292bf215546Sopenharmony_ci   ctx->bind_sampler_states(ctx, PIPE_SHADER_FRAGMENT, 0, 1, &sampler);
293bf215546Sopenharmony_ci
294bf215546Sopenharmony_ci}
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_cistatic void init( void )
297bf215546Sopenharmony_ci{
298bf215546Sopenharmony_ci   struct pipe_framebuffer_state fb;
299bf215546Sopenharmony_ci   struct pipe_resource templat;
300bf215546Sopenharmony_ci   struct pipe_surface surf_tmpl;
301bf215546Sopenharmony_ci   int i;
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci   /* It's hard to say whether window or screen should be created
304bf215546Sopenharmony_ci    * first.  Different environments would prefer one or the other.
305bf215546Sopenharmony_ci    *
306bf215546Sopenharmony_ci    * Also, no easy way of querying supported formats if the screen
307bf215546Sopenharmony_ci    * cannot be created first.
308bf215546Sopenharmony_ci    */
309bf215546Sopenharmony_ci   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
310bf215546Sopenharmony_ci      screen = graw_create_window_and_screen(0, 0, 300, 300,
311bf215546Sopenharmony_ci                                             formats[i],
312bf215546Sopenharmony_ci                                             &window);
313bf215546Sopenharmony_ci      if (window && screen)
314bf215546Sopenharmony_ci         break;
315bf215546Sopenharmony_ci   }
316bf215546Sopenharmony_ci   if (!screen || !window) {
317bf215546Sopenharmony_ci      fprintf(stderr, "Unable to create window\n");
318bf215546Sopenharmony_ci      exit(1);
319bf215546Sopenharmony_ci   }
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci   ctx = screen->context_create(screen, NULL, 0);
322bf215546Sopenharmony_ci   if (ctx == NULL)
323bf215546Sopenharmony_ci      exit(3);
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_ci   memset(&templat, 0, sizeof(templat));
326bf215546Sopenharmony_ci   templat.target = PIPE_TEXTURE_2D;
327bf215546Sopenharmony_ci   templat.format = formats[i];
328bf215546Sopenharmony_ci   templat.width0 = WIDTH;
329bf215546Sopenharmony_ci   templat.height0 = HEIGHT;
330bf215546Sopenharmony_ci   templat.depth0 = 1;
331bf215546Sopenharmony_ci   templat.array_size = 1;
332bf215546Sopenharmony_ci   templat.last_level = 0;
333bf215546Sopenharmony_ci   templat.bind = (PIPE_BIND_RENDER_TARGET |
334bf215546Sopenharmony_ci                   PIPE_BIND_DISPLAY_TARGET);
335bf215546Sopenharmony_ci
336bf215546Sopenharmony_ci   rttex = screen->resource_create(screen,
337bf215546Sopenharmony_ci                                 &templat);
338bf215546Sopenharmony_ci   if (rttex == NULL)
339bf215546Sopenharmony_ci      exit(4);
340bf215546Sopenharmony_ci
341bf215546Sopenharmony_ci   surf_tmpl.format = templat.format;
342bf215546Sopenharmony_ci   surf_tmpl.u.tex.level = 0;
343bf215546Sopenharmony_ci   surf_tmpl.u.tex.first_layer = 0;
344bf215546Sopenharmony_ci   surf_tmpl.u.tex.last_layer = 0;
345bf215546Sopenharmony_ci   surf = ctx->create_surface(ctx, rttex, &surf_tmpl);
346bf215546Sopenharmony_ci   if (surf == NULL)
347bf215546Sopenharmony_ci      exit(5);
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci   memset(&fb, 0, sizeof fb);
350bf215546Sopenharmony_ci   fb.nr_cbufs = 1;
351bf215546Sopenharmony_ci   fb.width = WIDTH;
352bf215546Sopenharmony_ci   fb.height = HEIGHT;
353bf215546Sopenharmony_ci   fb.cbufs[0] = surf;
354bf215546Sopenharmony_ci
355bf215546Sopenharmony_ci   ctx->set_framebuffer_state(ctx, &fb);
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci   {
358bf215546Sopenharmony_ci      struct pipe_blend_state blend;
359bf215546Sopenharmony_ci      void *handle;
360bf215546Sopenharmony_ci      memset(&blend, 0, sizeof blend);
361bf215546Sopenharmony_ci      blend.rt[0].colormask = PIPE_MASK_RGBA;
362bf215546Sopenharmony_ci      handle = ctx->create_blend_state(ctx, &blend);
363bf215546Sopenharmony_ci      ctx->bind_blend_state(ctx, handle);
364bf215546Sopenharmony_ci   }
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_ci   {
367bf215546Sopenharmony_ci      struct pipe_depth_stencil_alpha_state depthstencil;
368bf215546Sopenharmony_ci      void *handle;
369bf215546Sopenharmony_ci      memset(&depthstencil, 0, sizeof depthstencil);
370bf215546Sopenharmony_ci      handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
371bf215546Sopenharmony_ci      ctx->bind_depth_stencil_alpha_state(ctx, handle);
372bf215546Sopenharmony_ci   }
373bf215546Sopenharmony_ci
374bf215546Sopenharmony_ci   {
375bf215546Sopenharmony_ci      struct pipe_rasterizer_state rasterizer;
376bf215546Sopenharmony_ci      void *handle;
377bf215546Sopenharmony_ci      memset(&rasterizer, 0, sizeof rasterizer);
378bf215546Sopenharmony_ci      rasterizer.cull_face = PIPE_FACE_NONE;
379bf215546Sopenharmony_ci      rasterizer.half_pixel_center = 1;
380bf215546Sopenharmony_ci      rasterizer.bottom_edge_rule = 1;
381bf215546Sopenharmony_ci      rasterizer.depth_clip_near = 1;
382bf215546Sopenharmony_ci      rasterizer.depth_clip_far = 1;
383bf215546Sopenharmony_ci      handle = ctx->create_rasterizer_state(ctx, &rasterizer);
384bf215546Sopenharmony_ci      ctx->bind_rasterizer_state(ctx, handle);
385bf215546Sopenharmony_ci   }
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci   set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ci   init_tex();
390bf215546Sopenharmony_ci
391bf215546Sopenharmony_ci   set_vertices();
392bf215546Sopenharmony_ci   set_vertex_shader();
393bf215546Sopenharmony_ci   set_fragment_shader();
394bf215546Sopenharmony_ci}
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_cistatic void args(int argc, char *argv[])
397bf215546Sopenharmony_ci{
398bf215546Sopenharmony_ci   int i;
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ci   for (i = 1; i < argc;) {
401bf215546Sopenharmony_ci      if (graw_parse_args(&i, argc, argv)) {
402bf215546Sopenharmony_ci         continue;
403bf215546Sopenharmony_ci      }
404bf215546Sopenharmony_ci      exit(1);
405bf215546Sopenharmony_ci   }
406bf215546Sopenharmony_ci}
407bf215546Sopenharmony_ci
408bf215546Sopenharmony_ci
409bf215546Sopenharmony_ciint main( int argc, char *argv[] )
410bf215546Sopenharmony_ci{
411bf215546Sopenharmony_ci   args(argc, argv);
412bf215546Sopenharmony_ci   init();
413bf215546Sopenharmony_ci
414bf215546Sopenharmony_ci   graw_set_display_func( draw );
415bf215546Sopenharmony_ci   graw_main_loop();
416bf215546Sopenharmony_ci   return 0;
417bf215546Sopenharmony_ci}
418