Пример использования UBO
This commit is contained in:
parent
c13e49282a
commit
bce0048b52
|
@ -1,16 +1,21 @@
|
|||
#version 330 core
|
||||
#version 420 core
|
||||
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec2 inTexCoord;
|
||||
layout(location = 2) in vec3 normals;
|
||||
|
||||
uniform mat4 vp;
|
||||
layout(std140, binding = 0) uniform Camera
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 view;
|
||||
};
|
||||
|
||||
uniform mat4 model;
|
||||
|
||||
out vec2 texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vp * model * vec4(pos, 1.0);
|
||||
gl_Position = projection * view * model * vec4(pos, 1.0);
|
||||
texCoord = inTexCoord;
|
||||
}
|
||||
|
|
|
@ -192,16 +192,19 @@ int main(void)
|
|||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Расположение Uniform-переменной
|
||||
GLuint vp_uniform = glGetUniformLocation(shaderProgram, "vp");
|
||||
GLuint model_uniform = glGetUniformLocation(shaderProgram, "model");
|
||||
|
||||
// Uniform-буферы
|
||||
UBO cameraUB(sizeof(glm::mat4)*2, 0);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Использование уменьшенных версий mipmap
|
||||
|
||||
// Пока не произойдет событие запроса закрытия окна
|
||||
while(!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Загрузим матрицу проекции*вида
|
||||
glUniformMatrix4fv(vp_uniform, 1, GL_FALSE, &Camera::current().getVP()[0][0]);
|
||||
// Загрузка данных о камере
|
||||
cameraUB.loadSub(&Camera::current().getProjection(), sizeof(glm::mat4), 0);
|
||||
cameraUB.loadSub(&Camera::current().getView(), sizeof(glm::mat4), sizeof(glm::mat4));
|
||||
|
||||
// Очистка буфера цвета
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
|
Loading…
Reference in New Issue