<p>I want to implement shadows in my already existing glmatrix-based project.
You can see <a href="https://github.com/zlatnaspirala/matrix-engine" rel="nofollow noreferrer">my project's github</a> source. It is classic scebe object based structure. I have draw functions, I render recalls.</p>
<p>By this <a href="https://www.youtube.com/watch?v=txcgqWdZwR8&amp;ab_channel=DavidParker" rel="nofollow noreferrer">youtube tutorial</a> + <a href="https://github.com/davidwparker/programmingtil-webgl/blob/master/0091-framebuffer-part-2/index.js" rel="nofollow noreferrer">code</a>, I figured that draw calls must be in order.</p>
<p>Chronology of draw calls:</p>
<pre><code>   this.gl.enable(this.gl.DEPTH_TEST);
   this.gl.disable(this.gl.BLEND);
   this.gl.depthMask(true);

   - draw all `non fbo` and `no blend`

    state.gl.enable(state.gl.BLEND);
    state.gl.depthMask(false);

   - draw all `non fbo` and `blend`
    
   (this line is after draw func in main render) 
    state.gl.depthMask(true);


    // moment after all (non fbo objects) draws.

    state.gl.bindFramebuffer(state.gl.FRAMEBUFFER, null);
    state.gl.viewport(0, 0, state.canvas.width, state.canvas.height);  

    state.gl.clearColor(0.0, 0.0, 0.0, 1.0);
    state.gl.clear(state.gl.COLOR_BUFFER_BIT | state.gl.DEPTH_BUFFER_BIT);

    // Draw again...
    state.gl.enable(state.gl.DEPTH_TEST);
    state.gl.disable(state.gl.BLEND);
    state.gl.depthMask(true);

     - draw **all** but `no blend`

    // Leave on the depth test!
    state.gl.enable(state.gl.BLEND);
    state.gl.depthMask(false);

     - draw **all** but `blend`

    state.gl.depthMask(true);
</code></pre>
<p>Is this correct?</p>
<p>Is it necessary to use <code>createRenderbuffer</code>?</p>
<p>I dont understand why this operation is put into the draw loop:</p>
<pre class="lang-js prettyprint-override"><code>    // Set FBOs
    state.app.objects.forEach(function(obj) {
      if (obj.state.hasTexture &amp;&amp; obj.state.hasFbo) {
        obj.state.fbo = state.fbo;
      }
    });
</code></pre>

CC BY-SA 4.0
2022-11-29T22:31:44.763Z
It might be helpful if you provide a description what the code is supposed to do and what you have tried so far to solve your problem.
wychmaster
CC BY-SA 4.0
2022-11-30T12:13:15.140Z
@wychmaster 
♦ I updated question
Nikola Lukic
CC BY-SA 4.0
2022-12-06T03:01:25.730Z
This error says you tried to set a uniform array but the actual uniform is not an array. Please show the relevant glUniform call and declarations of the uniforms.
Criticize SE actions means ban
CC BY-SA 4.0
2022-12-09T16:00:46.190Z
This works , i will preformuled this question on next level.  (About FBO vs shadows cast) but i need some time to get it...
Nikola Lukic
<webgl><frame-buffer>
Warn GL_INVALID_OPERATION: Only array uniforms may have count > 1
Nikola Lukic
# Warn GL_INVALID_OPERATION: Only array uniforms may have count > 1

(Asked by: username_0 on 2022-11-29)

I want to implement shadows in my already existing glmatrix-based project.
You can see [my project's github](https://github.com/zlatnaspirala/matrix-engine) source. It is classic scebe object based structure. I have draw functions, I render recalls.

By this [youtube tutorial](https://www.youtube.com/watch?v=txcgqWdZwR8&ab_channel=DavidParker) + [code](https://github.com/davidwparker/programmingtil-webgl/blob/master/0091-framebuffer-part-2/index.js), I figured that draw calls must be in order.

Chronology of draw calls:

```
   this.gl.enable(this.gl.DEPTH_TEST);
   this.gl.disable(this.gl.BLEND);
   this.gl.depthMask(true);

   - draw all `non fbo` and `no blend`

    state.gl.enable(state.gl.BLEND);
    state.gl.depthMask(false);

   - draw all `non fbo` and `blend`
    
   (this line is after draw func in main render) 
    state.gl.depthMask(true);

    // moment after all (non fbo objects) draws.

    state.gl.bindFramebuffer(state.gl.FRAMEBUFFER, null);
    state.gl.viewport(0, 0, state.canvas.width, state.canvas.height);  

    state.gl.clearColor(0.0, 0.0, 0.0, 1.0);
    state.gl.clear(state.gl.COLOR_BUFFER_BIT | state.gl.DEPTH_BUFFER_BIT);

    // Draw again...
    state.gl.enable(state.gl.DEPTH_TEST);
    state.gl.disable(state.gl.BLEND);
    state.gl.depthMask(true);

     - draw **all** but `no blend`

    // Leave on the depth test!
    state.gl.enable(state.gl.BLEND);
    state.gl.depthMask(false);

     - draw **all** but `blend`

    state.gl.depthMask(true);

```

Is this correct?

Is it necessary to use `createRenderbuffer`?

I dont understand why this operation is put into the draw loop:

```js
    // Set FBOs
    state.app.objects.forEach(function(obj) {
      if (obj.state.hasTexture && obj.state.hasFbo) {
        obj.state.fbo = state.fbo;
      }
    });

```

**Tags:** webgl, frame-buffer

> **Comments:**
> **username_1**: It might be helpful if you provide a description what the code is supposed to do and what you have tried so far to solve your problem.  
> **username_0**: @username_1  ♦ I updated question  
> **username_2**: This error says you tried to set a uniform array but the actual uniform is not an array. Please show the relevant glUniform call and declarations of the uniforms.  
> **username_0**: This works , i will preformuled this question on next level.  (About FBO vs shadows cast) but i need some time to get it...  

---

## 0 answers

