Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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" |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 18 | #include <GLES/gl.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 19 | |
| 20 | using namespace android; |
| 21 | using namespace android::renderscript; |
| 22 | |
| 23 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 24 | Component::Component(Context *rsc) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 26 | mAllocFile = __FILE__; |
| 27 | mAllocLine = __LINE__; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | mType = FLOAT; |
Jason Sams | 25ffcdc | 2009-08-20 16:10:36 -0700 | [diff] [blame] | 29 | mKind = USER; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 30 | mIsNormalized = false; |
| 31 | mBits = 0; |
| 32 | } |
| 33 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 34 | Component::Component(Context *rsc, |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 35 | DataKind dk, DataType dt, |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 36 | bool isNormalized, uint32_t bits, const char * name) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 38 | mAllocFile = __FILE__; |
| 39 | mAllocLine = __LINE__; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | mType = dt; |
| 41 | mKind = dk; |
| 42 | mIsNormalized = isNormalized; |
| 43 | mBits = bits; |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 44 | if (name) { |
| 45 | mName = name; |
| 46 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 49 | 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 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 69 | Component::~Component() |
| 70 | { |
| 71 | } |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 72 | |
| 73 | 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 | |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 105 | 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 | } |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 110 | |