blob: 67184ffacc27cc3bd9bfee5c25a3141931adcbb0 [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 "rsComponent.h"
Jason Sams1bada8c2009-08-09 17:01:55 -070018#include <GLES/gl.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070019
20using namespace android;
21using namespace android::renderscript;
22
23
Jason Samsa9e7a052009-09-25 14:51:22 -070024Component::Component(Context *rsc) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -070025{
26 mType = FLOAT;
Jason Sams25ffcdc2009-08-20 16:10:36 -070027 mKind = USER;
Jason Samsd19f10d2009-05-22 14:03:28 -070028 mIsNormalized = false;
29 mBits = 0;
30}
31
Jason Samsa9e7a052009-09-25 14:51:22 -070032Component::Component(Context *rsc,
Jason Sams1bada8c2009-08-09 17:01:55 -070033 DataKind dk, DataType dt,
Jason Samsa9e7a052009-09-25 14:51:22 -070034 bool isNormalized, uint32_t bits, const char * name) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -070035{
36 mType = dt;
37 mKind = dk;
38 mIsNormalized = isNormalized;
39 mBits = bits;
Jason Sams43ee06852009-08-12 17:54:11 -070040 if (name) {
41 mName = name;
42 }
Jason Samsd19f10d2009-05-22 14:03:28 -070043}
44
Jason Samsfbf0b9e2009-08-13 12:59:04 -070045const char * Component::getCType() const
46{
47 switch(mType) {
48 case FLOAT:
49 return "float";
50 case SIGNED:
51 case UNSIGNED:
52 switch(mBits) {
53 case 32:
54 return "int";
55 case 16:
56 return "short";
57 case 8:
58 return "char";
59 }
60 break;
61 }
62 return NULL;
63}
64
Jason Samsd19f10d2009-05-22 14:03:28 -070065Component::~Component()
66{
67}
Jason Sams1bada8c2009-08-09 17:01:55 -070068
69uint32_t Component::getGLType() const
70{
71 switch(mType) {
72 case RS_TYPE_FLOAT:
73 rsAssert(mBits == 32);
74 return GL_FLOAT;
75 case RS_TYPE_SIGNED:
76 switch(mBits) {
77 case 32:
78 return 0;//GL_INT;
79 case 16:
80 return GL_SHORT;
81 case 8:
82 return GL_BYTE;
83 }
84 break;
85 case RS_TYPE_UNSIGNED:
86 switch(mBits) {
87 case 32:
88 return 0;//GL_UNSIGNED_INT;
89 case 16:
90 return GL_UNSIGNED_SHORT;
91 case 8:
92 return GL_UNSIGNED_BYTE;
93 }
94 break;
95 }
96 //rsAssert(!"Bad type");
97 //LOGE("mType %i, mKind %i, mBits %i, mIsNormalized %i", mType, mKind, mBits, mIsNormalized);
98 return 0;
99}
100
101