void LLPostProcess::doEffects(void) { /// Save GL State glPushAttrib(GL_ALL_ATTRIB_BITS); glPushClientAttrib(GL_ALL_ATTRIB_BITS); /// Copy the screen buffer to the render texture { U32 tex = mSceneRenderTexture->getTexName() ; copyFrameBuffer(tex, screenW, screenH); } /// Clear the frame buffer. glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); /// Change to an orthogonal view viewOrthogonal(screenW, screenH); checkError(); applyShaders(); LLGLSLShader::bindNoShader(); checkError(); /// Change to a perspective view viewPerspective(); /// Reset GL State glPopClientAttrib(); glPopAttrib(); checkError(); }
// Applies the shaders and shader constants to the Direct3D device gl::Error RendererD3D::applyShaders(const gl::Data &data) { gl::Program *program = data.state->getProgram(); GetImplAs<ProgramD3D>(program)->updateCachedInputLayout(program, *data.state); const gl::Framebuffer *fbo = data.state->getDrawFramebuffer(); gl::Error error = applyShaders(program, fbo, data.state->getRasterizerState().rasterizerDiscard, data.state->isTransformFeedbackActiveUnpaused()); if (error.isError()) { return error; } return program->applyUniforms(); }
// Applies the shaders and shader constants to the Direct3D device gl::Error RendererD3D::applyShaders(const gl::Data &data) { gl::Program *program = data.state->getProgram(); gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS]; gl::VertexFormat::GetInputLayout(inputLayout, program, *data.state); const gl::Framebuffer *fbo = data.state->getDrawFramebuffer(); gl::Error error = applyShaders(program, inputLayout, fbo, data.state->getRasterizerState().rasterizerDiscard, data.state->isTransformFeedbackActiveUnpaused()); if (error.isError()) { return error; } return program->applyUniforms(); }
void LLPostProcess::doEffects(void) { LLVertexBuffer::unbind(); mNoiseTextureScale = 0.001f + ((100.f - mSelectedEffectInfo["noise_size"].asFloat()) / 100.f); mNoiseTextureScale *= (mScreenHeight / NOISE_SIZE); /// Copy the screen buffer to the render texture copyFrameBuffer(); stop_glerror(); //Disable depth. Set blendmode to replace. LLGLDepthTest depth(GL_FALSE,GL_FALSE); LLGLEnable blend(GL_BLEND); gGL.setSceneBlendType(LLRender::BT_REPLACE); /// Change to an orthogonal view gGL.matrixMode(LLRender::MM_PROJECTION); gGL.pushMatrix(); gGL.loadIdentity(); gGL.ortho( 0.f, (GLdouble) mScreenWidth, 0.f, (GLdouble) mScreenHeight, -1.f, 1.f ); gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.pushMatrix(); gGL.loadIdentity(); applyShaders(); LLGLSLShader::bindNoShader(); /// Change to a perspective view gGL.flush(); gGL.matrixMode( LLRender::MM_PROJECTION ); gGL.popMatrix(); gGL.matrixMode( LLRender::MM_MODELVIEW ); gGL.popMatrix(); gGL.setSceneBlendType(LLRender::BT_ALPHA); //Restore blendstate. Alpha is ASSUMED for hud/ui render, etc. gGL.getTexUnit(1)->disable(); }
gl::Error RendererD3D::drawElements(const gl::Data &data, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances, const gl::RangeUI &indexRange) { if (data.state->isPrimitiveRestartEnabled()) { UNIMPLEMENTED(); return gl::Error(GL_INVALID_OPERATION, "Primitive restart not implemented"); } gl::Program *program = data.state->getProgram(); ASSERT(program != NULL); program->updateSamplerMapping(); gl::Error error = generateSwizzles(data); if (error.isError()) { return error; } if (!applyPrimitiveType(mode, count, program->usesPointSize())) { return gl::Error(GL_NO_ERROR); } error = applyRenderTarget(data, mode, false); if (error.isError()) { return error; } error = applyState(data, mode); if (error.isError()) { return error; } gl::VertexArray *vao = data.state->getVertexArray(); TranslatedIndexData indexInfo; indexInfo.indexRange = indexRange; SourceIndexData sourceIndexInfo; error = applyIndexBuffer(indices, vao->getElementArrayBuffer().get(), count, mode, type, &indexInfo, &sourceIndexInfo); if (error.isError()) { return error; } applyTransformFeedbackBuffers(*data.state); // Transform feedback is not allowed for DrawElements, this error should have been caught at the API validation // layer. ASSERT(!data.state->isTransformFeedbackActiveUnpaused()); GLsizei vertexCount = indexInfo.indexRange.length() + 1; error = applyVertexBuffer(*data.state, mode, indexInfo.indexRange.start, vertexCount, instances, &sourceIndexInfo); if (error.isError()) { return error; } error = applyShaders(data); if (error.isError()) { return error; } error = applyTextures(data); if (error.isError()) { return error; } error = program->applyUniformBuffers(data); if (error.isError()) { return error; } if (!skipDraw(data, mode)) { error = drawElements(mode, count, type, indices, vao->getElementArrayBuffer().get(), indexInfo, instances, program->usesPointSize()); if (error.isError()) { return error; } } return gl::Error(GL_NO_ERROR); }
gl::Error RendererD3D::drawArrays(const gl::Data &data, GLenum mode, GLint first, GLsizei count, GLsizei instances) { gl::Program *program = data.state->getProgram(); ASSERT(program != NULL); program->updateSamplerMapping(); gl::Error error = generateSwizzles(data); if (error.isError()) { return error; } if (!applyPrimitiveType(mode, count, program->usesPointSize())) { return gl::Error(GL_NO_ERROR); } error = applyRenderTarget(data, mode, false); if (error.isError()) { return error; } error = applyState(data, mode); if (error.isError()) { return error; } applyTransformFeedbackBuffers(*data.state); error = applyVertexBuffer(*data.state, mode, first, count, instances, nullptr); if (error.isError()) { return error; } error = applyShaders(data); if (error.isError()) { return error; } error = applyTextures(data); if (error.isError()) { return error; } error = program->applyUniformBuffers(data); if (error.isError()) { return error; } if (!skipDraw(data, mode)) { error = drawArrays(data, mode, count, instances, program->usesPointSize()); if (error.isError()) { return error; } if (data.state->isTransformFeedbackActiveUnpaused()) { markTransformFeedbackUsage(data); } } return gl::Error(GL_NO_ERROR); }
gl::Error RendererD3D::genericDrawElements(const gl::Data &data, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances, const gl::IndexRange &indexRange) { gl::Program *program = data.state->getProgram(); ASSERT(program != nullptr); ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); bool usesPointSize = programD3D->usesPointSize(); programD3D->updateSamplerMapping(); gl::Error error = generateSwizzles(data); if (error.isError()) { return error; } if (!applyPrimitiveType(mode, count, usesPointSize)) { return gl::Error(GL_NO_ERROR); } error = updateState(data, mode); if (error.isError()) { return error; } TranslatedIndexData indexInfo; indexInfo.indexRange = indexRange; error = applyIndexBuffer(data, indices, count, mode, type, &indexInfo); if (error.isError()) { return error; } applyTransformFeedbackBuffers(*data.state); // Transform feedback is not allowed for DrawElements, this error should have been caught at the API validation // layer. ASSERT(!data.state->isTransformFeedbackActiveUnpaused()); size_t vertexCount = indexInfo.indexRange.vertexCount(); error = applyVertexBuffer(*data.state, mode, static_cast<GLsizei>(indexInfo.indexRange.start), static_cast<GLsizei>(vertexCount), instances, &indexInfo); if (error.isError()) { return error; } error = applyTextures(data); if (error.isError()) { return error; } error = applyShaders(data, mode); if (error.isError()) { return error; } error = programD3D->applyUniformBuffers(data); if (error.isError()) { return error; } if (!skipDraw(data, mode)) { error = drawElementsImpl(data, indexInfo, mode, count, type, indices, instances); if (error.isError()) { return error; } } return gl::Error(GL_NO_ERROR); }