blob: c24f2281e12ac1aefcb18dcc5348b652b8dc249f [file] [log] [blame]
Jason Sams326e0dd2009-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;
Jason Sams326e0dd2009-05-22 14:03:28 -070028}
29
30ProgramVertex::~ProgramVertex()
31{
32}
33
Jason Sams56bc1af2009-06-16 17:49:58 -070034static void logMatrix(const char *txt, const float *f)
35{
36 LOGE("Matrix %s, %p", txt, f);
37 LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[0], f[4], f[8], f[12]);
38 LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[1], f[5], f[9], f[13]);
39 LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[2], f[6], f[10], f[14]);
40 LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[3], f[7], f[11], f[15]);
41}
42
Jason Sams326e0dd2009-05-22 14:03:28 -070043void ProgramVertex::setupGL()
44{
45 const float *f = static_cast<const float *>(mConstants[0]->getPtr());
46
47 glMatrixMode(GL_TEXTURE);
48 if (mTextureMatrixEnable) {
49 glLoadMatrixf(&f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET]);
50 } else {
51 glLoadIdentity();
52 }
53
Jason Sams56bc1af2009-06-16 17:49:58 -070054 //logMatrix("prog", &f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
55 //logMatrix("model", &f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]);
Jason Sams326e0dd2009-05-22 14:03:28 -070056
57 glMatrixMode(GL_PROJECTION);
Jason Sams56bc1af2009-06-16 17:49:58 -070058 glLoadMatrixf(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
Jason Sams326e0dd2009-05-22 14:03:28 -070059 glMatrixMode(GL_MODELVIEW);
Jason Sams56bc1af2009-06-16 17:49:58 -070060 glLoadMatrixf(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]);
Jason Sams326e0dd2009-05-22 14:03:28 -070061}
62
63void ProgramVertex::setConstantType(uint32_t slot, const Type *t)
64{
65 mConstantTypes[slot].set(t);
66}
67
68void ProgramVertex::bindAllocation(uint32_t slot, Allocation *a)
69{
70 mConstants[slot].set(a);
71}
72
73
74ProgramVertexState::ProgramVertexState()
75{
76 mPV = NULL;
77}
78
79ProgramVertexState::~ProgramVertexState()
80{
81 delete mPV;
82}
83
84
85
86namespace android {
87namespace renderscript {
88
89void rsi_ProgramVertexBegin(Context *rsc, RsElement in, RsElement out)
90{
91 delete rsc->mStateVertex.mPV;
92 rsc->mStateVertex.mPV = new ProgramVertex((Element *)in, (Element *)out);
93}
94
95RsProgramVertex rsi_ProgramVertexCreate(Context *rsc)
96{
97 ProgramVertex *pv = rsc->mStateVertex.mPV;
98 pv->incRef();
99 rsc->mStateVertex.mPV = 0;
Jason Sams326e0dd2009-05-22 14:03:28 -0700100 return pv;
101}
102
103void rsi_ProgramVertexBindAllocation(Context *rsc, RsProgramVertex vpgm, uint32_t slot, RsAllocation constants)
104{
105 ProgramVertex *pv = static_cast<ProgramVertex *>(vpgm);
106 pv->bindAllocation(slot, static_cast<Allocation *>(constants));
107}
108
109void rsi_ProgramVertexSetType(Context *rsc, uint32_t slot, RsType constants)
110{
111 rsc->mStateVertex.mPV->setConstantType(slot, static_cast<const Type *>(constants));
112}
113
Jason Sams326e0dd2009-05-22 14:03:28 -0700114void rsi_ProgramVertexSetTextureMatrixEnable(Context *rsc, bool enable)
115{
116 rsc->mStateVertex.mPV->setTextureMatrixEnable(enable);
117}
118
Jason Sams326e0dd2009-05-22 14:03:28 -0700119
120
121}
122}