blob: fc26ab50ee917017de0167493d689f5892603f8c [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "rsContext.h"
18#include "rsProgramVertex.h"
19
20using namespace android;
21using namespace android::renderscript;
22
23
24ProgramVertex::ProgramVertex(Element *in, Element *out) :
25 Program(in, out)
26{
27 mTextureMatrixEnable = false;
28 mProjectionEnable = false;
29 mTransformEnable = false;
30}
31
32ProgramVertex::~ProgramVertex()
33{
34}
35
36void ProgramVertex::setupGL()
37{
38 const float *f = static_cast<const float *>(mConstants[0]->getPtr());
39
40 glMatrixMode(GL_TEXTURE);
41 if (mTextureMatrixEnable) {
42 glLoadMatrixf(&f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET]);
43 } else {
44 glLoadIdentity();
45 }
46
47
48 glMatrixMode(GL_PROJECTION);
49 if (mProjectionEnable) {
Jason Sams0826a6f2009-06-15 19:04:56 -070050 glLoadMatrixf(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
Jason Samsd19f10d2009-05-22 14:03:28 -070051 } else {
52 }
53
54 glMatrixMode(GL_MODELVIEW);
55 if (mTransformEnable) {
56 glLoadMatrixf(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]);
57 } else {
58 glLoadIdentity();
59 }
Jason Samsd19f10d2009-05-22 14:03:28 -070060}
61
62void ProgramVertex::setConstantType(uint32_t slot, const Type *t)
63{
64 mConstantTypes[slot].set(t);
65}
66
67void ProgramVertex::bindAllocation(uint32_t slot, Allocation *a)
68{
69 mConstants[slot].set(a);
70}
71
72
73ProgramVertexState::ProgramVertexState()
74{
75 mPV = NULL;
76}
77
78ProgramVertexState::~ProgramVertexState()
79{
80 delete mPV;
81}
82
83
84
85namespace android {
86namespace renderscript {
87
88void rsi_ProgramVertexBegin(Context *rsc, RsElement in, RsElement out)
89{
90 delete rsc->mStateVertex.mPV;
91 rsc->mStateVertex.mPV = new ProgramVertex((Element *)in, (Element *)out);
92}
93
94RsProgramVertex rsi_ProgramVertexCreate(Context *rsc)
95{
96 ProgramVertex *pv = rsc->mStateVertex.mPV;
97 pv->incRef();
98 rsc->mStateVertex.mPV = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -070099 return pv;
100}
101
102void rsi_ProgramVertexBindAllocation(Context *rsc, RsProgramVertex vpgm, uint32_t slot, RsAllocation constants)
103{
104 ProgramVertex *pv = static_cast<ProgramVertex *>(vpgm);
105 pv->bindAllocation(slot, static_cast<Allocation *>(constants));
106}
107
108void rsi_ProgramVertexSetType(Context *rsc, uint32_t slot, RsType constants)
109{
110 rsc->mStateVertex.mPV->setConstantType(slot, static_cast<const Type *>(constants));
111}
112
113void rsi_ProgramVertexSetCameraMode(Context *rsc, bool ortho)
114{
115 rsc->mStateVertex.mPV->setProjectionEnabled(!ortho);
116}
117
118void rsi_ProgramVertexSetTextureMatrixEnable(Context *rsc, bool enable)
119{
120 rsc->mStateVertex.mPV->setTextureMatrixEnable(enable);
121}
122
123void rsi_ProgramVertexSetModelMatrixEnable(Context *rsc, bool enable)
124{
125 rsc->mStateVertex.mPV->setTransformEnable(enable);
126}
127
Jason Sams0826a6f2009-06-15 19:04:56 -0700128void rsi_ProgramVertexSetProjectionMatrixEnable(Context *rsc, bool enable)
129{
130 rsc->mStateVertex.mPV->setProjectionEnable(enable);
131}
132
Jason Samsd19f10d2009-05-22 14:03:28 -0700133
134
135}
136}