pp_program.c revision 85d2ee59d9dd71b829f7356e9080103fe0b3251a
11320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci/**************************************************************************
21320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci *
31320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * Copyright 2010 Jakob Bornecrantz
41320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * Copyright 2011 Lauri Kasanen
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * All Rights Reserved.
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci *
71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * Permission is hereby granted, free of charge, to any person obtaining a
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * copy of this software and associated documentation files (the
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * "Software"), to deal in the Software without restriction, including
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29#include "postprocess/postprocess.h"
30#include "cso_cache/cso_context.h"
31#include "pipe/p_screen.h"
32#include "pipe/p_context.h"
33#include "pipe/p_state.h"
34#include "pipe/p_shader_tokens.h"
35#include "util/u_inlines.h"
36#include "util/u_simple_shaders.h"
37
38/** Initialize the internal details */
39struct program *
40pp_init_prog(struct pp_queue_t *ppq, struct pipe_screen *pscreen)
41{
42
43   struct program *p = calloc(1, sizeof(struct program));
44
45   pp_debug("Initializing program\n");
46   if (!pscreen)
47      return NULL;
48
49   if (!p)
50      return NULL;
51
52   p->screen = pscreen;
53   p->pipe = pscreen->context_create(pscreen, NULL);
54   p->cso = cso_create_context(p->pipe);
55
56   {
57      static const float verts[4][2][4] = {
58         {
59          {1.0f, 1.0f, 0.0f, 1.0f},
60          {1.0f, 1.0f, 0.0f, 1.0f}
61          },
62         {
63          {-1.0f, 1.0f, 0.0f, 1.0f},
64          {0.0f, 1.0f, 0.0f, 1.0f}
65          },
66         {
67          {-1.0f, -1.0f, 0.0f, 1.0f},
68          {0.0f, 0.0f, 0.0f, 1.0f}
69          },
70         {
71          {1.0f, -1.0f, 0.0f, 1.0f},
72          {1.0f, 0.0f, 0.0f, 1.0f}
73          }
74      };
75
76      p->vbuf = pipe_buffer_create(pscreen, PIPE_BIND_VERTEX_BUFFER,
77                                   PIPE_USAGE_STATIC, sizeof(verts));
78      pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(verts), verts);
79   }
80
81   p->blend.rt[0].colormask = PIPE_MASK_RGBA;
82   p->blend.rt[0].rgb_src_factor = p->blend.rt[0].alpha_src_factor =
83      PIPE_BLENDFACTOR_SRC_ALPHA;
84   p->blend.rt[0].rgb_dst_factor = p->blend.rt[0].alpha_dst_factor =
85      PIPE_BLENDFACTOR_INV_SRC_ALPHA;
86
87   p->rasterizer.cull_face = PIPE_FACE_NONE;
88   p->rasterizer.gl_rasterization_rules = 1;
89
90   p->sampler.wrap_s = p->sampler.wrap_t = p->sampler.wrap_r =
91      PIPE_TEX_WRAP_CLAMP_TO_EDGE;
92
93   p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
94   p->sampler.min_img_filter = p->sampler.mag_img_filter =
95      PIPE_TEX_FILTER_LINEAR;
96   p->sampler.normalized_coords = 1;
97
98   p->sampler_point.wrap_s = p->sampler_point.wrap_t =
99      p->sampler_point.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
100   p->sampler_point.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
101   p->sampler_point.min_img_filter = p->sampler_point.mag_img_filter =
102      PIPE_TEX_FILTER_NEAREST;
103   p->sampler_point.normalized_coords = 1;
104
105   p->velem[0].src_offset = 0;
106   p->velem[0].instance_divisor = 0;
107   p->velem[0].vertex_buffer_index = 0;
108   p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
109   p->velem[1].src_offset = 1 * 4 * sizeof(float);
110   p->velem[1].instance_divisor = 0;
111   p->velem[1].vertex_buffer_index = 0;
112   p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
113
114   if (!p->screen->is_format_supported(p->screen,
115                                       PIPE_FORMAT_R32G32B32A32_FLOAT,
116                                       PIPE_BUFFER, 1,
117                                       PIPE_BIND_VERTEX_BUFFER))
118      pp_debug("Vertex buf format fail\n");
119
120
121   {
122      const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
123         TGSI_SEMANTIC_GENERIC
124      };
125      const uint semantic_indexes[] = { 0, 0 };
126      p->passvs = util_make_vertex_passthrough_shader(p->pipe, 2,
127                                                      semantic_names,
128                                                      semantic_indexes);
129   }
130
131   p->framebuffer.nr_cbufs = 1;
132
133   p->surf.usage = PIPE_BIND_RENDER_TARGET;
134   p->surf.format = PIPE_FORMAT_B8G8R8A8_UNORM;
135
136   return p;
137}
138