blob: de074c8ce664ed5e54e270586d0d21510fc99a2e [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 "rsComponent.h"
Jason Samse5ffb872009-08-09 17:01:55 -070018#include <GLES/gl.h>
Jason Sams326e0dd2009-05-22 14:03:28 -070019
20using namespace android;
21using namespace android::renderscript;
22
23
Jason Samse514b452009-09-25 14:51:22 -070024Component::Component(Context *rsc) : ObjectBase(rsc)
Jason Sams326e0dd2009-05-22 14:03:28 -070025{
Jason Samsf2649a92009-09-25 16:37:33 -070026 mAllocFile = __FILE__;
27 mAllocLine = __LINE__;
Jason Sams326e0dd2009-05-22 14:03:28 -070028 mType = FLOAT;
Jason Samse0158412009-08-20 16:10:36 -070029 mKind = USER;
Jason Sams326e0dd2009-05-22 14:03:28 -070030 mIsNormalized = false;
31 mBits = 0;
32}
33
Jason Samse514b452009-09-25 14:51:22 -070034Component::Component(Context *rsc,
Jason Samse5ffb872009-08-09 17:01:55 -070035 DataKind dk, DataType dt,
Jason Samse514b452009-09-25 14:51:22 -070036 bool isNormalized, uint32_t bits, const char * name) : ObjectBase(rsc)
Jason Sams326e0dd2009-05-22 14:03:28 -070037{
Jason Samsf2649a92009-09-25 16:37:33 -070038 mAllocFile = __FILE__;
39 mAllocLine = __LINE__;
Jason Sams326e0dd2009-05-22 14:03:28 -070040 mType = dt;
41 mKind = dk;
42 mIsNormalized = isNormalized;
43 mBits = bits;
Jason Sams8b2c0652009-08-12 17:54:11 -070044 if (name) {
45 mName = name;
46 }
Jason Sams326e0dd2009-05-22 14:03:28 -070047}
48
Jason Samsfa517192009-08-13 12:59:04 -070049const char * Component::getCType() const
50{
51 switch(mType) {
52 case FLOAT:
53 return "float";
54 case SIGNED:
55 case UNSIGNED:
56 switch(mBits) {
57 case 32:
58 return "int";
59 case 16:
60 return "short";
61 case 8:
62 return "char";
63 }
64 break;
65 }
66 return NULL;
67}
68
Jason Sams326e0dd2009-05-22 14:03:28 -070069Component::~Component()
70{
71}
Jason Samse5ffb872009-08-09 17:01:55 -070072
73uint32_t Component::getGLType() const
74{
75 switch(mType) {
76 case RS_TYPE_FLOAT:
77 rsAssert(mBits == 32);
78 return GL_FLOAT;
79 case RS_TYPE_SIGNED:
80 switch(mBits) {
81 case 32:
82 return 0;//GL_INT;
83 case 16:
84 return GL_SHORT;
85 case 8:
86 return GL_BYTE;
87 }
88 break;
89 case RS_TYPE_UNSIGNED:
90 switch(mBits) {
91 case 32:
92 return 0;//GL_UNSIGNED_INT;
93 case 16:
94 return GL_UNSIGNED_SHORT;
95 case 8:
96 return GL_UNSIGNED_BYTE;
97 }
98 break;
99 }
100 //rsAssert(!"Bad type");
101 //LOGE("mType %i, mKind %i, mBits %i, mIsNormalized %i", mType, mKind, mBits, mIsNormalized);
102 return 0;
103}
104
Jason Samse12c1c52009-09-27 17:50:38 -0700105void Component::dumpLOGV(const char *prefix) const
106{
107 ObjectBase::dumpLOGV(prefix);
108 LOGV("%s component: %i %i %i %i", prefix, mType, mKind, mIsNormalized, mBits);
109}
Jason Samse5ffb872009-08-09 17:01:55 -0700110