/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example custominstancing
    \ingroup quick3d-examples
    \title Qt Quick 3D - Custom Instanced Rendering
    \brief Demonstrates instancing with custom materials and a C++ instance table.
    \image custominstancing.jpg

    This example shows how to create instance data programmatically in C++, and how to use custom
    materials with instanced rendering.

    \section1 Custom instancing table

    We define our table as a subclass of \l {QQuick3DInstancing} and add some properties so we can
    control it from QML:

    \snippet custominstancing/cppinstancetable.h properties

    The virtual function \l {QQuick3DInstancing::getInstanceBuffer}{getInstanceBuffer} is
    reimplemented to return the instancing data:
    \snippet custominstancing/cppinstancetable.cpp getInstanceBuffer


    \section1 Custom material

    We use a shaded custom material, meaning that Qt gives us the basic implementation, and we just
    specify additional logic.

    The only customization we need for the vertex shader is for passing information to the fragment
    shader. By default, Qt only provides the instance data to the vertex shader, so we pass it on as
    \c vCustomData. We also calculate the global position of the vertex and make it available as \c
    vGlobalPosition.

    \quotefile custominstancing/cubeMaterial.vert

    The fragment shader performs a simple wave animation for water surfaces. Everything else gets a
    subtle radial gradient. The difference is determined by the first element of the custom data.

    \quotefile custominstancing/cubeMaterial.frag


    \section1 Using the custom table and material in QML

    We create a custom material using the shaders we made earlier, and add a new property \c uTime.
    This property is automatically mapped to the corresponding uniform in the fragment shader.

    \snippet custominstancing/main.qml material

    Finally, we create our model and apply the custom material and instance table:
    \snippet custominstancing/main.qml model

    Note that we only create a single cube: All the heavy lifting is done by the GPU.
*/
