blob: c5c64c27b6027a6a81972b9b3982e1bcdb91ea89 [file] [log] [blame]
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -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#include "rsFBOCache.h"
18
19#include "rsContext.h"
20#include "rsAllocation.h"
21
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070022using namespace android;
23using namespace android::renderscript;
24
25
26FBOCache::FBOCache() {
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070027 mDirty = true;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070028 mHal.state.colorTargetsCount = 1;
29 mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070030}
31
32FBOCache::~FBOCache() {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070033 delete[] mHal.state.colorTargets;
34}
35
36void FBOCache::init(Context *rsc) {
37 rsc->mHal.funcs.framebuffer.init(rsc, this);
38}
39
40void FBOCache::deinit(Context *rsc) {
41 rsc->mHal.funcs.framebuffer.destroy(rsc, this);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070042}
43
44void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070045 if (slot >= mHal.state.colorTargetsCount) {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070046 LOGE("Invalid render target index");
47 return;
48 }
49 if (a != NULL) {
50 if (!a->getIsTexture()) {
51 LOGE("Invalid Color Target");
52 return;
53 }
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070054 }
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070055 mHal.state.colorTargets[slot].set(a);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070056 mDirty = true;
57}
58
59void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
60 if (a != NULL) {
61 if (!a->getIsRenderTarget()) {
62 LOGE("Invalid Depth Target");
63 return;
64 }
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070065 }
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070066 mHal.state.depthTarget.set(a);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070067 mDirty = true;
68}
69
70void FBOCache::resetAll(Context *) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070071 for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
72 mHal.state.colorTargets[i].set(NULL);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070073 }
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070074 mHal.state.depthTarget.set(NULL);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070075 mDirty = true;
76}
77
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070078void FBOCache::setup(Context *rsc) {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070079 if (!mDirty) {
80 return;
81 }
82
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070083 rsc->mHal.funcs.framebuffer.setActive(rsc, this);
84
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070085 mDirty = false;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070086}