src/gl/basicshaderprogram.cpp

changeset 216
c7241f504117
parent 215
34c6e7bc4ee1
child 250
2837b549e616
equal deleted inserted replaced
215:34c6e7bc4ee1 216:c7241f504117
41 if (not this->isInitialized) 41 if (not this->isInitialized)
42 { 42 {
43 this->initializeOpenGLFunctions(); 43 this->initializeOpenGLFunctions();
44 this->isInitialized = true; 44 this->isInitialized = true;
45 this->program = std::make_unique<gl::ShaderProgram>(); 45 this->program = std::make_unique<gl::ShaderProgram>();
46 gl::buildShaders(&*this->program, vertexShaderSource, fragmentShaderSource); 46 gl::buildShaders(this->program.get(), vertexShaderSource, fragmentShaderSource);
47 this->program->bind(); 47 this->program->bind();
48 this->buffer.create(); 48 this->buffer.create();
49 this->buffer.bind(); 49 this->buffer.bind();
50 this->buffer.setUsagePattern(usagePattern); 50 this->buffer.setUsagePattern(usagePattern);
51 this->vertexArrayObject.create(); 51 this->vertexArrayObject.create();
62 } 62 }
63 } 63 }
64 64
65 void BasicShader::setMvpMatrix(const glm::mat4& newMvpMatrix) 65 void BasicShader::setMvpMatrix(const glm::mat4& newMvpMatrix)
66 { 66 {
67 this->setUniformMatrix("mvp", newMvpMatrix);
68 }
69
70 void BasicShader::setUniformMatrix(const char* name, const glm::mat4& value)
71 {
67 Q_ASSERT(this->isInitialized); 72 Q_ASSERT(this->isInitialized);
68 this->program->bind(); 73 this->program->bind();
69 this->program->setUniformMatrix("mvp", newMvpMatrix); 74 this->program->setUniformMatrix(name, value);
75 this->program->release();
76 gl::checkForGLErrors(nullptr);
77 }
78
79 void BasicShader::setUniformVector(const char* name, const glm::vec4& value)
80 {
81 Q_ASSERT(this->isInitialized);
82 this->program->bind();
83 this->program->setUniformVector(name, value);
70 this->program->release(); 84 this->program->release();
71 gl::checkForGLErrors(nullptr); 85 gl::checkForGLErrors(nullptr);
72 } 86 }
73 87
74 void BasicShader::bufferData(const void* data, std::size_t count, std::size_t size) 88 void BasicShader::bufferData(const void* data, std::size_t count, std::size_t size)

mercurial