コード例 #1
0
ファイル: GroupImpl.cpp プロジェクト: JamesLinus/pipeline
      void GroupImpl::updateMatrices( )
      {
        dp::util::ProfileEntry p("cull::updateMatrices");
        if ( m_matricesChanged )
        {
          if ( ! m_matricesBuffer )
          {
            m_matricesBuffer = dp::gl::Buffer::create(dp::gl::Buffer::CORE, GL_STATIC_DRAW, GL_SHADER_STORAGE_BUFFER);
          }

          // copy over matrices
          m_matricesBuffer->setSize(getMatricesCount() * sizeof( dp::math::Mat44f ));
          dp::gl::MappedBuffer<dp::math::Mat44f> matrices( m_matricesBuffer, GL_MAP_WRITE_BIT );
          char const* basePtr = reinterpret_cast<char const*>(getMatrices());
          for ( size_t index = 0; index < getMatricesCount(); ++index )
          {
            dp::math::Mat44f const& modelView = reinterpret_cast<dp::math::Mat44f const&>(*(basePtr + index * getMatricesStride()));
            matrices[index] = modelView;
          }

          m_matricesChanged = false;
        }
        else
        {
          struct MatrixUpdater
          {
            MatrixUpdater( char const* matricesInBasePtr, size_t matricesInStride )
              : m_matricesInBasePtr( matricesInBasePtr )
              , m_matricesInStride( matricesInStride )
            {
            }

            void operator()( size_t index )
            {
              glBufferSubData( GL_SHADER_STORAGE_BUFFER, index * sizeof(dp::math::Mat44f), sizeof(dp::math::Mat44f), m_matricesInBasePtr + index * m_matricesInStride );
            }

          private:
            char const*       m_matricesInBasePtr;
            size_t            m_matricesInStride;
          };

          bind( GL_SHADER_STORAGE_BUFFER, m_matricesBuffer );
          MatrixUpdater matrixUpdater( reinterpret_cast<char const*>(getMatrices()), getMatricesStride() );
          m_dirtyMatrices.traverseBits( matrixUpdater );
        }
        m_dirtyMatrices.clear();
      }
コード例 #2
0
	void Model::render(const RenderConf & _conf) const
	{
		if (!getShader())
			return;

		if (!Configurator::isDepthTestEnabled())
			glEnable(GL_DEPTH_TEST);

		Shader & shader = *getShader();
		shader.use();

		bool useCustomConf = _conf != RenderConf::Default;

		const auto & lights = useCustomConf ? _conf.lights : getLights();
		const auto & matrices = useCustomConf ? _conf.matrices : getMatrices();

		shader.setMat4f("mvp", matrices.mvp)
			.setMat4f("model", matrices.transform)
			.setMat4f("inverseModel", matrices.inverseTransform)
			.setVec3("cameraPos", matrices.cameraPosition)
			.setFloat("material.shininess", 5.f)
			.setLights("light", lights.cbegin(), lights.cend())
			.setBoolean("useColorOnly", m_useColorOnly)
			.setColor("singleColor", m_color);

		renderMeshes();

		Shader::unuse();

		if (!Configurator::isDepthTestEnabled())
			glDisable(GL_DEPTH_TEST);
	}