* API BREAKAGE: this change aims to fix multi-view support What has changed: - View doesn't have a notion of clear color anymore - View doesn't have a notion of discard flags anymore - The clear color and color-buffer discard/clear flags are moved to Renderer - Skybox can now be set to a constant color - View have a blend-mode What does is all mean: "Clearing" (i.e.) setting its background is now handled by Skybox, by setting a constant color to the Skybox. This should take care of drawing views side by side. When a view needs to be drawn on top of another, it's BlendMode needs to be set to TRANSLUCENT and of course and, generally, it wither won't have a skybox, or will have one that sets some translucent pixels. As an optimization, a View with BlendMode::OPAQUE will have its background cleared with the color specified in Renderer. If the SwapChain already has some content, it's now possible to set the Renderer to not discard the content, together with TRANSLUCENT views, it's possible to draw on top of that content. It is NOT possible to share depth/stencil buffers between views. Fixes: #2369, #2372, #2364 * Address reviewers comments. Note: WebGL is still broken with this PR
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
/*
|
|
* Copyright (C) 2018 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <filament/Engine.h>
|
|
#include <filament/View.h>
|
|
#include <filament/Scene.h>
|
|
#include <filament/Skybox.h>
|
|
|
|
#include <filamentapp/Config.h>
|
|
#include <filamentapp/FilamentApp.h>
|
|
|
|
#include <cmath>
|
|
|
|
using namespace filament;
|
|
|
|
int main(int argc, char** argv) {
|
|
Config config;
|
|
config.title = "strobecolor";
|
|
config.backend = Engine::Backend::VULKAN;
|
|
Skybox* skybox;
|
|
|
|
auto setup = [&skybox](Engine* engine, View* view, Scene* scene) {
|
|
skybox = Skybox::Builder().color({ 0.0, 0.25, 0.5, 1.0 }).build(*engine);
|
|
scene->setSkybox(skybox);
|
|
view->setPostProcessingEnabled(false);
|
|
};
|
|
|
|
auto cleanup = [](Engine*, View*, Scene*) {
|
|
};
|
|
|
|
FilamentApp::get().animate([skybox](Engine*, View* view, double now) {
|
|
constexpr float SPEED = 4;
|
|
float r = 0.5f + 0.5f * std::sin(SPEED * now);
|
|
float g = 0.5f + 0.5f * std::sin(SPEED * now + M_PI * 2 / 3);
|
|
float b = 0.5f + 0.5f * std::sin(SPEED * now + M_PI * 4 / 3);
|
|
skybox->setColor({r, g, b, 1.0});
|
|
});
|
|
|
|
FilamentApp::get().run(config, setup, cleanup);
|
|
|
|
return 0;
|
|
}
|