3 Star 8 Fork 3

萌谷王/GameEngineForEdu

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
RenderPass.cpp 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
公开技术 提交于 2020-09-07 15:27 +08:00 . 备份一下代码
#include "RenderPass.h"
#include "utils.h"
#include "VertexData.h"
void RenderPass::Bind(Camera*camera) {
glUseProgram(mShader->mProgram);
GloblalRenderState::SetBlendState(mRenderState.mbEnableBlend);
GloblalRenderState::SetBlendFunc(mRenderState.mSrcBlendFunc, mRenderState.mDstBlendFunc);
GloblalRenderState::SetDepthTestState(mRenderState.mbEnableDepthTest);
GloblalRenderState::SetDepthMask(mRenderState.mbWriteDepthBuffer);
if (mShader->mAttributes != nullptr) {
mShader->mAttributes->Active();
}
UniformUpdater*uniform_updater = mUniforms;
int slot_index = 0;
while (uniform_updater != nullptr) {
if (uniform_updater->mUpdateFunction == UniformUpdater::UpdateSampler2D) {
glActiveTexture(GL_TEXTURE0 + slot_index);
MaterialPropertySampler2D* prop = (MaterialPropertySampler2D*)uniform_updater->mTargetProperty;
glBindTexture(GL_TEXTURE_2D,prop->mTextureName);
glUniform1i(uniform_updater->mLocation, slot_index);
slot_index++;
}
else {
uniform_updater->mUpdateFunction(uniform_updater->mLocation, camera, uniform_updater->mTargetProperty);
}
uniform_updater = uniform_updater->Next<UniformUpdater>();
}
}
void RenderPass::SetMatrix4(const char *uniform_name, float*mat4) {
auto iter = mProperties.find(uniform_name);
if (iter!=mProperties.end()){
((MaterialPropertyMatrix4*)iter->second)->mPropertyValue = mat4;
}
}
void RenderPass::SetVec4(const char *uniform_name, float*ptr) {
auto iter = mProperties.find(uniform_name);
if (iter != mProperties.end()) {
((MaterialPropertyVec4*)iter->second)->mPropertyValue = ptr;
}
}
void RenderPass::SetSampler2D(const char* uniform_name, GLuint texture_name) {
auto iter = mProperties.find(uniform_name);
if (iter != mProperties.end()) {
((MaterialPropertySampler2D*)iter->second)->mTextureName = texture_name;
}
}
void RenderPass::SetShader(Shader*shader) {
mShader = shader;
mUniforms = nullptr;
UniformUpdater*current_uniform_updater = shader->mUniforms;
while (current_uniform_updater != nullptr) {
UniformUpdater*uniform_updater = current_uniform_updater->Clone();
AppendUniformUpdater(uniform_updater);
if (uniform_updater->mTargetProperty != nullptr) {
mProperties.insert(std::pair<std::string, MaterialProperty*>(uniform_updater->mTargetProperty->mName, uniform_updater->mTargetProperty));
}
current_uniform_updater = current_uniform_updater->Next<UniformUpdater>();
}
}
void RenderPass::AppendUniformUpdater(UniformUpdater*uniform_updater) {
if (mUniforms == nullptr) {
mUniforms = uniform_updater;
}
else {
mUniforms->PushBack(uniform_updater);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/battlefire/GameEngineForEdu.git
git@gitee.com:battlefire/GameEngineForEdu.git
battlefire
GameEngineForEdu
GameEngineForEdu
master

搜索帮助