2
* Copyright © 2014 Keith Packard
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
* documentation for any purpose is hereby granted without fee, provided that
6
* the above copyright notice appear in all copies and that both that copyright
7
* notice and this permission notice appear in supporting documentation, and
8
* that the name of the copyright holders not be used in advertising or
9
* publicity pertaining to distribution of the software without specific,
10
* written prior permission. The copyright holders make no representations
11
* about the suitability of this software for any purpose. It is provided "as
12
* is" without express or implied warranty.
14
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23
#include "glamor_priv.h"
24
#include "glamor_program.h"
25
#include "glamor_transform.h"
27
static const glamor_facet glamor_facet_polyfillrect_130 = {
28
.name = "poly_fill_rect",
30
.vs_vars = "attribute vec4 primitive;\n",
31
.vs_exec = (" vec2 pos = primitive.zw * vec2(gl_VertexID&1, (gl_VertexID&2)>>1);\n"
32
GLAMOR_POS(gl_Position, (primitive.xy + pos))),
35
static const glamor_facet glamor_facet_polyfillrect_120 = {
36
.name = "poly_fill_rect",
37
.vs_vars = "attribute vec2 primitive;\n",
38
.vs_exec = (" vec2 pos = vec2(0,0);\n"
39
GLAMOR_POS(gl_Position, primitive.xy)),
43
glamor_poly_fill_rect_gl(DrawablePtr drawable,
44
GCPtr gc, int nrect, xRectangle *prect)
46
ScreenPtr screen = drawable->pScreen;
47
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
48
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
49
glamor_pixmap_private *pixmap_priv;
56
pixmap_priv = glamor_get_pixmap_private(pixmap);
57
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
60
glamor_make_current(glamor_priv);
62
if (glamor_priv->glsl_version >= 130) {
63
prog = glamor_use_program_fill(pixmap, gc,
64
&glamor_priv->poly_fill_rect_program,
65
&glamor_facet_polyfillrect_130);
70
/* Set up the vertex buffers for the points */
72
v = glamor_get_vbo_space(drawable->pScreen, nrect * sizeof (xRectangle), &vbo_offset);
74
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
75
glVertexAttribDivisor(GLAMOR_VERTEX_POS, 1);
76
glVertexAttribPointer(GLAMOR_VERTEX_POS, 4, GL_SHORT, GL_FALSE,
77
4 * sizeof (short), vbo_offset);
79
memcpy(v, prect, nrect * sizeof (xRectangle));
81
glamor_put_vbo_space(screen);
85
prog = glamor_use_program_fill(pixmap, gc,
86
&glamor_priv->poly_fill_rect_program,
87
&glamor_facet_polyfillrect_120);
92
/* Set up the vertex buffers for the points */
94
v = glamor_get_vbo_space(drawable->pScreen, nrect * 8 * sizeof (short), &vbo_offset);
96
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
97
glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE,
98
2 * sizeof (short), vbo_offset);
100
for (n = 0; n < nrect; n++) {
101
v[0] = prect->x; v[1] = prect->y;
102
v[2] = prect->x; v[3] = prect->y + prect->height;
103
v[4] = prect->x + prect->width; v[5] = prect->y + prect->height;
104
v[6] = prect->x + prect->width; v[7] = prect->y;
109
glamor_put_vbo_space(screen);
112
glEnable(GL_SCISSOR_TEST);
114
glamor_pixmap_loop(pixmap_priv, box_index) {
115
int nbox = RegionNumRects(gc->pCompositeClip);
116
BoxPtr box = RegionRects(gc->pCompositeClip);
118
glamor_set_destination_drawable(drawable, box_index, TRUE, FALSE,
119
prog->matrix_uniform, &off_x, &off_y);
122
glScissor(box->x1 + off_x,
127
if (glamor_priv->glsl_version >= 130)
128
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, nrect);
130
glamor_glDrawArrays_GL_QUADS(glamor_priv, nrect);
135
glDisable(GL_SCISSOR_TEST);
136
if (glamor_priv->glsl_version >= 130)
137
glVertexAttribDivisor(GLAMOR_VERTEX_POS, 0);
138
glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
146
glamor_poly_fill_rect_bail(DrawablePtr drawable,
147
GCPtr gc, int nrect, xRectangle *prect)
149
glamor_fallback("to %p (%c)\n", drawable,
150
glamor_get_drawable_location(drawable));
151
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) &&
152
glamor_prepare_access_gc(gc)) {
153
fbPolyFillRect(drawable, gc, nrect, prect);
155
glamor_finish_access_gc(gc);
156
glamor_finish_access(drawable);
160
glamor_poly_fill_rect(DrawablePtr drawable,
161
GCPtr gc, int nrect, xRectangle *prect)
163
if (glamor_poly_fill_rect_gl(drawable, gc, nrect, prect))
165
glamor_poly_fill_rect_bail(drawable, gc, nrect, prect);