Previously, Cleanup is scoped to the testing function, which will go out of scope before BackendTest's destructor is called. We need to order the cleanup (destruction of resources) to after the readPixels and previous commands are complete - which is in the destructor of BackendTest. Additionally, we need to cleanup before the destruction of the driver. This means we need to be able to order the destruction of Cleanup (and not rely on RAII). This is done by having a unique_ptr holding a Cleanup instance.
80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
/*
|
|
* Copyright (C) 2022 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 "BackendTest.h"
|
|
|
|
#include "ImageExpectations.h"
|
|
#include "Lifetimes.h"
|
|
#include "Shader.h"
|
|
#include "SharedShaders.h"
|
|
#include "TrianglePrimitive.h"
|
|
|
|
namespace test {
|
|
|
|
using namespace filament;
|
|
using namespace filament::backend;
|
|
using namespace filament::math;
|
|
|
|
TEST_F(BackendTest, TestTemplate) {
|
|
constexpr int kRenderTargetSize = 512;
|
|
|
|
auto& api = getDriverApi();
|
|
auto swapChain = addCleanup(createSwapChain());
|
|
api.makeCurrent(swapChain, swapChain);
|
|
RenderTargetHandle renderTarget = addCleanup(api.createDefaultRenderTarget());
|
|
|
|
Shader shader = SharedShaders::makeShader(api, *mCleanup, ShaderRequest{
|
|
.mVertexType = VertexShaderType::Simple,
|
|
.mFragmentType = FragmentShaderType::SolidColored,
|
|
.mUniformType = ShaderUniformType::Simple,
|
|
});
|
|
TrianglePrimitive triangle(api);
|
|
|
|
RenderPassParams params = getClearColorRenderPass();
|
|
params.viewport = getFullViewport();
|
|
|
|
PipelineState ps = getColorWritePipelineState();
|
|
shader.addProgramToPipelineState(ps);
|
|
|
|
auto ubuffer = addCleanup(api.createBufferObject(sizeof(SimpleMaterialParams),
|
|
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
|
shader.uploadUniform(api, ubuffer, SimpleMaterialParams{
|
|
.color = float4(1, 0, 0, 1),
|
|
.scaleMinusOne = float4(0, 0, -0.5, 0),
|
|
.offset = float4(0, 0, 0, 0),
|
|
});
|
|
shader.bindUniform<SimpleMaterialParams>(api, ubuffer);
|
|
|
|
{
|
|
RenderFrame frame(api);
|
|
|
|
api.beginRenderPass(renderTarget, params);
|
|
ps.primitiveType = PrimitiveType::TRIANGLES;
|
|
ps.vertexBufferInfo = triangle.getVertexBufferInfo();
|
|
api.bindPipeline(ps);
|
|
api.bindRenderPrimitive(triangle.getRenderPrimitive());
|
|
api.draw2(0, 3, 1);
|
|
api.endRenderPass();
|
|
|
|
EXPECT_IMAGE(renderTarget,
|
|
ScreenshotParams(kRenderTargetSize, kRenderTargetSize, "TestTemplate", 1048576));
|
|
|
|
api.commit(swapChain);
|
|
}
|
|
}
|
|
|
|
} // namespace test
|