Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/tests/graw/tri-large.c
4565 views
1
/* Display a huge triangle on a 8192x8192 canvas.
2
* This demo has no dependencies on any utility code,
3
* just the graw interface and gallium.
4
*/
5
6
#include "graw_util.h"
7
#include "util/u_debug.h"
8
9
#include <stdio.h>
10
11
static struct graw_info info;
12
13
static const int WIDTH = 4*2048;
14
static const int HEIGHT = 4*2048;
15
16
17
struct vertex {
18
float position[4];
19
float color[4];
20
};
21
22
static boolean FlatShade = FALSE;
23
24
25
static struct vertex vertices[3] =
26
{
27
{
28
{ -1.0f, -1.0f, 0.0f, 1.0f },
29
{ 1.0f, 0.0f, 0.0f, 1.0f }
30
},
31
{
32
{ -1.0f, 1.0f, 0.0f, 1.0f },
33
{ 0.0f, 1.0f, 0.0f, 1.0f }
34
},
35
{
36
{ 1.0f, 1.0f, 0.0f, 1.0f },
37
{ 0.0f, 0.0f, 1.0f, 1.0f }
38
}
39
};
40
41
42
static void set_vertices( void )
43
{
44
struct pipe_vertex_element ve[2];
45
struct pipe_vertex_buffer vbuf;
46
void *handle;
47
48
memset(ve, 0, sizeof ve);
49
50
ve[0].src_offset = Offset(struct vertex, position);
51
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
52
ve[1].src_offset = Offset(struct vertex, color);
53
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
54
55
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
56
info.ctx->bind_vertex_elements_state(info.ctx, handle);
57
58
memset(&vbuf, 0, sizeof vbuf);
59
60
vbuf.stride = sizeof( struct vertex );
61
vbuf.buffer_offset = 0;
62
vbuf.buffer.resource = pipe_buffer_create_with_data(info.ctx,
63
PIPE_BIND_VERTEX_BUFFER,
64
PIPE_USAGE_DEFAULT,
65
sizeof(vertices),
66
vertices);
67
68
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &vbuf);
69
}
70
71
72
static void set_vertex_shader( void )
73
{
74
void *handle;
75
const char *text =
76
"VERT\n"
77
"DCL IN[0]\n"
78
"DCL IN[1]\n"
79
"DCL OUT[0], POSITION\n"
80
"DCL OUT[1], COLOR\n"
81
" 0: MOV OUT[1], IN[1]\n"
82
" 1: MOV OUT[0], IN[0]\n"
83
" 2: END\n";
84
85
handle = graw_parse_vertex_shader(info.ctx, text);
86
info.ctx->bind_vs_state(info.ctx, handle);
87
}
88
89
90
static void set_fragment_shader( void )
91
{
92
void *handle;
93
const char *text =
94
"FRAG\n"
95
"DCL IN[0], COLOR, LINEAR\n"
96
"DCL OUT[0], COLOR\n"
97
" 0: MOV OUT[0], IN[0]\n"
98
" 1: END\n";
99
100
handle = graw_parse_fragment_shader(info.ctx, text);
101
info.ctx->bind_fs_state(info.ctx, handle);
102
}
103
104
105
static void draw( void )
106
{
107
union pipe_color_union clear_color = { {1,0,1,1} };
108
109
info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
110
util_draw_arrays(info.ctx, PIPE_PRIM_TRIANGLES, 0, 3);
111
info.ctx->flush(info.ctx, NULL, 0);
112
113
graw_save_surface_to_file(info.ctx, info.color_surf[0], NULL);
114
115
graw_util_flush_front(&info);
116
}
117
118
119
static void init( void )
120
{
121
if (!graw_util_create_window(&info, WIDTH, HEIGHT, 1, FALSE))
122
exit(1);
123
124
graw_util_default_state(&info, FALSE);
125
126
{
127
struct pipe_rasterizer_state rasterizer;
128
void *handle;
129
memset(&rasterizer, 0, sizeof rasterizer);
130
rasterizer.cull_face = PIPE_FACE_NONE;
131
rasterizer.half_pixel_center = 1;
132
rasterizer.bottom_edge_rule = 1;
133
rasterizer.flatshade = FlatShade;
134
rasterizer.depth_clip_near = 1;
135
rasterizer.depth_clip_far = 1;
136
handle = info.ctx->create_rasterizer_state(info.ctx, &rasterizer);
137
info.ctx->bind_rasterizer_state(info.ctx, handle);
138
}
139
140
141
graw_util_viewport(&info, 0, 0, WIDTH, HEIGHT, 30, 1000);
142
143
set_vertices();
144
set_vertex_shader();
145
set_fragment_shader();
146
}
147
148
static void args(int argc, char *argv[])
149
{
150
int i;
151
152
for (i = 1; i < argc; ) {
153
if (graw_parse_args(&i, argc, argv)) {
154
/* ok */
155
}
156
else if (strcmp(argv[i], "-f") == 0) {
157
FlatShade = TRUE;
158
i++;
159
}
160
else {
161
printf("Invalid arg %s\n", argv[i]);
162
exit(1);
163
}
164
}
165
}
166
167
int main( int argc, char *argv[] )
168
{
169
args(argc, argv);
170
init();
171
172
graw_set_display_func( draw );
173
graw_main_loop();
174
return 0;
175
}
176
177