Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
| 18 | #include "rsdCore.h" |
| 19 | #include "rsdFrameBuffer.h" |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 20 | #include "rsdFrameBufferObj.h" |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 21 | #include "rsdAllocation.h" |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 22 | |
| 23 | #include "rsContext.h" |
| 24 | #include "rsFBOCache.h" |
| 25 | |
| 26 | #include <GLES2/gl2.h> |
| 27 | #include <GLES2/gl2ext.h> |
| 28 | |
| 29 | using namespace android; |
| 30 | using namespace android::renderscript; |
| 31 | |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 32 | void setDepthAttachment(const Context *rsc, const FBOCache *fb) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 33 | RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv; |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 34 | |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 35 | DrvAllocation *depth = NULL; |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 36 | if (fb->mHal.state.depthTarget != NULL) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 37 | depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv; |
| 38 | |
| 39 | if (depth->uploadDeferred) { |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 40 | rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget, |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 41 | RS_ALLOCATION_USAGE_SCRIPT); |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 42 | } |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 43 | } |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 44 | fbo->setDepthTarget(depth); |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void setColorAttachment(const Context *rsc, const FBOCache *fb) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 48 | RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv; |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 49 | // Now attach color targets |
| 50 | for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 51 | DrvAllocation *color = NULL; |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 52 | if (fb->mHal.state.colorTargets[i] != NULL) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 53 | color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv; |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 54 | |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 55 | if (color->uploadDeferred) { |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 56 | rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i], |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 57 | RS_ALLOCATION_USAGE_SCRIPT); |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 58 | } |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 59 | } |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 60 | fbo->setColorTarget(color, i); |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 64 | bool rsdFrameBufferInit(const Context *rsc, const FBOCache *fb) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 65 | RsdFrameBufferObj *fbo = new RsdFrameBufferObj(); |
| 66 | if (fbo == NULL) { |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 67 | return false; |
| 68 | } |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 69 | fb->mHal.drv = fbo; |
| 70 | |
| 71 | RsdHal *dc = (RsdHal *)rsc->mHal.drv; |
| 72 | dc->gl.currentFrameBuffer = fbo; |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | void rsdFrameBufferSetActive(const Context *rsc, const FBOCache *fb) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 78 | setDepthAttachment(rsc, fb); |
| 79 | setColorAttachment(rsc, fb); |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 80 | |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 81 | RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv; |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 82 | if (fb->mHal.state.colorTargets[0]) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 83 | fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(), |
| 84 | fb->mHal.state.colorTargets[0]->getType()->getDimY()); |
Alex Sakhartchouk | 5ef2f53 | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 85 | } else if (fb->mHal.state.depthTarget) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 86 | fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(), |
| 87 | fb->mHal.state.depthTarget->getType()->getDimY()); |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 88 | } |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 89 | |
| 90 | fbo->setActive(rsc); |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void rsdFrameBufferDestroy(const Context *rsc, const FBOCache *fb) { |
Alex Sakhartchouk | 8650c32 | 2011-06-16 11:05:13 -0700 | [diff] [blame] | 94 | RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv; |
| 95 | delete fbo; |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 96 | fb->mHal.drv = NULL; |
| 97 | } |
| 98 | |
| 99 | |