blob: 39d9a6f191fb053d4255c7ba35bf21a09cb42b3e [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_UI_LIB_ESCHER_PAPER_PAPER_SHADER_LIST_H_
#define SRC_UI_LIB_ESCHER_PAPER_PAPER_SHADER_LIST_H_
#include <lib/syslog/cpp/macros.h>
#include <array>
#include "src/ui/lib/escher/util/enum_cast.h"
#include "src/ui/lib/escher/util/enum_count.h"
namespace escher {
class ShaderProgram;
// Acts as an index into a PaperShaderList (see below).
// NOTE: if we wanted to reduce the size of PaperShaderList, we could reuse the same index
// for multiple shaders. For example, PaperDrawCallFactory currently emits separate draw calls for
// drawing shadow casters, and casting shadows from them. So we could make kShadowCaster == 0 if we
// wanted to. However, without more data, this would be a premature optimization.
enum class PaperShaderListSelector : uint8_t {
kAmbientLighting = 0,
kPointLighting = 1,
kShadowCaster = 2,
kShadowCasterDebug = 3,
kEnumCount
};
// Stores shaders that will be used by items enqueued in a PaperRenderQueue. These are generated by
// PaperDrawCallFactory, which is responsible for putting the right shader at the right index in the
// list. Later, when PaperRenderer tells the PaperRenderQueue to generate Vulkan commands, it will
// specify the selector used to choose a shader from the list.
class PaperShaderList {
public:
PaperShaderList() { shaders_.fill(nullptr); }
void set_shader(PaperShaderListSelector sel, ShaderProgram* prog) {
auto index = EnumCast(sel);
// It's OK to clear a shader to nullptr, but stomping on an existing shader is probably a
// programming error by the caller.
FX_DCHECK(prog == nullptr || shaders_[index] == nullptr);
shaders_[index] = prog;
}
ShaderProgram* get_shader(PaperShaderListSelector sel) const { return shaders_[EnumCast(sel)]; }
private:
std::array<ShaderProgram*, EnumCount<PaperShaderListSelector>()> shaders_;
};
} // namespace escher
#endif // SRC_UI_LIB_ESCHER_PAPER_PAPER_SHADER_LIST_H_