Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [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 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 18 | #include "rsContext.h" |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 19 | #include <GLES/gl.h> |
| 20 | #include <GLES2/gl2.h> |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 21 | #else |
| 22 | #include "rsContextHostStub.h" |
| 23 | #include <OpenGL/gl.h> |
| 24 | #endif |
| 25 | |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 26 | |
| 27 | using namespace android; |
| 28 | using namespace android::renderscript; |
| 29 | |
| 30 | |
Alex Sakhartchouk | 54929cc | 2010-11-08 15:10:52 -0800 | [diff] [blame^] | 31 | VertexArray::VertexArray(const Attrib *attribs, uint32_t numAttribs) |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 32 | { |
Alex Sakhartchouk | 54929cc | 2010-11-08 15:10:52 -0800 | [diff] [blame^] | 33 | mAttribs = attribs; |
| 34 | mCount = numAttribs; |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | VertexArray::~VertexArray() |
| 38 | { |
| 39 | } |
| 40 | |
Jason Sams | 433eca3 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 41 | VertexArray::Attrib::Attrib() |
| 42 | { |
| 43 | clear(); |
| 44 | } |
| 45 | |
Jason Sams | 433eca3 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 46 | void VertexArray::Attrib::clear() |
| 47 | { |
| 48 | buffer = 0; |
| 49 | offset = 0; |
| 50 | type = 0; |
| 51 | size = 0; |
| 52 | stride = 0; |
Jason Sams | 590549f | 2010-06-30 12:07:41 -0700 | [diff] [blame] | 53 | ptr = NULL; |
Jason Sams | 433eca3 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 54 | normalized = false; |
| 55 | name.setTo(""); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Alex Sakhartchouk | 54929cc | 2010-11-08 15:10:52 -0800 | [diff] [blame^] | 58 | void VertexArray::Attrib::set(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name) |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 59 | { |
Alex Sakhartchouk | 54929cc | 2010-11-08 15:10:52 -0800 | [diff] [blame^] | 60 | clear(); |
| 61 | this->type = type; |
| 62 | this->size = size; |
| 63 | this->offset = offset; |
| 64 | this->normalized = normalized; |
| 65 | this->stride = stride; |
| 66 | this->name.setTo(name); |
Jason Sams | 433eca3 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void VertexArray::logAttrib(uint32_t idx, uint32_t slot) const { |
Alex Sakhartchouk | 886f11a | 2010-09-29 09:49:13 -0700 | [diff] [blame] | 70 | if(idx == 0) { |
| 71 | LOGV("Starting vertex attribute binding"); |
| 72 | } |
| 73 | LOGV("va %i: slot=%i name=%s buf=%i ptr=%p size=%i type=0x%x stride=0x%x norm=%i offset=0x%x", |
| 74 | idx, slot, |
Jason Sams | 433eca3 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 75 | mAttribs[idx].name.string(), |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 76 | mAttribs[idx].buffer, |
Jason Sams | 760f1f7 | 2010-06-25 12:45:41 -0700 | [diff] [blame] | 77 | mAttribs[idx].ptr, |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 78 | mAttribs[idx].size, |
| 79 | mAttribs[idx].type, |
| 80 | mAttribs[idx].stride, |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 81 | mAttribs[idx].normalized, |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 82 | mAttribs[idx].offset); |
| 83 | } |
| 84 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 85 | void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, ShaderCache *sc) const |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 86 | { |
Jason Sams | 3eb28f0 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 87 | rsc->checkError("VertexArray::setupGL2 start"); |
Jason Sams | 79f52df | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 88 | for (uint32_t ct=1; ct <= 0xf/*state->mLastEnableCount*/; ct++) { |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 89 | glDisableVertexAttribArray(ct); |
| 90 | } |
| 91 | |
Jason Sams | 3eb28f0 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 92 | rsc->checkError("VertexArray::setupGL2 disabled"); |
Jason Sams | be504f2 | 2010-01-25 12:31:24 -0800 | [diff] [blame] | 93 | for (uint32_t ct=0; ct < mCount; ct++) { |
Alex Sakhartchouk | 886f11a | 2010-09-29 09:49:13 -0700 | [diff] [blame] | 94 | int32_t slot = sc->vtxAttribSlot(mAttribs[ct].name); |
| 95 | if(rsc->props.mLogShadersAttr) { |
| 96 | logAttrib(ct, slot); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 97 | } |
Alex Sakhartchouk | af83e79 | 2010-08-27 16:10:55 -0700 | [diff] [blame] | 98 | if(slot < 0) { |
| 99 | continue; |
| 100 | } |
Jason Sams | be504f2 | 2010-01-25 12:31:24 -0800 | [diff] [blame] | 101 | glEnableVertexAttribArray(slot); |
| 102 | glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer); |
Jason Sams | be504f2 | 2010-01-25 12:31:24 -0800 | [diff] [blame] | 103 | glVertexAttribPointer(slot, |
| 104 | mAttribs[ct].size, |
| 105 | mAttribs[ct].type, |
| 106 | mAttribs[ct].normalized, |
| 107 | mAttribs[ct].stride, |
Jason Sams | 760f1f7 | 2010-06-25 12:45:41 -0700 | [diff] [blame] | 108 | mAttribs[ct].ptr + mAttribs[ct].offset); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 109 | } |
Jason Sams | 3eb28f0 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 110 | state->mLastEnableCount = mCount; |
| 111 | rsc->checkError("VertexArray::setupGL2 done"); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 112 | } |
| 113 | //////////////////////////////////////////// |
| 114 | |
| 115 | void VertexArrayState::init(Context *) { |
Jason Sams | 3eb28f0 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 116 | mLastEnableCount = 0; |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 117 | } |
| 118 | |