Exemplo n.º 1
0
	bool initBuffer()
	{
		// Generate a buffer object
		glGenBuffers(buffer::MAX, &BufferName[0]);

		// Allocate and copy buffers memory
		std::vector<glm::byte> Data(PositionSizeF32 + PositionSizeI8 + PositionSizeI32 + PositionSizeRGB10A2 + PositionSizeF16 + PositionSizeRG11FB10F);
		
		std::size_t CurrentOffset = 0;
		memcpy(&Data[0] + CurrentOffset, PositionDataF32, PositionSizeF32);
		CurrentOffset += PositionSizeF32;
		memcpy(&Data[0] + CurrentOffset, PositionDataI8, PositionSizeI8);
		CurrentOffset += PositionSizeI8;
		memcpy(&Data[0] + CurrentOffset, PositionDataI32, PositionSizeI32);
		CurrentOffset += PositionSizeI32;
		memcpy(&Data[0] + CurrentOffset, PositionDataRGB10A2, PositionSizeRGB10A2);
		CurrentOffset += PositionSizeRGB10A2;
		memcpy(&Data[0] + CurrentOffset, PositionDataF16, PositionSizeF16);
		CurrentOffset += PositionSizeF16;
		memcpy(&Data[0] + CurrentOffset, PositionDataRG11FB10F, PositionSizeRG11FB10F);

		glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::VERTEX]);
		glBufferStorage(GL_ARRAY_BUFFER, GLsizeiptr(Data.size()), &Data[0], 0);

		GLint UniformBufferOffset(0);
		glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &UniformBufferOffset);
		GLint UniformBlockSize = glm::max(GLint(sizeof(glm::mat4)), UniformBufferOffset);

		glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);
		glBufferStorage(GL_UNIFORM_BUFFER, UniformBlockSize, nullptr, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
		glBindBuffer(GL_UNIFORM_BUFFER, 0);

		return this->checkError("initBuffer");
	}
Exemplo n.º 2
0
 ParameterRendererBuffer::ParameterRendererBuffer( ParameterCacheEntryStreamBuffers const& parameterCacheEntries, dp::gl::SharedBuffer const& ubo, GLenum target, size_t uboBinding, size_t uboOffset, GLsizeiptr uboBlockSize )
   : m_parameters( parameterCacheEntries )
   , m_ubo( ubo )
   , m_target( target )
   , m_uboBinding( GLint(uboBinding) )
   , m_uboOffset( GLsizeiptr(uboOffset) )
   , m_uboBlockSize( uboBlockSize )
 {
   DP_ASSERT( !m_parameters.empty() );
 }
 ParameterRendererBuffer::ParameterRendererBuffer(ParameterCacheEntryStreamBuffers const& parameterCacheEntries, dp::gl::BufferSharedPtr const& ubo, GLenum target
                                                 , size_t uboBinding, size_t uboOffset, GLsizeiptr uboBlockSize
                                                 , bool useUniformBufferUnifiedMemory)
   : ParameterRendererStreamBuffer(parameterCacheEntries)
   , m_ubo(ubo)
   , m_target(target)
   , m_uboBinding(GLint(uboBinding))
   , m_uboOffset(GLsizeiptr(uboOffset))
   , m_uboBlockSize(uboBlockSize)
   , m_useUniformBufferUnifiedMemory(useUniformBufferUnifiedMemory)
 {
 }
