• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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"
18 #include <GLES/gl.h>
19 
20 using namespace android;
21 using namespace android::renderscript;
22 
23 
Component(Context * rsc)24 Component::Component(Context *rsc) : ObjectBase(rsc)
25 {
26     mAllocFile = __FILE__;
27     mAllocLine = __LINE__;
28     mType = FLOAT;
29     mKind = USER;
30     mIsNormalized = false;
31     mBits = 0;
32 }
33 
Component(Context * rsc,DataKind dk,DataType dt,bool isNormalized,uint32_t bits,const char * name)34 Component::Component(Context *rsc,
35     DataKind dk, DataType dt,
36     bool isNormalized, uint32_t bits, const char * name) : ObjectBase(rsc)
37 {
38     mAllocFile = __FILE__;
39     mAllocLine = __LINE__;
40     mType = dt;
41     mKind = dk;
42     mIsNormalized = isNormalized;
43     mBits = bits;
44     if (name) {
45         mName = name;
46     }
47 }
48 
getCType() const49 const 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 
~Component()69 Component::~Component()
70 {
71 }
72 
getGLType() const73 uint32_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 
dumpLOGV(const char * prefix) const105 void 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 }
110 
111