/usr/share/qt5/doc/qtquick/qsgsimplematerialshader.html is in qtdeclarative5-doc-html 5.9.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qsgsimplematerial.cpp -->
<title>QSGSimpleMaterialShader Class | Qt Quick 5.9</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<table><tr>
<td >Qt 5.9</td><td ><a href="qtquick-index.html">Qt Quick</a></td><td ><a href="qtquick-module.html">C++ Classes</a></td><td >QSGSimpleMaterialShader</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
</tr></table>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#macros">Macros</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QSGSimpleMaterialShader Class</h1>
<!-- $$$QSGSimpleMaterialShader-brief -->
<p>The <a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a> class provides a convenient way of building custom OpenGL-based materials for the scene graph. <a href="#details">More...</a></p>
<!-- @@@QSGSimpleMaterialShader -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QSGSimpleMaterialShader></span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += quick</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qsgmaterialshader.html">QSGMaterialShader</a></td></tr></table></div><ul>
<li><a href="qsgsimplematerialshader-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual QList<QByteArray> </td><td class="memItemRight bottomAlign"><b><a href="qsgsimplematerialshader.html#attributes">attributes</a></b>() const = 0</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qsgsimplematerialshader.html#resolveUniforms">resolveUniforms</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const char *</td><td class="memItemRight bottomAlign"><b><a href="qsgsimplematerialshader.html#uniformMatrixName">uniformMatrixName</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const char *</td><td class="memItemRight bottomAlign"><b><a href="qsgsimplematerialshader.html#uniformOpacityName">uniformOpacityName</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qsgsimplematerialshader.html#updateState">updateState</a></b>(const State *<i>newState</i>, const State *<i>oldState</i>) = 0</td></tr>
</table></div>
<ul>
<li class="fn">5 public functions inherited from <a href="qsgmaterialshader.html#public-functions">QSGMaterialShader</a></li>
</ul>
<a name="macros"></a>
<h2 id="macros">Macros</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qsgsimplematerialshader.html#QSG_DECLARE_SIMPLE_COMPARABLE_SHADER">QSG_DECLARE_SIMPLE_COMPARABLE_SHADER</a></b>(<i>Shader</i>, <i>State</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qsgsimplematerialshader.html#QSG_DECLARE_SIMPLE_SHADER">QSG_DECLARE_SIMPLE_SHADER</a></b>(<i>Shader</i>, <i>State</i>)</td></tr>
</table></div>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">6 protected functions inherited from <a href="qsgmaterialshader.html#protected-functions">QSGMaterialShader</a></li>
</ul>
<a name="details"></a>
<!-- $$$QSGSimpleMaterialShader-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a> class provides a convenient way of building custom OpenGL-based materials for the scene graph.</p>
<p><b>Warning:</b> This utility class is only functional when running with the OpenGL backend of the Qt Quick scenegraph.</p>
<p>Where the <a href="qsgmaterial.html">QSGMaterial</a> and <a href="qsgmaterialshader.html">QSGMaterialShader</a> API requires a bit of boilerplate code to create a functioning material, the <a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a> tries to hide some of this through the use of templates.</p>
<p><a href="qsgmaterialshader.html#vertexShader">QSGSimpleMaterialShader::vertexShader</a>() and <a href="qsgmaterialshader.html#fragmentShader">QSGSimpleMaterialShader::fragmentShader</a>() are used to specify the actual shader source code. The names of the vertex attributes should be listed in the <a href="qsgsimplematerialshader.html#attributes">QSGSimpleMaterialShader::attributes</a>()</p>
<p><a href="qsgsimplematerialshader.html#updateState">QSGSimpleMaterialShader::updateState</a>() is used to push the material state to the OpenGL shader program.</p>
<p>The actual OpenGL shader program is accessible through the <a href="qsgmaterialshader.html#program">QSGSimpleMaterialShader::program</a>() function.</p>
<p>Each <a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a> implementation operates on a unique state struct. The state struct must be declared using the <code>QSG_DECLARE_SIMPLE_SHADER</code> macro.</p>
<p>Here is a simple example of a custom solid-color:</p>
<pre class="cpp">
<span class="keyword">struct</span> Color
{
<span class="type">float</span> r<span class="operator">,</span> g<span class="operator">,</span> b<span class="operator">,</span> a;
};
<span class="keyword">class</span> MinimalShader : <span class="keyword">public</span> <span class="type"><a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a></span><span class="operator"><</span>Color<span class="operator">></span>
{
QSG_DECLARE_SIMPLE_SHADER(MinimalShader<span class="operator">,</span> Color)
<span class="keyword">public</span>:
<span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>vertexShader() <span class="keyword">const</span> {
<span class="keyword">return</span>
<span class="string">"attribute highp vec4 vertex; \n"</span>
<span class="string">"uniform highp mat4 qt_Matrix; \n"</span>
<span class="string">"void main() { \n"</span>
<span class="string">" gl_Position = qt_Matrix * vertex; \n"</span>
<span class="string">"}"</span>;
}
<span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>fragmentShader() <span class="keyword">const</span> {
<span class="keyword">return</span>
<span class="string">"uniform lowp float qt_Opacity; \n"</span>
<span class="string">"uniform lowp vec4 color; \n"</span>
<span class="string">"void main() { \n"</span>
<span class="string">" gl_FragColor = color * qt_Opacity; \n"</span>
<span class="string">"}"</span>;
}
<span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span><span class="operator">></span> attributes() <span class="keyword">const</span> {
<span class="keyword">return</span> <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span><span class="operator">></span>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"vertex"</span>;
}
<span class="type">void</span> updateState(<span class="keyword">const</span> Color <span class="operator">*</span>color<span class="operator">,</span> <span class="keyword">const</span> Color <span class="operator">*</span>) {
program()<span class="operator">-</span><span class="operator">></span>setUniformValue(<span class="string">"color"</span><span class="operator">,</span> color<span class="operator">-</span><span class="operator">></span>r<span class="operator">,</span> color<span class="operator">-</span><span class="operator">></span>g<span class="operator">,</span> color<span class="operator">-</span><span class="operator">></span>b<span class="operator">,</span> color<span class="operator">-</span><span class="operator">></span>a);
}
};
</pre>
<p>Instances of materials using this shader can be created using the createMaterial() function which will be defined by the <a href="qsgsimplematerialshader.html#QSG_DECLARE_SIMPLE_SHADER">QSG_DECLARE_SIMPLE_SHADER</a> macro.</p>
<pre class="cpp">
<span class="type"><a href="qsgsimplematerial.html">QSGSimpleMaterial</a></span><span class="operator"><</span>Color<span class="operator">></span> <span class="operator">*</span>material <span class="operator">=</span> MinimalShader<span class="operator">::</span>createMaterial();
material<span class="operator">-</span><span class="operator">></span>state()<span class="operator">-</span><span class="operator">></span>r <span class="operator">=</span> <span class="number">1</span>;
material<span class="operator">-</span><span class="operator">></span>state()<span class="operator">-</span><span class="operator">></span>g <span class="operator">=</span> <span class="number">0</span>;
material<span class="operator">-</span><span class="operator">></span>state()<span class="operator">-</span><span class="operator">></span>b <span class="operator">=</span> <span class="number">0</span>;
material<span class="operator">-</span><span class="operator">></span>state()<span class="operator">-</span><span class="operator">></span>a <span class="operator">=</span> <span class="number">1</span>;
node<span class="operator">-</span><span class="operator">></span>setMaterial(material);
</pre>
<p>The scene graph will often try to find materials that have the same or at least similar state so that these can be batched together inside the renderer, which gives better performance. To specify sortable material states, use <a href="qsgsimplematerialshader.html#QSG_DECLARE_SIMPLE_COMPARABLE_SHADER">QSG_DECLARE_SIMPLE_COMPARABLE_SHADER</a> instead of <a href="qsgsimplematerialshader.html#QSG_DECLARE_SIMPLE_SHADER">QSG_DECLARE_SIMPLE_SHADER</a>. The state struct must then also define the function:</p>
<pre class="cpp">
<span class="type">int</span> compare(<span class="keyword">const</span> Type <span class="operator">*</span>other) <span class="keyword">const</span>;
</pre>
<p><b>Warning:</b> The <a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a> relies on template instantiation to create a <a href="qsgmaterialtype.html">QSGMaterialType</a> which the scene graph renderer internally uses to identify this shader. For this reason, the unique <a href="qsgsimplematerialshader.html">QSGSimpleMaterialShader</a> implementation must be instantiated with a unique C++ type.</p>
<p><b>Note: </b>All classes with QSG prefix should be used solely on the scene graph's rendering thread. See <a href="qtquick-visualcanvas-scenegraph.html#scene-graph-and-rendering">Scene Graph and Rendering</a> for more information.</p></div>
<p><b>See also </b><a href="qtquick-scenegraph-simplematerial-example.html">Scene Graph - Simple Material</a>.</p>
<!-- @@@QSGSimpleMaterialShader -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$attributes[overload1]$$$attributes -->
<h3 class="fn" id="attributes"><a name="attributes"></a><code>[pure virtual] </code><span class="type"><a href="../qtcore/qlist.html">QList</a></span><<span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span>> QSGSimpleMaterialShader::<span class="name">attributes</span>() const</h3>
<p>Returns a list of names, declaring the vertex attributes in the vertex shader.</p>
<!-- @@@attributes -->
<!-- $$$resolveUniforms[overload1]$$$resolveUniforms -->
<h3 class="fn" id="resolveUniforms"><a name="resolveUniforms"></a><code>[virtual] </code><span class="type">void</span> QSGSimpleMaterialShader::<span class="name">resolveUniforms</span>()</h3>
<p>Reimplement this function to resolve the location of named uniforms in the shader program.</p>
<p>This function is called when the material shader is initialized.</p>
<!-- @@@resolveUniforms -->
<!-- $$$uniformMatrixName[overload1]$$$uniformMatrixName -->
<h3 class="fn" id="uniformMatrixName"><a name="uniformMatrixName"></a>const <span class="type">char</span> *QSGSimpleMaterialShader::<span class="name">uniformMatrixName</span>() const</h3>
<p>Returns the name for the transform matrix uniform of this item. The default value is <code>qt_Matrix</code>.</p>
<!-- @@@uniformMatrixName -->
<!-- $$$uniformOpacityName[overload1]$$$uniformOpacityName -->
<h3 class="fn" id="uniformOpacityName"><a name="uniformOpacityName"></a>const <span class="type">char</span> *QSGSimpleMaterialShader::<span class="name">uniformOpacityName</span>() const</h3>
<p>Returns the name for the opacity uniform of this item. The default value is <code>qt_Opacity</code>.</p>
<!-- @@@uniformOpacityName -->
<!-- $$$updateState[overload1]$$$updateStateconstState*constState* -->
<h3 class="fn" id="updateState"><a name="updateState"></a><code>[pure virtual] </code><span class="type">void</span> QSGSimpleMaterialShader::<span class="name">updateState</span>(const <span class="type">State</span> *<i>newState</i>, const <span class="type">State</span> *<i>oldState</i>)</h3>
<p>Called whenever the state of this shader should be updated from <i>oldState</i> to <i>newState</i>, typical for each new set of geometries being drawn.</p>
<p>Both the old and the new state are passed in so that the implementation can compare and minimize the state changes when applicable.</p>
<!-- @@@updateState -->
</div>
<div class="macros">
<h2>Macro Documentation</h2>
<!-- $$$QSG_DECLARE_SIMPLE_COMPARABLE_SHADER[overload1]$$$QSG_DECLARE_SIMPLE_COMPARABLE_SHADER -->
<h3 class="fn" id="QSG_DECLARE_SIMPLE_COMPARABLE_SHADER"><a name="QSG_DECLARE_SIMPLE_COMPARABLE_SHADER"></a><span class="name">QSG_DECLARE_SIMPLE_COMPARABLE_SHADER</span>(<i>Shader</i>, <i>State</i>)</h3>
<p>This macro is used to declare a <a href="qsgmaterialtype.html">QSGMaterialType</a> and a <code>createMaterial()</code> function for <i>Shader</i> with the given <i>State</i>, where the <i>State</i> class must define a compare function on the form:</p>
<pre class="cpp">
<span class="type">int</span> compare(<span class="keyword">const</span> State <span class="operator">*</span>other) <span class="keyword">const</span>;
</pre>
<!-- @@@QSG_DECLARE_SIMPLE_COMPARABLE_SHADER -->
<!-- $$$QSG_DECLARE_SIMPLE_SHADER[overload1]$$$QSG_DECLARE_SIMPLE_SHADER -->
<h3 class="fn" id="QSG_DECLARE_SIMPLE_SHADER"><a name="QSG_DECLARE_SIMPLE_SHADER"></a><span class="name">QSG_DECLARE_SIMPLE_SHADER</span>(<i>Shader</i>, <i>State</i>)</h3>
<p>This macro is used to declare a <a href="qsgmaterialtype.html">QSGMaterialType</a> and a <code>createMaterial()</code> function for <i>Shader</i> with the given <i>State</i>.</p>
<!-- @@@QSG_DECLARE_SIMPLE_SHADER -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|