Lines Matching refs:renderer
28 #include "renderer.h"
76 struct renderer {
133 * Return VG_TRUE if the renderer can use the resource as the asked bindings.
135 static VGboolean renderer_can_support(struct renderer *renderer,
139 struct pipe_screen *screen = renderer->pipe->screen;
148 static void renderer_set_mvp(struct renderer *renderer,
151 struct matrix *cur = &renderer->mvp;
158 mvp = &renderer->projection;
172 cbuf = renderer->vs_cbuf;
174 cbuf = pipe_buffer_create(renderer->pipe->screen,
179 pipe_buffer_write(renderer->pipe, cbuf,
182 pipe_set_constant_buffer(renderer->pipe,
186 renderer->vs_cbuf = cbuf;
230 * Set renderer vertex shader.
234 static void renderer_set_vs(struct renderer *r, RendererVs id)
250 assert(!"Unknown renderer vs id");
299 * Set renderer fragment shader.
303 static void renderer_set_fs(struct renderer *r, RendererFs id)
324 assert(!"Unknown renderer fs id");
339 static void vg_set_viewport(struct renderer *r,
359 * Set renderer target.
363 static void renderer_set_target(struct renderer *r,
382 * Set renderer blend state. Blending is disabled.
386 static void renderer_set_blend(struct renderer *r,
411 * Set renderer sampler and view states.
415 static void renderer_set_samplers(struct renderer *r,
446 * Set custom renderer fragment shader, and optionally set samplers and views
452 static void renderer_set_custom_fs(struct renderer *renderer,
460 cso_set_fragment_shader_handle(renderer->cso, fs);
464 cso_set_samplers(renderer->cso, PIPE_SHADER_FRAGMENT, num_samplers, samplers);
465 cso_set_sampler_views(renderer->cso, PIPE_SHADER_FRAGMENT, num_samplers, views);
470 struct pipe_resource *cbuf = renderer->fs_cbuf;
472 if (!cbuf || renderer->fs_cbuf_len != const_buffer_len ||
473 memcmp(renderer->fs_cbuf_data, const_buffer, const_buffer_len)) {
476 cbuf = pipe_buffer_create(renderer->pipe->screen,
479 pipe_buffer_write(renderer->pipe, cbuf, 0,
481 pipe_set_constant_buffer(renderer->pipe,
484 renderer->fs_cbuf = cbuf;
485 if (const_buffer_len <= sizeof(renderer->fs_cbuf_data)) {
486 memcpy(renderer->fs_cbuf_data, const_buffer, const_buffer_len);
487 renderer->fs_cbuf_len = const_buffer_len;
490 renderer->fs_cbuf_len = 0;
497 * Setup renderer quad position.
499 static void renderer_quad_pos(struct renderer *r,
528 * Setup renderer quad texture coordinates.
530 static void renderer_quad_texcoord(struct renderer *r,
565 * Draw renderer quad.
567 static void renderer_quad_draw(struct renderer *r)
575 * Prepare the renderer for copying.
577 VGboolean renderer_copy_begin(struct renderer *renderer,
582 assert(renderer->state == RENDERER_STATE_INIT);
585 renderer,
587 !renderer_can_support(renderer,
591 cso_save_framebuffer(renderer->cso);
592 cso_save_viewport(renderer->cso);
593 cso_save_blend(renderer->cso);
594 cso_save_samplers(renderer->cso, PIPE_SHADER_FRAGMENT);
595 cso_save_sampler_views(renderer->cso, PIPE_SHADER_FRAGMENT);
596 cso_save_fragment_shader(renderer->cso);
597 cso_save_vertex_shader(renderer->cso);
599 renderer_set_target(renderer, dst, NULL, y0_top);
601 renderer_set_blend(renderer, ~0);
602 renderer_set_samplers(renderer, 1, &src);
604 renderer_set_fs(renderer, RENDERER_FS_TEXTURE);
605 renderer_set_vs(renderer, RENDERER_VS_TEXTURE);
607 renderer_set_mvp(renderer, NULL);
610 renderer->u.copy.tex_width = src->texture->width0;
611 renderer->u.copy.tex_height = src->texture->height0;
612 renderer->state = RENDERER_STATE_COPY;
623 void renderer_copy(struct renderer *renderer,
627 assert(renderer->state == RENDERER_STATE_COPY);
630 renderer_quad_pos(renderer, x, y, x + w, y + h, VG_FALSE);
631 renderer_quad_texcoord(renderer, sx, sy, sx + sw, sy + sh,
632 renderer->u.copy.tex_width,
633 renderer->u.copy.tex_height);
635 renderer_quad_draw(renderer);
641 void renderer_copy_end(struct renderer *renderer)
643 assert(renderer->state == RENDERER_STATE_COPY);
645 cso_restore_framebuffer(renderer->cso);
646 cso_restore_viewport(renderer->cso);
647 cso_restore_blend(renderer->cso);
648 cso_restore_samplers(renderer->cso, PIPE_SHADER_FRAGMENT);
649 cso_restore_sampler_views(renderer->cso, PIPE_SHADER_FRAGMENT);
650 cso_restore_fragment_shader(renderer->cso);
651 cso_restore_vertex_shader(renderer->cso);
653 renderer->state = RENDERER_STATE_INIT;
657 * Prepare the renderer for textured drawing.
659 VGboolean renderer_drawtex_begin(struct renderer *renderer,
662 assert(renderer->state == RENDERER_STATE_INIT);
664 if (!renderer_can_support(renderer, src->texture, PIPE_BIND_SAMPLER_VIEW))
667 cso_save_blend(renderer->cso);
668 cso_save_samplers(renderer->cso, PIPE_SHADER_FRAGMENT);
669 cso_save_sampler_views(renderer->cso, PIPE_SHADER_FRAGMENT);
670 cso_save_fragment_shader(renderer->cso);
671 cso_save_vertex_shader(renderer->cso);
673 renderer_set_blend(renderer, ~0);
675 renderer_set_samplers(renderer, 1, &src);
677 renderer_set_fs(renderer, RENDERER_FS_TEXTURE);
678 renderer_set_vs(renderer, RENDERER_VS_TEXTURE);
680 renderer_set_mvp(renderer, NULL);
683 renderer->u.drawtex.tex_width = src->texture->width0;
684 renderer->u.drawtex.tex_height = src->texture->height0;
685 renderer->state = RENDERER_STATE_DRAWTEX;
696 void renderer_drawtex(struct renderer *renderer,
700 assert(renderer->state == RENDERER_STATE_DRAWTEX);
703 renderer_quad_pos(renderer, x, y, x + w, y + h, VG_TRUE);
704 renderer_quad_texcoord(renderer, sx, sy, sx + sw, sy + sh,
705 renderer->u.drawtex.tex_width,
706 renderer->u.drawtex.tex_height);
708 renderer_quad_draw(renderer);
714 void renderer_drawtex_end(struct renderer *renderer)
716 assert(renderer->state == RENDERER_STATE_DRAWTEX);
718 cso_restore_blend(renderer->cso);
719 cso_restore_samplers(renderer->cso, PIPE_SHADER_FRAGMENT);
720 cso_restore_sampler_views(renderer->cso, PIPE_SHADER_FRAGMENT);
721 cso_restore_fragment_shader(renderer->cso);
722 cso_restore_vertex_shader(renderer->cso);
724 renderer->state = RENDERER_STATE_INIT;
728 * Prepare the renderer for scissor update. This will reset the depth buffer
731 VGboolean renderer_scissor_begin(struct renderer *renderer,
736 assert(renderer->state == RENDERER_STATE_INIT);
739 cso_save_depth_stencil_alpha(renderer->cso);
740 cso_save_blend(renderer->cso);
741 cso_save_fragment_shader(renderer->cso);
748 cso_set_depth_stencil_alpha(renderer->cso, &dsa);
751 renderer_set_blend(renderer, 0);
752 renderer_set_fs(renderer, RENDERER_FS_SCISSOR);
754 renderer_set_mvp(renderer, NULL);
756 renderer->u.scissor.restore_dsa = restore_dsa;
757 renderer->state = RENDERER_STATE_SCISSOR;
760 renderer->pipe->clear(renderer->pipe,
770 void renderer_scissor(struct renderer *renderer,
773 assert(renderer->state == RENDERER_STATE_SCISSOR);
775 renderer_quad_pos(renderer, x, y, x + width, y + height, VG_FALSE);
776 renderer_quad_draw(renderer);
782 void renderer_scissor_end(struct renderer *renderer)
784 assert(renderer->state == RENDERER_STATE_SCISSOR);
786 if (renderer->u.scissor.restore_dsa)
787 cso_restore_depth_stencil_alpha(renderer->cso);
788 cso_restore_blend(renderer->cso);
789 cso_restore_fragment_shader(renderer->cso);
791 renderer->state = RENDERER_STATE_INIT;
795 * Prepare the renderer for clearing.
797 VGboolean renderer_clear_begin(struct renderer *renderer)
799 assert(renderer->state == RENDERER_STATE_INIT);
801 cso_save_blend(renderer->cso);
802 cso_save_fragment_shader(renderer->cso);
803 cso_save_vertex_shader(renderer->cso);
805 renderer_set_blend(renderer, ~0);
806 renderer_set_fs(renderer, RENDERER_FS_COLOR);
807 renderer_set_vs(renderer, RENDERER_VS_COLOR);
809 renderer_set_mvp(renderer, NULL);
811 renderer->state = RENDERER_STATE_CLEAR;
821 void renderer_clear(struct renderer *renderer,
827 assert(renderer->state == RENDERER_STATE_CLEAR);
829 renderer_quad_pos(renderer, x, y, x + width, y + height, VG_TRUE);
831 memcpy(renderer->vertices[i][1], color, sizeof(VGfloat) * 4);
833 renderer_quad_draw(renderer);
839 void renderer_clear_end(struct renderer *renderer)
841 assert(renderer->state == RENDERER_STATE_CLEAR);
843 cso_restore_blend(renderer->cso);
844 cso_restore_fragment_shader(renderer->cso);
845 cso_restore_vertex_shader(renderer->cso);
847 renderer->state = RENDERER_STATE_INIT;
851 * Prepare the renderer for image filtering.
853 VGboolean renderer_filter_begin(struct renderer *renderer,
866 assert(renderer->state == RENDERER_STATE_INIT);
870 if (!renderer_can_support(renderer, dst, PIPE_BIND_RENDER_TARGET))
875 surf = renderer->pipe->create_surface(renderer->pipe, dst, &surf_tmpl);
879 cso_save_framebuffer(renderer->cso);
880 cso_save_viewport(renderer->cso);
881 cso_save_blend(renderer->cso);
884 renderer_set_target(renderer, surf, NULL, y0_top);
887 renderer_set_blend(renderer, channel_mask);
892 cso_save_samplers(renderer->cso, PIPE_SHADER_FRAGMENT);
893 cso_save_sampler_views(renderer->cso, PIPE_SHADER_FRAGMENT);
894 cso_save_fragment_shader(renderer->cso);
895 cso_save_vertex_shader(renderer->cso);
897 renderer_set_custom_fs(renderer, fs,
900 renderer_set_vs(renderer, RENDERER_VS_TEXTURE);
903 renderer->u.filter.tex_width = tex->width0;
904 renderer->u.filter.tex_height = tex->height0;
905 renderer->u.filter.use_sampler = VG_TRUE;
908 cso_save_fragment_shader(renderer->cso);
910 renderer_set_custom_fs(renderer, fs, NULL, NULL, 0,
913 renderer->u.filter.use_sampler = VG_FALSE;
916 renderer_set_mvp(renderer, NULL);
918 renderer->state = RENDERER_STATE_FILTER;
929 void renderer_filter(struct renderer *renderer,
933 assert(renderer->state == RENDERER_STATE_FILTER);
935 renderer_quad_pos(renderer, x, y, x + w, y + h, VG_FALSE);
936 if (renderer->u.filter.use_sampler) {
937 renderer_quad_texcoord(renderer, sx, sy, sx + sw, sy + sh,
938 renderer->u.filter.tex_width,
939 renderer->u.filter.tex_height);
942 renderer_quad_draw(renderer);
948 void renderer_filter_end(struct renderer *renderer)
950 assert(renderer->state == RENDERER_STATE_FILTER);
952 if (renderer->u.filter.use_sampler) {
953 cso_restore_samplers(renderer->cso, PIPE_SHADER_FRAGMENT);
954 cso_restore_sampler_views(renderer->cso, PIPE_SHADER_FRAGMENT);
955 cso_restore_vertex_shader(renderer->cso);
958 cso_restore_framebuffer(renderer->cso);
959 cso_restore_viewport(renderer->cso);
960 cso_restore_blend(renderer->cso);
961 cso_restore_fragment_shader(renderer->cso);
963 renderer->state = RENDERER_STATE_INIT;
967 * Prepare the renderer for polygon silhouette rendering.
969 VGboolean renderer_polygon_stencil_begin(struct renderer *renderer,
977 assert(renderer->state == RENDERER_STATE_INIT);
979 cso_save_vertex_elements(renderer->cso);
980 cso_save_blend(renderer->cso);
981 cso_save_depth_stencil_alpha(renderer->cso);
983 cso_set_vertex_elements(renderer->cso, 1, velem);
986 renderer_set_blend(renderer, 0);
989 dsa = &renderer->u.polygon_stencil.dsa;
1012 if (renderer->pipe->screen->get_param(renderer->pipe->screen,
1022 cso_set_depth_stencil_alpha(renderer->cso, dsa);
1025 cso_save_rasterizer(renderer->cso);
1027 renderer->u.polygon_stencil.manual_two_sides = manual_two_sides;
1028 renderer->u.polygon_stencil.restore_dsa = restore_dsa;
1029 renderer->state = RENDERER_STATE_POLYGON_STENCIL;
1037 void renderer_polygon_stencil(struct renderer *renderer,
1041 assert(renderer->state == RENDERER_STATE_POLYGON_STENCIL);
1043 cso_set_vertex_buffers(renderer->cso, 1, vbuf);
1045 if (!renderer->u.polygon_stencil.manual_two_sides) {
1046 cso_draw_arrays(renderer->cso, mode, start, count);
1052 raster = renderer->g3d.rasterizer;
1053 dsa = renderer->u.polygon_stencil.dsa;
1059 cso_set_rasterizer(renderer->cso, &raster);
1060 cso_set_depth_stencil_alpha(renderer->cso, &dsa);
1061 cso_draw_arrays(renderer->cso, mode, start, count);
1067 cso_set_rasterizer(renderer->cso, &raster);
1068 cso_set_depth_stencil_alpha(renderer->cso, &dsa);
1069 cso_draw_arrays(renderer->cso, mode, start, count);
1076 void renderer_polygon_stencil_end(struct renderer *renderer)
1078 assert(renderer->state == RENDERER_STATE_POLYGON_STENCIL);
1080 if (renderer->u.polygon_stencil.manual_two_sides)
1081 cso_restore_rasterizer(renderer->cso);
1083 cso_restore_vertex_elements(renderer->cso);
1086 cso_restore_blend(renderer->cso);
1088 if (renderer->u.polygon_stencil.restore_dsa)
1089 cso_restore_depth_stencil_alpha(renderer->cso);
1091 renderer->state = RENDERER_STATE_INIT;
1095 * Prepare the renderer for polygon filling.
1097 VGboolean renderer_polygon_fill_begin(struct renderer *renderer,
1102 assert(renderer->state == RENDERER_STATE_INIT);
1105 cso_save_depth_stencil_alpha(renderer->cso);
1116 dsa.depth = renderer->g3d.dsa.depth;
1117 cso_set_depth_stencil_alpha(renderer->cso, &dsa);
1119 renderer->state = RENDERER_STATE_POLYGON_FILL;
1127 void renderer_polygon_fill(struct renderer *renderer,
1131 assert(renderer->state == RENDERER_STATE_POLYGON_FILL);
1133 renderer_quad_pos(renderer, min_x, min_y, max_x, max_y, VG_TRUE);
1134 renderer_quad_draw(renderer);
1140 void renderer_polygon_fill_end(struct renderer *renderer)
1142 assert(renderer->state == RENDERER_STATE_POLYGON_FILL);
1144 cso_restore_depth_stencil_alpha(renderer->cso);
1146 renderer->state = RENDERER_STATE_INIT;
1149 struct renderer * renderer_create(struct vg_context *owner)
1151 struct renderer *renderer;
1156 renderer = CALLOC_STRUCT(renderer);
1157 if (!renderer)
1160 renderer->pipe = owner->pipe;
1161 renderer->cso = owner->cso_context;
1165 renderer->vertices[i][0][3] = 1.0f; /* w */
1168 renderer->velems[i].src_offset = i * 4 * sizeof(float);
1169 renderer->velems[i].instance_divisor = 0;
1170 renderer->velems[i].vertex_buffer_index = 0;
1171 renderer->velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
1173 cso_set_vertex_elements(renderer->cso, 2, renderer->velems);
1176 raster = &renderer->g3d.rasterizer;
1180 cso_set_rasterizer(renderer->cso, raster);
1184 cso_set_stencil_ref(renderer->cso, &sr);
1186 renderer_set_vs(renderer, RENDERER_VS_PLAIN);
1188 renderer->state = RENDERER_STATE_INIT;
1190 return renderer;
1193 void renderer_destroy(struct renderer *ctx)
1212 static void update_clip_state(struct renderer *renderer,
1215 struct pipe_depth_stencil_alpha_state *dsa = &renderer->g3d.dsa;
1220 struct pipe_framebuffer_state *fb = &renderer->g3d.fb;
1223 renderer_scissor_begin(renderer, VG_FALSE);
1250 renderer_scissor(renderer, x0, y0, iw, ih);
1253 renderer_scissor_end(renderer);
1261 static void renderer_validate_blend(struct renderer *renderer,
1320 cso_set_blend(renderer->cso, &blend);
1324 * Propogate OpenVG state changes to the renderer. Only framebuffer, blending
1327 void renderer_validate(struct renderer *renderer,
1332 assert(renderer->state == RENDERER_STATE_INIT);
1334 dirty |= renderer->dirty;
1335 renderer->dirty = 0;
1338 struct pipe_framebuffer_state *fb = &renderer->g3d.fb;
1339 struct matrix *proj = &renderer->projection;
1348 cso_set_framebuffer(renderer->cso, fb);
1349 vg_set_viewport(renderer, VEGA_Y0_BOTTOM);
1357 renderer->pipe->clear(renderer->pipe,
1364 update_clip_state(renderer, state);
1365 cso_set_depth_stencil_alpha(renderer->cso, &renderer->g3d.dsa);
1369 renderer_validate_blend(renderer, state, stfb->strb->format);
1373 * Prepare the renderer for OpenVG pipeline.
1375 void renderer_validate_for_shader(struct renderer *renderer,
1384 struct matrix mvp = renderer->projection;
1388 renderer_set_mvp(renderer, &mvp);
1390 renderer_set_custom_fs(renderer, fs,
1395 void renderer_validate_for_mask_rendering(struct renderer *renderer,
1399 struct matrix mvp = renderer->projection;
1403 renderer_set_mvp(renderer, &mvp);
1405 renderer_set_target(renderer, dst, renderer->g3d.fb.zsbuf, VG_FALSE);
1406 renderer_set_blend(renderer, ~0);
1407 renderer_set_fs(renderer, RENDERER_FS_WHITE);
1410 renderer->dirty = FRAMEBUFFER_DIRTY | BLEND_DIRTY;
1413 void renderer_copy_surface(struct renderer *ctx,
1515 void renderer_texture_quad(struct renderer *r,