blob: bb07d296c5eebc0939cfb4e0dad12e8a2c125c4a [file] [log] [blame]
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -07001/*
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 Sakhartchouka9495242011-06-16 11:05:13 -070020#include "rsdFrameBufferObj.h"
Jason Samseb4fe182011-05-26 16:33:01 -070021#include "rsdAllocation.h"
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070022
23#include "rsContext.h"
24#include "rsFBOCache.h"
25
26#include <GLES2/gl2.h>
27#include <GLES2/gl2ext.h>
28
29using namespace android;
30using namespace android::renderscript;
31
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070032void setDepthAttachment(const Context *rsc, const FBOCache *fb) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070033 RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
Jason Samseb4fe182011-05-26 16:33:01 -070034
Alex Sakhartchouka9495242011-06-16 11:05:13 -070035 DrvAllocation *depth = NULL;
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070036 if (fb->mHal.state.depthTarget != NULL) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070037 depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv;
38
39 if (depth->uploadDeferred) {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070040 rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget,
Alex Sakhartchouka9495242011-06-16 11:05:13 -070041 RS_ALLOCATION_USAGE_SCRIPT);
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070042 }
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070043 }
Alex Sakhartchouka9495242011-06-16 11:05:13 -070044 fbo->setDepthTarget(depth);
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070045}
46
47void setColorAttachment(const Context *rsc, const FBOCache *fb) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070048 RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070049 // Now attach color targets
50 for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070051 DrvAllocation *color = NULL;
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070052 if (fb->mHal.state.colorTargets[i] != NULL) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070053 color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv;
Jason Samseb4fe182011-05-26 16:33:01 -070054
Alex Sakhartchouka9495242011-06-16 11:05:13 -070055 if (color->uploadDeferred) {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070056 rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i],
Alex Sakhartchouka9495242011-06-16 11:05:13 -070057 RS_ALLOCATION_USAGE_SCRIPT);
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070058 }
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070059 }
Alex Sakhartchouka9495242011-06-16 11:05:13 -070060 fbo->setColorTarget(color, i);
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070061 }
62}
63
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070064bool rsdFrameBufferInit(const Context *rsc, const FBOCache *fb) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070065 RsdFrameBufferObj *fbo = new RsdFrameBufferObj();
66 if (fbo == NULL) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070067 return false;
68 }
Alex Sakhartchouka9495242011-06-16 11:05:13 -070069 fb->mHal.drv = fbo;
70
71 RsdHal *dc = (RsdHal *)rsc->mHal.drv;
72 dc->gl.currentFrameBuffer = fbo;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070073
74 return true;
75}
76
77void rsdFrameBufferSetActive(const Context *rsc, const FBOCache *fb) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070078 setDepthAttachment(rsc, fb);
79 setColorAttachment(rsc, fb);
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070080
Alex Sakhartchouka9495242011-06-16 11:05:13 -070081 RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070082 if (fb->mHal.state.colorTargets[0]) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070083 fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(),
84 fb->mHal.state.colorTargets[0]->getType()->getDimY());
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070085 } else if (fb->mHal.state.depthTarget) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070086 fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(),
87 fb->mHal.state.depthTarget->getType()->getDimY());
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070088 }
Alex Sakhartchouka9495242011-06-16 11:05:13 -070089
90 fbo->setActive(rsc);
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070091}
92
93void rsdFrameBufferDestroy(const Context *rsc, const FBOCache *fb) {
Alex Sakhartchouka9495242011-06-16 11:05:13 -070094 RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
95 delete fbo;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070096 fb->mHal.drv = NULL;
97}
98
99