简体   繁体   English

1. 我必须为每个着色器使用绘图 function 吗? 2. 对于我想要绘制的每个不同纹理,我是否需要不同的着色器?

[英]1. Do i have to use a draw function for every shader? 2. Do I need a different shader for every different texture I want to draw?

Trying to learn openGL.努力学习openGL。 I want to draw multiple models with the same shader, but with different textures each, in a single VAO, is this possible?我想在单个 VAO 中使用相同的着色器绘制多个模型,但每个模型都有不同的纹理,这可能吗?

If not it wouldn't be very practical because I would have to compile a different shader for each texture that I want to use, and it would have the same code which makes my stomach turn, that or change the texture and call the draw function every time which makes me even more sick xd.如果不是这样,它就不是很实用,因为我必须为我想使用的每个纹理编译一个不同的着色器,并且它会有相同的代码让我的胃转动,或者更改纹理并调用绘图 function每次都让我更恶心xd。

And I also have been looking on the internet, and I can't find anyone who draws multiple shaders in one draw function, they use (useProgram(program)), and then draw the VAO, so you would need a different VAO for each shader?而且我也一直在网上寻找,我找不到任何人一次绘制多个着色器function,他们使用(useProgram(program)),然后绘制VAO,所以你需要为每个不同的VAO着色器?

I tought VAOs where only for vertex formats.我将 VAO 用于仅用于顶点格式的位置。 I hope you understand what I mean, I suck at expressing myself.我希望你明白我的意思,我很擅长表达自己。

The shaders are just like VAOs, VBOs and so on.着色器就像 VAO、VBO 等。 You have a shader id, you bind that shader, you make the draw call.您有一个着色器 ID,绑定该着色器,然后进行绘图调用。 Then, you can bind another shader, make another draw call, and so on.然后,您可以绑定另一个着色器,进行另一个绘制调用,等等。 All in the same draw function.所有这些都在同一张画中 function。

And of course, textures are more or less the same.当然,纹理或多或少是相同的。 Each texture also has an ID, so you can bind and unbind them to select which texture unit to use.每个纹理也有一个 ID,因此您可以将它们绑定和取消绑定到 select 使用哪个纹理单元。

In principle, you need to bind your data (the VAO), the texture and the shader.原则上,您需要绑定数据(VAO)、纹理和着色器。 And you can use them in any combination.您可以任意组合使用它们。

A VAO holds the information on how to pass the data stored in the buffers to the shader (It holds the "memory layout" of it). VAO 保存有关如何将存储在缓冲区中的数据传递给着色器的信息(它保存它的“内存布局”)。 You can store multiple objects in one VAO or create a VAO for each object.您可以将多个对象存储在一个 VAO 中,或者为每个 object 创建一个 VAO。

There is no direct coupling between the Shader and the VAO.着色器和 VAO 之间没有直接耦合。

With glUseProgram you say which shader program should be used for drawing, and with glBindVertexArray you say which VAO should pass the data to the shader program, and after you set up that combination you will issue the draw command.使用glUseProgram表示应该使用哪个着色器程序进行绘图,使用glBindVertexArray表示应该使用哪个 VAO 将数据传递给着色器程序,在设置好组合后,您将发出绘图命令。

You can draw on VAO with different shaders, or use one shader to draw different VAOs, or draw one VAO multiple times with the same or different shaders.您可以使用不同的着色器在 VAO 上绘制,或者使用一个着色器来绘制不同的 VAO,或者使用相同或不同的着色器多次绘制一个 VAO。

But for each VAO Shader combination, you need to issue on draw command.但是对于每个 VAO Shader 组合,您需要发出绘制命令。

Before each draw, you can change the uniforms and/or textures that are shader should use.在每次绘制之前,您可以更改着色器应使用的制服和/或纹理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我必须切换“纹理单位”才能使“片段着色器”识别要使用的纹理? - Why do I have to switch Texture Unit in order for my Fragment Shader to recognize which texture to use? 如何从 OpenGL 着色器中的纹理贴图绘制贴图? - How I can draw a tile from a texture tilemap in an OpenGL shader? 如果我使用片段着色器制作纹理,如何绘制红线? - How to draw red lines if I used a fragment shader for texture? 当我在顶点着色器中有一个“ out”时,OpenGL无法绘制 - OpenGL doesn't draw when I have an “out” in vertex shader 我需要为OpenGL 3.3 Core使用着色器吗? - Do I need to use a shader for OpenGL 3.3 Core? 我是否必须为每个不同的参数重载函数? - Do I have to overload functions for every different parameter? 使用纹理 arrays 时,为什么我不必将采样器绑定到着色器? - When using texture arrays, why do I not have to bind the sampler to the shader? 如果我想更改 function 的返回类型,我是否必须覆盖基础 class 中的每个 function? - Do I have to override every function in base class, if I want to change the return type of a function? 即使编译失败,是否还需要删除OpenGL着色器对象? - Do I need to delete OpenGL shader objects even if compilation fails? 我是否需要通过几何着色器将颜色传递给片段着色器? - Do I need to pass color though my geometry shader to the fragment shader?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM