QENGINE_API void renderFullscreenTexturedQuad() { int isDepthEnabled = isZTestEnabled(); disableZTest(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); // g_pTexturedEffect->Bind(); // float verts[20] = {-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, // 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, // -1.0f, 1.0f, 1.0f, 0.0f, 1.0f}; // unsigned int indices[6] = {0, 1, 2, 0, 2, 3}; // glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE, 20, verts); // glVertexAttribPointer(LOC_TEXCOORD0, 2, GL_FLOAT, GL_TRUE, 20, (float*)&verts[3]); // glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices); // g_pTexturedEffect->EvictTextures(); // g_pTexturedEffect->Unbind(); bindBuffer(g_fullscreenQuad); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); bindDefaultBuffer(); glDisable(GL_BLEND); if(isDepthEnabled) enableZTest(); }
Material::Material(const Path& path, ResourceManager& resource_manager, IAllocator& allocator) : Resource(path, resource_manager, allocator) , m_shader(nullptr) , m_uniforms(allocator) , m_allocator(allocator) , m_texture_count(0) , m_render_states(0) , m_specular(1, 1, 1) , m_shininess(4) , m_shader_instance(nullptr) , m_shader_mask(0) { auto* manager = resource_manager.get(ResourceManager::MATERIAL); auto* mat_manager = static_cast<MaterialManager*>(manager); s_alpha_cutout_define_idx = mat_manager->getRenderer().getShaderDefineIdx("ALPHA_CUTOUT"); s_shadow_receiver_define_idx = mat_manager->getRenderer().getShaderDefineIdx("SHADOW_RECEIVER"); enableZTest(true); enableBackfaceCulling(true); enableShadowReceiving(true); for (int i = 0; i < MAX_TEXTURE_COUNT; ++i) { m_textures[i] = nullptr; } }
void DebugEmitterComponent::Render(const UpdateContext& updateContext) { if (!_model) return; auto parent = GetParentEntity(); vec3f center = GetModelCenter(); vec3f desiredPos = parent->GetPosition(); vec3f desiredScale = parent->GetScale(); mat4f desiredPose = parent->GetPose(); enableZTest(); changeZTest(GL_LEQUAL); mat4f ident, NT, T, S, R, x, y, z; ident.loadIdentity(); _matrixStack.PushMatrix(ident); //NT.loadTranslation(-center.x, -center.y, -center.z); T.loadTranslation(desiredPos.x, desiredPos.y, desiredPos.z); S.loadScale(desiredScale.x, desiredScale.y, desiredScale.z); R = desiredPose; R.m[12] = 0.0f; R.m[13] = 0.0f; R.m[14] = 0.0f; R.m[15] = 1.0f; _matrixStack.MultiplyMatrix(T); _matrixStack.MultiplyMatrix(S); _matrixStack.MultiplyMatrix(R); //_matrixStack.MultiplyMatrix(NT); // _matrixStack.MultiplyMatrix(parent->GetTransform()); /*vec3f rot = parent->GetDirection(); mat4f xRot, yRot, zRot; xRot.loadXRotation(rot.x); yRot.loadYRotation(rot.y); zRot.loadZRotation(rot.z); xRot *= yRot; xRot *= zRot; _matrixStack.MultiplyMatrix(xRot);*/ mat4f MV; MV = getMatrix(MATRIX_MODEL); _RenderNode(_model->RootNode, updateContext); _matrixStack.PopMatrix(); setMatrix(MATRIX_MODEL, MV); }
QENGINE_API void renderFullscreenTexturedQuad(bool invertV, unsigned int texID) { if(texID <= 0) return; int isDepthEnabled = isZTestEnabled(); // float minV, maxV; // minV = 0.0f; maxV = 1.0f; // if (invertV) // { // minV = 1.0f; maxV = 0.0f; // } disableZTest(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); mat4f ID; ID.loadIdentity(); pushMatrix(MATRIX_MODEL, ID); pushMatrix(MATRIX_VIEW, ID); pushMatrix(MATRIX_PROJECTION, ID); float a = 1.0f; float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; g_pTexturedEffect->Bind(); g_pTexturedEffect->BindTexture("s0", texID); g_pTexturedEffect->BindBool("invert", invertV); g_pTexturedEffect->BindFloat("globalColor", color, 4); g_pTexturedEffect->BindStateMatrix("MVP", MATRIX_MODEL | MATRIX_VIEW | MATRIX_PROJECTION); bindBuffer(g_fullscreenQuad); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); bindDefaultBuffer(); g_pTexturedEffect->EvictTextures(); g_pTexturedEffect->Unbind(); glDisable(GL_BLEND); popMatrix(MATRIX_MODEL); popMatrix(MATRIX_VIEW); popMatrix(MATRIX_PROJECTION); if(isDepthEnabled) enableZTest(); }
QENGINE_API void renderFullscreenQuad(const texture_rect& rect, unsigned int w, unsigned int h) { int isDepthEnabled = isZTestEnabled(); disableZTest(); // glMatrixMode(GL_MODELVIEW); // glPushMatrix(); // glLoadIdentity(); // glMatrixMode(GL_PROJECTION); // glPushMatrix(); // glLoadIdentity(); float fWidth5 = (float)w - 0.5f; float fHeight5 = (float)h - 0.5f; // glBegin(GL_QUADS); // glTexCoord2f(rect.leftU, rect.bottomV); // glVertex3f(-1.0f, -1.0f, 1.0f); // glTexCoord2f(rect.rightU, rect.bottomV); // glVertex3f(1.0f, -1.0f, 1.0f); // glTexCoord2f(rect.rightU, rect.topV); // glVertex3f(1.0f, 1.0f, 1.0f); // glTexCoord2f(rect.leftU, rect.topV); // glVertex3f(-1.0F, 1.0F, 1.0f); // glEnd(); // glPopMatrix(); // glMatrixMode(GL_PROJECTION); // glPopMatrix(); float verts[20] = {-1.0f, -1.0f, 1.0f, rect.leftU, rect.bottomV, 1.0f, -1.0f, 1.0f, rect.rightU, rect.bottomV, 1.0f, 1.0f, 1.0f, rect.rightU, rect.topV, -1.0f, 1.0f, 1.0f, rect.leftU, rect.topV}; unsigned int indices[6] = {0, 1, 2, 0, 2, 3}; glEnableVertexAttribArray(LOC_POSITION); glEnableVertexAttribArray(LOC_TEXCOORD0); glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE, 20, verts); glVertexAttribPointer(LOC_TEXCOORD0, 2, GL_FLOAT, GL_TRUE, 20, (float*)&verts[3]); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices); glDisableVertexAttribArray(LOC_POSITION); glDisableVertexAttribArray(LOC_TEXCOORD0); if(isDepthEnabled) enableZTest(); }
QENGINE_API void renderFullscreenQuad(float r, float g, float b, float a) { float verts[28] = { -1.0f, -1.0f, 1.0f, r, g, b, a, 1.0f, -1.0f, 1.0f, r, g, b, a, 1.0f, 1.0f, 1.0f, r, g, b, a, -1.0f, 1.0f, 1.0f, r, g, b, a }; uint32_t indices[6] = { 0, 1, 2, 0, 2, 3 }; int isDepthEnabled = isZTestEnabled(); disableZTest(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); mat4f id; id.loadIdentity(); pushMatrix(MATRIX_PROJECTION, id); pushMatrix(MATRIX_VIEW, id); g_pColoredEffect->Bind(); g_pColoredEffect->BindStateMatrix("MVP", MATRIX_MODEL | MATRIX_VIEW | MATRIX_PROJECTION); glEnableVertexAttribArray(LOC_POSITION); glEnableVertexAttribArray(LOC_COLOR); glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE, 28, verts); glVertexAttribPointer(LOC_COLOR, 4, GL_FLOAT, GL_TRUE, 28, (float*)&verts[3]); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices); glDisableVertexAttribArray(LOC_POSITION); glDisableVertexAttribArray(LOC_COLOR); g_pColoredEffect->Unbind(); if(isDepthEnabled) enableZTest(); glDisable(GL_BLEND); popMatrix(MATRIX_PROJECTION); popMatrix(MATRIX_VIEW); }
bool Material::load(FS::IFile& file) { PROFILE_FUNCTION(); m_render_states = BGFX_STATE_DEPTH_TEST_LEQUAL | BGFX_STATE_CULL_CW; m_uniforms.clear(); JsonSerializer serializer(file, JsonSerializer::READ, getPath().c_str(), m_allocator); serializer.deserializeObjectBegin(); char path[MAX_PATH_LENGTH]; char label[256]; char material_dir[MAX_PATH_LENGTH]; PathUtils::getDir(material_dir, MAX_PATH_LENGTH, getPath().c_str()); bool b_value; while (!serializer.isObjectEnd()) { serializer.deserializeLabel(label, 255); if (compareString(label, "uniforms") == 0) { deserializeUniforms(serializer); } else if (compareString(label, "texture") == 0) { if (!deserializeTexture(serializer, material_dir)) { return false; } } else if (compareString(label, "alpha_cutout") == 0) { bool b; serializer.deserialize(b, false); enableAlphaCutout(b); } else if (compareString(label, "alpha_blending") == 0) { if (serializer.isNextBoolean()) { bool is_alpha_blending; serializer.deserialize(is_alpha_blending, false); if (is_alpha_blending) { m_render_states |= BGFX_STATE_BLEND_ADD; } else { m_render_states &= ~BGFX_STATE_BLEND_MASK; } } else { serializer.deserialize(label, 255, "alpha"); if (compareString(label, "alpha") == 0) { m_render_states |= BGFX_STATE_BLEND_ALPHA; } else if (compareString(label, "add") == 0) { m_render_states |= BGFX_STATE_BLEND_ADD; } else if (compareString(label, "disabled") == 0) { m_render_states &= ~BGFX_STATE_BLEND_MASK; } } } else if (compareString(label, "specular") == 0) { serializer.deserializeArrayBegin(); serializer.deserializeArrayItem(m_specular.x, 1.0f); serializer.deserializeArrayItem(m_specular.y, 1.0f); serializer.deserializeArrayItem(m_specular.z, 1.0f); serializer.deserializeArrayEnd(); } else if (compareString(label, "shininess") == 0) { serializer.deserialize(m_shininess, 4.0f); } else if (compareString(label, "shadow_receiver") == 0) { bool b; serializer.deserialize(b, true); enableShadowReceiving(b); } else if (compareString(label, "shader") == 0) { serializer.deserialize(path, MAX_PATH_LENGTH, ""); setShader(static_cast<Shader*>( m_resource_manager.get(ResourceManager::SHADER)->load(Path(path)))); } else if (compareString(label, "z_test") == 0) { serializer.deserialize(b_value, true); enableZTest(b_value); } else if (compareString(label, "backface_culling") == 0) { serializer.deserialize(b_value, true); enableBackfaceCulling(b_value); } else { g_log_warning.log("renderer") << "Unknown parameter " << label << " in material " << getPath().c_str(); } } serializer.deserializeObjectEnd(); if (!m_shader) { g_log_error.log("renderer") << "Material " << getPath().c_str() << " without a shader"; return false; } m_size = file.size(); return true; }