Exemplo n.º 4
0
	// Buffer update using glBufferSubData
	bool initBuffer()
	{
		// Generate a buffer object
		glGenBuffers(1, &BufferName);

		// Bind the buffer for use
		glBindBuffer(GL_ARRAY_BUFFER, BufferName);

		// Reserve buffer memory but don't copy the values
		glBufferData(GL_ARRAY_BUFFER, GLsizeiptr(VertexCount * sizeof(glf::vertex_v4fc4f)), NULL, GL_STATIC_DRAW);

		glf::vertex_v4fc4f* Data = (glf::vertex_v4fc4f*)glMapBufferRange(
			GL_ARRAY_BUFFER, 
			0,				// Offset
			GLsizeiptr(VertexCount * sizeof(glf::vertex_v4fc4f)),	// Size,
			GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

		for(std::size_t i = 0; i < VertexCount; ++i)
		{
			//Data[i].Position = glm::vec4(glm::linearRand(glm::vec2(-1), glm::vec2(1)), glm::gaussRand(0.0f, 1.0f), 1);
			//Data[i].Position = glm::vec4(glm::linearRand(glm::vec2(-1), glm::vec2(1)), /*glm::gaussRand(0.0f, 1.0f)*/0, 1);
			//Data[i].Position = glm::vec4(glm::sphericalRand(1.0f), 1);
			//Data[i].Position = glm::vec4(glm::gaussRand(glm::vec3(0), glm::vec3(1)), 1);
			//Data[i].Position = glm::vec4(glm::circularRand(1.0f), 0, 1);
			//Data[i].Position = glm::vec4(glm::diskRand(1.0f), 0, 1);
			//Data[i].Position = glm::vec4(glm::ballRand(1.0f), 1);
			Data[i].Position = glm::vec4(
				glm::cos(static_cast<float>(i) / static_cast<float>(VertexCount) * glm::pi<float>() * 2.f) * 1.f,
				glm::sin(static_cast<float>(i) / static_cast<float>(VertexCount) * glm::pi<float>() * 2.f) * 1.f,
				0.0f, 1.0f);
			Data[i].Color = glm::vec4(1);
		}

		glUnmapBuffer(GL_ARRAY_BUFFER);

		// Unbind the buffer
		glBindBuffer(GL_ARRAY_BUFFER, 0);

		return this->checkError("initArrayBuffer");
	}
Exemplo n.º 5
0
	/**
	 *  @glsymbols
	 *  @glfunref{FlushMappedNamedBufferRange}
	 *
	 *  @pre Mapped()
	 *
	 *  @throws Error
	 */
	void FlushRange(BufferSize offset, BufferSize length)
	{
		OGLPLUS_GLFUNC(FlushMappedNamedBufferRange)(
			_name,
			GLintptr(offset.Get()),
			GLsizeiptr(length.Get())
		);
		OGLPLUS_CHECK(
			FlushMappedNamedBufferRange,
			ObjectError,
			Object(BufferName(_name))
		);
	}
Exemplo n.º 6
0
void
OpenGL::InitShapes()
{
  if (!OpenGL::vertex_buffer_object)
    return;

  DeinitShapes();

  assert(4096 % CIRCLE_SIZE == 0);  // implies: assert(SIZE % 2 == 0)

  GLshort *p = circle_data, *p2 = circle_data + CIRCLE_SIZE;
  for (unsigned i = 0; i < CIRCLE_SIZE / 2; ++i) {
    GLshort x = ISINETABLE[(i * (4096 / CIRCLE_SIZE) + 1024) & 0xfff];
    GLshort y = ISINETABLE[i * (4096 / CIRCLE_SIZE)];

    *p++ = x;
    *p++ = y;

    *p2++ = -x;
    *p2++ = -y;
  }

  circle_buffer = new GLArrayBuffer();
  circle_buffer->Load(GLsizeiptr(sizeof(circle_data)), circle_data);

  p = small_circle_data;
  p2 = circle_data;
  for (unsigned i = 0; i < SMALL_CIRCLE_SIZE; ++i) {
    *p++ = p2[0] >> 2;
    *p++ = p2[1] >> 2;

    p2 += 2 * CIRCLE_SIZE / SMALL_CIRCLE_SIZE;
  }

  small_circle_buffer = new GLArrayBuffer();
  small_circle_buffer->Load(GLsizeiptr(sizeof(small_circle_data)),
                            small_circle_data);
}
Exemplo n.º 7
0
 ObjectOps& BufferRange(
   GLuint index, BufferName buffer, BufferSize offset, BufferSize size) {
     OGLPLUS_GLFUNC(TransformFeedbackBufferRange)
     (_obj_name(),
      index,
      GetGLName(buffer),
      GLintptr(offset.Get()),
      GLsizeiptr(size.Get()));
     OGLPLUS_CHECK(
       TransformFeedbackBufferRange,
       ObjectPairError,
       Subject(buffer).Object(*this).Index(index));
     return *this;
 }
Exemplo n.º 8
0
	static GLsizeiptr _get_size(GLuint buf_name)
	{
		GLint value = 0;
		OGLPLUS_GLFUNC(GetNamedBufferParameterivEXT)(
			buf_name,
			GL_BUFFER_SIZE,
			&value
		);
		OGLPLUS_CHECK(
			GetNamedBufferParameterivEXT,
			ObjectError,
			Object(BufferName(buf_name))
		);
		return GLsizeiptr(value);
	}