目标:(九十五)中的问题177
RenderBindings用于声明rex引擎要渲染哪些种类的图层信息,比如影像、父影像、高程、法线等,只指定绑定类别,对每一个绑定类别都会设置其对应的采样器、偏移矩阵、纹理单元号,在rex的setupRenderBindings中有详细描述。
RenderingPasses用于声明rex实际有哪些图层要渲染,这里的图层中,同一类型的可能有多个,比如多个影像层、多个高层层,想象以下earth文件中配置的image、elevation等,每一个都会对应一个这里的通道RenderingPass,通过会存放实际渲染要用到的纹理、纹理矩阵,纹理会上传到上面RenderBindings中为每类图层分配的gpu显存中,供渲染使用。
RenderBindings属于rex引擎使用的对象,相当于全局对象,告知rex引擎中的其它部分,绑定类别有哪些,是如何设置的。
RenderingPasses属于每个瓦片使用的对象,只是该瓦片在生命周期中会使用,存放瓦片相关的影像、高程数据。
RenderBindings的声明如下:
osgEarthDrivers/engine_rex/RenderBindings
class SamplerBinding
{
public:
enum Usage
{
COLOR = 0,
COLOR_PARENT = 1,
ELEVATION = 2,
NORMAL = 3,
COVERAGE = 4,
SHARED = 5 // non-core shared layers start at this index
};
public:
SamplerBinding() : _unit(-1) { }
/** Optional UID of the source (usually a layer) to which this binding applies */
optional<osgEarth::UID>& sourceUID() { return _sourceUID; }
const optional<osgEarth::UID>& sourceUID() const { return _sourceUID; }
/** Optional usage hint */
optional<Usage>& usage() { return _usage; }
const optional<Usage>& usage() const { return _usage; }
/** Texture image unit of the sampler */
int& unit() { return _unit; }
const int& unit() const { return _unit; }
/** Uniform name of the sampler */
std::string& samplerName() { return _samplerName; }
const std::string& samplerName() const { return _samplerName; }
/** Uniform name of the sampler matrix */
std::string& matrixName() { return _matrixName; }
const std::string& matrixName() const { return _matrixName; }
public:
/** True if this binding is bound to a teture image unit and therefore active. */
bool isActive() const { return _unit >= 0; }
private:
optional<UID> _sourceUID;
optional<Usage> _usage;
int _unit;
std::string _samplerName;
std::string _matrixName;
};
typedef AutoArray<SamplerBinding> RenderBindings;
RenderingPasses的声明如下:
osgEarthDrivers/engine_rex/TileRenderModel
/**
* Samplers (one per RenderBinding) specific to one rendering pass of a tile.
* Typically this is just the color and color parent samplers.
*/
struct RenderingPass
{
public:
RenderingPass() :
_sourceUID(-1),
_samplers(SamplerBinding::COLOR_PARENT+1),
_visibleLayer(0L)
{ }
UID sourceUID() const { return _sourceUID; }
Samplers& samplers() { return _samplers; }
const Samplers& samplers() const { return _samplers; }
const Layer* layer() const { return _layer.get(); }
const VisibleLayer* visibleLayer() const { return _visibleLayer; }
void releaseGLObjects(osg::State* state) const
{
for (unsigned s = 0; s<_samplers.size(); ++s)
if (_samplers[s]._texture.valid() && _samplers[s]._matrix.isIdentity())
_samplers[s]._texture->releaseGLObjects(state);
}
void resizeGLObjectBuffers(unsigned size)
{
for (unsigned s =