rsProgramStore.cpp revision fb6b614bcea88a587a7ea4530be45ff0ffa0210e
1326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams/*
2326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Copyright (C) 2009 The Android Open Source Project
3326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
4326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * you may not use this file except in compliance with the License.
6326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * You may obtain a copy of the License at
7326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
8326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
10326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Unless required by applicable law or agreed to in writing, software
11326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * See the License for the specific language governing permissions and
14326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * limitations under the License.
15326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams */
16326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
17fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#ifndef ANDROID_RS_BUILD_FOR_HOST
18326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsContext.h"
191aa5a4eb81b8b88aeb5d2b6f4c47356fd0a62923Jason Sams#include <GLES/gl.h>
201aa5a4eb81b8b88aeb5d2b6f4c47356fd0a62923Jason Sams#include <GLES/glext.h>
21fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#else
22fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#include "rsContextHostStub.h"
23fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#include <OpenGL/gl.h>
24fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#include <OpenGl/glext.h>
25fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#endif //ANDROID_RS_BUILD_FOR_HOST
26fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
27fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#include "rsProgramStore.h"
281aa5a4eb81b8b88aeb5d2b6f4c47356fd0a62923Jason Sams
29326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsusing namespace android;
30326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsusing namespace android::renderscript;
31326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
32326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
33ccc010bb7c0f89e162bf60033968a20be90a903aJason SamsProgramStore::ProgramStore(Context *rsc) :
344815c0d121310cfcd6a8aba4eab77a9910af53acJason Sams    Program(rsc)
35326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
36f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mAllocFile = __FILE__;
37f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mAllocLine = __LINE__;
38326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mDitherEnable = true;
39326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mBlendEnable = false;
40326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorRWriteEnable = true;
41326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorGWriteEnable = true;
42326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorBWriteEnable = true;
43326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorAWriteEnable = true;
44326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mBlendSrc = GL_ONE;
45326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mBlendDst = GL_ZERO;
46326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
47326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
48326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mDepthTestEnable = false;
49326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mDepthWriteEnable = true;
50326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mDepthFunc = GL_LESS;
51326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
52326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
53326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
54326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
55ccc010bb7c0f89e162bf60033968a20be90a903aJason SamsProgramStore::~ProgramStore()
56326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
57326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
58326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
59ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStore::setupGL(const Context *rsc, ProgramStoreState *state)
60326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
61cfb1d11ce6826fce7241d316d8b7dcab661f63a6Jason Sams    if (state->mLast.get() == this) {
62cfb1d11ce6826fce7241d316d8b7dcab661f63a6Jason Sams        return;
63cfb1d11ce6826fce7241d316d8b7dcab661f63a6Jason Sams    }
64cfb1d11ce6826fce7241d316d8b7dcab661f63a6Jason Sams    state->mLast.set(this);
65cfb1d11ce6826fce7241d316d8b7dcab661f63a6Jason Sams
66326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    glColorMask(mColorRWriteEnable,
67326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams                mColorGWriteEnable,
68326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams                mColorBWriteEnable,
69326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams                mColorAWriteEnable);
70326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    if (mBlendEnable) {
71326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glEnable(GL_BLEND);
72326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glBlendFunc(mBlendSrc, mBlendDst);
73326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    } else {
74326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glDisable(GL_BLEND);
75326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    }
76326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
77fd10b71b33b7340c00c11c8684ca940e83b5aacaJason Sams    //LOGE("pfs  %i, %i, %x", mDepthWriteEnable, mDepthTestEnable, mDepthFunc);
78fd10b71b33b7340c00c11c8684ca940e83b5aacaJason Sams
79326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    glDepthMask(mDepthWriteEnable);
80fd10b71b33b7340c00c11c8684ca940e83b5aacaJason Sams    if(mDepthTestEnable || mDepthWriteEnable) {
81326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glEnable(GL_DEPTH_TEST);
82326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glDepthFunc(mDepthFunc);
83326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    } else {
84326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glDisable(GL_DEPTH_TEST);
85326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    }
86326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
87326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    if (mDitherEnable) {
88326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glEnable(GL_DITHER);
89326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    } else {
90326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        glDisable(GL_DITHER);
91326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    }
92c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams}
93326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
94ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state)
95c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams{
96c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    if (state->mLast.get() == this) {
97c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        return;
98c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    }
99c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    state->mLast.set(this);
100c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams
101c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    glColorMask(mColorRWriteEnable,
102c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams                mColorGWriteEnable,
103c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams                mColorBWriteEnable,
104c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams                mColorAWriteEnable);
105c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    if (mBlendEnable) {
106c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glEnable(GL_BLEND);
107c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glBlendFunc(mBlendSrc, mBlendDst);
108c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    } else {
109c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glDisable(GL_BLEND);
110c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    }
111326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
112c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    //LOGE("pfs  %i, %i, %x", mDepthWriteEnable, mDepthTestEnable, mDepthFunc);
113c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams
114c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    glDepthMask(mDepthWriteEnable);
115c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    if(mDepthTestEnable || mDepthWriteEnable) {
116c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glEnable(GL_DEPTH_TEST);
117c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glDepthFunc(mDepthFunc);
118c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    } else {
119c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glDisable(GL_DEPTH_TEST);
120c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    }
121c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams
122c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    if (mDitherEnable) {
123c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glEnable(GL_DITHER);
124c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    } else {
125c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        glDisable(GL_DITHER);
126c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    }
127326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
128326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
129c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams
130ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStore::setDitherEnable(bool enable)
131326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
132326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mDitherEnable = enable;
133326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
134326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
135fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchoukvoid ProgramStore::serialize(OStream *stream) const
136fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk{
137fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
138fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk}
139fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
140fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex SakhartchoukProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream)
141fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk{
142fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    return NULL;
143fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk}
144fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
145fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
146ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStore::setDepthFunc(RsDepthFunc func)
147326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
148326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mDepthTestEnable = true;
149326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
150326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    switch(func) {
151326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_DEPTH_FUNC_ALWAYS:
152326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthTestEnable = false;
153326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthFunc = GL_ALWAYS;
154326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
155326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_DEPTH_FUNC_LESS:
156326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthFunc = GL_LESS;
157326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
158326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_DEPTH_FUNC_LEQUAL:
159326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthFunc = GL_LEQUAL;
160326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
161326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_DEPTH_FUNC_GREATER:
162326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthFunc = GL_GREATER;
163326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
164326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_DEPTH_FUNC_GEQUAL:
165326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthFunc = GL_GEQUAL;
166326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
167326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_DEPTH_FUNC_EQUAL:
168326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthFunc = GL_EQUAL;
169326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
170326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_DEPTH_FUNC_NOTEQUAL:
171326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mDepthFunc = GL_NOTEQUAL;
172326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
173326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    }
174326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
175326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
176ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStore::setDepthMask(bool mask)
177326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
178326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mDepthWriteEnable = mask;
179326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
180326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
181ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst)
182326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
183326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mBlendEnable = true;
184cfb1d11ce6826fce7241d316d8b7dcab661f63a6Jason Sams    if ((src == RS_BLEND_SRC_ONE) &&
185326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        (dst == RS_BLEND_DST_ZERO)) {
186326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendEnable = false;
187326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    }
188326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
189326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    switch(src) {
190326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_ZERO:
191326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_ZERO;
192326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
193326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_ONE:
194326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_ONE;
195326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
196326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_DST_COLOR:
197326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_DST_COLOR;
198326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
199326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_ONE_MINUS_DST_COLOR:
200326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_ONE_MINUS_DST_COLOR;
201326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
202326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_SRC_ALPHA:
203326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_SRC_ALPHA;
204326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
205326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA:
206326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_ONE_MINUS_SRC_ALPHA;
207326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
208326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_DST_ALPHA:
209326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_DST_ALPHA;
210326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
211326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_ONE_MINUS_DST_ALPHA:
212326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_ONE_MINUS_DST_ALPHA;
213326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
214326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_SRC_SRC_ALPHA_SATURATE:
215326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendSrc = GL_SRC_ALPHA_SATURATE;
216326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
217326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    }
218326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
219326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    switch(dst) {
220326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_ZERO:
221326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_ZERO;
222326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
223326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_ONE:
224326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_ONE;
225326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
226326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_SRC_COLOR:
227326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_SRC_COLOR;
228326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
229326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_ONE_MINUS_SRC_COLOR:
230326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_ONE_MINUS_SRC_COLOR;
231326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
232326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_SRC_ALPHA:
233326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_SRC_ALPHA;
234326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
235326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_ONE_MINUS_SRC_ALPHA:
236326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_ONE_MINUS_SRC_ALPHA;
237326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
238326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_DST_ALPHA:
239326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_DST_ALPHA;
240326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
241326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    case RS_BLEND_DST_ONE_MINUS_DST_ALPHA:
242326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        mBlendDst = GL_ONE_MINUS_DST_ALPHA;
243326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams        break;
244326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    }
245326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
246326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
247ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStore::setColorMask(bool r, bool g, bool b, bool a)
248326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
249326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorRWriteEnable = r;
250326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorGWriteEnable = g;
251326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorBWriteEnable = b;
252326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mColorAWriteEnable = a;
253326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
254326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
255326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
256ccc010bb7c0f89e162bf60033968a20be90a903aJason SamsProgramStoreState::ProgramStoreState()
257326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
258326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mPFS = NULL;
259326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
260326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
261ccc010bb7c0f89e162bf60033968a20be90a903aJason SamsProgramStoreState::~ProgramStoreState()
262326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
263326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    delete mPFS;
264326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
265326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
266326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
267771565f47fc44608444c00aa8fa3bda769ceaeceJason Samsvoid ProgramStoreState::init(Context *rsc)
2688ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams{
269ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    ProgramStore *pfs = new ProgramStore(rsc);
2708ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams    mDefault.set(pfs);
2718ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams}
2728ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams
273ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid ProgramStoreState::deinit(Context *rsc)
274f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams{
275f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mDefault.clear();
276f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mLast.clear();
277f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams}
278f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams
279326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
280326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace android {
281326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace renderscript {
282326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
283ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid rsi_ProgramStoreBegin(Context * rsc, RsElement in, RsElement out)
284326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
285326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    delete rsc->mStateFragmentStore.mPFS;
286ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    rsc->mStateFragmentStore.mPFS = new ProgramStore(rsc);
287326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
288326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
289326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
290ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid rsi_ProgramStoreDepthFunc(Context *rsc, RsDepthFunc func)
291326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
292326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setDepthFunc(func);
293326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
294326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
295ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid rsi_ProgramStoreDepthMask(Context *rsc, bool mask)
296326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
297326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setDepthMask(mask);
298326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
299326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
300ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid rsi_ProgramStoreColorMask(Context *rsc, bool r, bool g, bool b, bool a)
301326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
302326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setColorMask(r, g, b, a);
303326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
304326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
305ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid rsi_ProgramStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc dst)
306326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
307326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setBlendFunc(src, dst);
308326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
309326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
310ccc010bb7c0f89e162bf60033968a20be90a903aJason SamsRsProgramStore rsi_ProgramStoreCreate(Context *rsc)
311326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
312ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    ProgramStore *pfs = rsc->mStateFragmentStore.mPFS;
3139397e30ce5fe3f6af9212a93b490836b04fdfffaJason Sams    pfs->incUserRef();
314326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS = 0;
315326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    return pfs;
316326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
317326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
318ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsvoid rsi_ProgramStoreDither(Context *rsc, bool enable)
319326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams{
320326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setDitherEnable(enable);
321326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
322326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
323326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
324326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
325326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
326