예제 #1
0
int
rb_remove_vertex_attrib
  (struct rb_vertex_array* array,
   int count,
   const int* list_of_attrib_indices)
{
  int i = 0;
  int err = 0;

  if(!array
  || count < 0
  || (count > 0 && !list_of_attrib_indices))
    return -1;

  OGL(BindVertexArray(array->name));
  for(i = 0; i < count; ++i) {
    const int current_attrib = list_of_attrib_indices[i];
    if(current_attrib < 0) {
      err = -1;
    } else {
      OGL(DisableVertexAttribArray(current_attrib));
    }
  }
  OGL(BindVertexArray(array->ctxt->state_cache.vertex_array_binding));

  return err;
}
예제 #2
0
int
rb_vertex_attrib_array
  (struct rb_vertex_array* array,
   struct rb_buffer* buffer,
   int count,
   const struct rb_buffer_attrib* attrib)
{
  intptr_t offset = 0;
  int i = 0;
  int err = 0;

  if(!array
  || !buffer
  || !attrib
  || count < 0
  || buffer->target != GL_ARRAY_BUFFER)
    goto error;

  OGL(BindVertexArray(array->name));
  OGL(BindBuffer(buffer->target, buffer->name));

  for(i=0; i < count; ++i) {

    if(attrib[i].type == RB_UNKNOWN_TYPE) {
      OGL(BindBuffer
        (buffer->target, 
         array->ctxt->state_cache.buffer_binding[buffer->binding]));
      goto error;
    }

    offset = attrib[i].offset;
    OGL(EnableVertexAttribArray(attrib[i].index));
    OGL(VertexAttribPointer
        (attrib[i].index,
         ogl3_attrib_nb_components(attrib[i].type),
         GL_FLOAT,
         GL_FALSE,
         attrib[i].stride,
         (void*)offset));
  }

  OGL(BindVertexArray(array->ctxt->state_cache.vertex_array_binding));
  OGL(BindBuffer
    (buffer->target, array->ctxt->state_cache.buffer_binding[buffer->binding]));

exit:
  return err;

error:
  err = -1;
  goto exit;
}
예제 #3
0
void GL3CharacterRenderer::render() {
	Character &localCharacter = client->getLocalCharacter();

		auto &defaultShader = ((GL3Renderer *) renderer)->getShaderManager()->getDefaultShader();

	glm::mat4 viewMatrix = glm::rotate(glm::mat4(1.0f), (float) (-localCharacter.getPitch() / 36000.0f * TAU), glm::vec3(1.0f, 0.0f, 0.0f));
	viewMatrix = glm::rotate(viewMatrix, (float) (-localCharacter.getYaw() / 36000.0f * TAU), glm::vec3(0.0f, 1.0f, 0.0f));
	viewMatrix = glm::rotate(viewMatrix, (float) (-TAU / 4.0), glm::vec3(1.0f, 0.0f, 0.0f));
	viewMatrix = glm::rotate(viewMatrix, (float) (TAU / 4.0), glm::vec3(0.0f, 0.0f, 1.0f));

	defaultShader.setViewMatrix(viewMatrix);
	defaultShader.setLightEnabled(true);
	defaultShader.setFogEnabled(client->getConf().fog != Fog::NONE);

	for (uint i = 0; i < MAX_CLIENTS; i++) {
		if (i == client->getLocalClientId())
			continue;
		Character &character = client->getWorld()->getCharacter(i);
		if (!character.isValid())
			continue;
		vec3i64 pDiff = character.getPos() - localCharacter.getPos();
		glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(
			(float) pDiff[0] / RESOLUTION,
			(float) pDiff[1] / RESOLUTION,
			(float) pDiff[2] / RESOLUTION)
		);
		modelMatrix = glm::rotate(modelMatrix, (float) (character.getYaw() / 36000.0f * TAU), glm::vec3(0.0f, 0.0f, 1.0f));

		defaultShader.setModelMatrix(modelMatrix);
		defaultShader.useProgram();

		GL(BindVertexArray(bodyVao));
		GL(DrawArrays(GL_TRIANGLES, 0, 144));

		modelMatrix = glm::translate(modelMatrix, glm::vec3(
			0.0f,
			0.0f,
			(float)  HEAD_ANCHOR_Z_OFFSET / RESOLUTION)
		);

		int pitch = clamp(character.getPitch(), PITCH_MIN * 100, PITCH_MAX * 100);
		modelMatrix = glm::rotate(modelMatrix, (float) (-pitch / 36000.0f * TAU), glm::vec3(0.0f, 1.0f, 0.0f));

		defaultShader.setModelMatrix(modelMatrix);
		defaultShader.useProgram();

		GL(BindVertexArray(headVao));
		GL(DrawArrays(GL_TRIANGLES, 0, 144));
		GL(BindVertexArray(0));
	}
}
예제 #4
0
int
rb_vertex_index_array(struct rb_vertex_array* array, struct rb_buffer* buffer)
{
  if(!array || (buffer && buffer->target != GL_ELEMENT_ARRAY_BUFFER))
    return -1;

  OGL(BindVertexArray(array->name));
  OGL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer ? buffer->name : 0));
  OGL(BindVertexArray(array->ctxt->state_cache.vertex_array_binding));
  OGL(BindBuffer
    (GL_ELEMENT_ARRAY_BUFFER,
     array->ctxt->state_cache.buffer_binding[RB_OGL3_BIND_INDEX_BUFFER]));

  return 0;
}
예제 #5
0
void GLShaderProgram::RegisterVertexArray(float *vertices, int vertexSize, unsigned int *indices, int indexSize)
{
	glGenVertexArrays(1, &m_uiVAO);
	glGenBuffers(1, &m_uiVBO);
	glGenBuffers(1, &m_uiEBO);

	// Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
	BindVertexArray();

	if (NULL != vertices) {
		glBindBuffer(GL_ARRAY_BUFFER, m_uiVBO);
		glBufferData(GL_ARRAY_BUFFER, vertexSize, vertices, GL_STATIC_DRAW);
	}

	if (NULL != indices) {
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_uiEBO);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize, indices, GL_STATIC_DRAW);
	}

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
	glEnableVertexAttribArray(2);

	glBindBuffer(GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind

	UnbindVertexArray(); // Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs), remember: do NOT unbind the EBO, keep it bound to this VAO
}
예제 #6
0
void MeshRenderer::InitializeCoordinateAxesMeshRenderer(const int& length){
	m_mesh->InitializeMeshCoordinateAxes(length);

	m_material->InitializeMaterial("Data/Shaders/basic.vert", "Data/Shaders/basic.frag");
	m_material->m_samplerInUse = false;
	BindVertexArray();
}
예제 #7
0
void CGLDevice::DrawArrays(Renderer::PrimitiveType mode, uint32_t base_vertex, uint32_t count)
{
	if (!count)
		return;

	BindVertexArray();
	glDrawArrays(ToGLPrimitiveType(mode), base_vertex, count);
}
예제 #8
0
void GL3CharacterRenderer::buildHead() {
	GL(GenVertexArrays(1, &headVao));
	GL(GenBuffers(1, &headVbo));
	GL(BindVertexArray(headVao));
	GL(BindBuffer(GL_ARRAY_BUFFER, headVbo));
	GL(VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 40, 0));
	GL(VertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 40, (void *) 12));
	GL(VertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 40, (void *) 24));
	GL(EnableVertexAttribArray(0));
	GL(EnableVertexAttribArray(1));
	GL(EnableVertexAttribArray(2));
	GL(BindVertexArray(0));

	VertexData vertexData[36];
	int vertexIndices[6] = {0, 1, 2, 0, 2, 3};
	int index = 0;
	for (int d = 0; d < 6; d++) {
		vec3f normal(0.0);
		normal[d % 3] = DIRS[d][d % 3];
		vec3f vertices[4];
		for (int i = 0; i < 4; i++) {
			vertices[i] = vec3f(
				(DIR_QUAD_CORNER_CYCLES_3D[d][i][0] - 0.5f) * HEAD_SIZE[0],
				(DIR_QUAD_CORNER_CYCLES_3D[d][i][1] - 0.5f) * HEAD_SIZE[1],
				(DIR_QUAD_CORNER_CYCLES_3D[d][i][2] - 0.5f) * HEAD_SIZE[2] + HEAD_Z_OFFSET
			) * (1.0f / RESOLUTION);
		}
		for (int j = 0; j < 6; j++) {
			vertexData[index].xyz[0] = vertices[vertexIndices[j]][0];
			vertexData[index].xyz[1] = vertices[vertexIndices[j]][1];
			vertexData[index].xyz[2] = vertices[vertexIndices[j]][2];
			vertexData[index].nxyz[0] = normal[0];
			vertexData[index].nxyz[1] = normal[1];
			vertexData[index].nxyz[2] = normal[2];
			vertexData[index].rgba[0] = CHARACTER_COLOR[0];
			vertexData[index].rgba[1] = CHARACTER_COLOR[1];
			vertexData[index].rgba[2] = CHARACTER_COLOR[2];
			vertexData[index].rgba[3] = 1.0f;
			index++;
		}
	}

	GL(BufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW));
	GL(BindBuffer(GL_ARRAY_BUFFER, 0));
}
예제 #9
0
int
rb_bind_vertex_array(struct rb_context* ctxt, struct rb_vertex_array* array)
{
  if(!ctxt)
    return -1;
  ctxt->state_cache.vertex_array_binding = array ? array->name : 0;
  OGL(BindVertexArray(ctxt->state_cache.vertex_array_binding));
  return 0;
}
예제 #10
0
void GLCpuPosInstancedArraysBench::teardown(const GrGLInterface* gl) {
    GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0));
    GR_GL_CALL(gl, BindVertexArray(0));
    GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
    GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
    GR_GL_CALL(gl, DeleteTextures(1, &fTexture));
    GR_GL_CALL(gl, DeleteProgram(fProgram));
    GR_GL_CALL(gl, DeleteBuffers(fBuffers.count(), fBuffers.begin()));
    GR_GL_CALL(gl, DeleteVertexArrays(1, &fVAO));
    fBuffers.reset();
}
void
WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
{
    if (!ValidateDeleteObject("deleteVertexArray", array))
        return;

    if (mBoundVertexArray == array)
        BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));

    array->RequestDelete();
}
void
WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
{
    const FuncScope funcScope(*this, "deleteVertexArray");
    if (!ValidateDeleteObject(array))
        return;

    if (mBoundVertexArray == array)
        BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));

    array->RequestDelete();
}
예제 #13
0
void GLCpuPosInstancedArraysBench::setup(const GrGLContext* ctx) {
    const GrGLInterface* gl = ctx->interface();
    fTexture = SetupFramebuffer(gl, kScreenWidth, kScreenHeight);

    fProgram = this->setupShader(ctx);

    // setup matrices
    int index = 0;
    SkMatrix viewMatrices[kNumTri];
    setup_matrices(kNumTri, [&index, &viewMatrices](const SkMatrix& m) {
        viewMatrices[index++] = m;
    });

    // setup VAO
    GR_GL_CALL(gl, GenVertexArrays(1, &fVAO));
    GR_GL_CALL(gl, BindVertexArray(fVAO));

    switch (fVboSetup) {
        case kUseOne_VboSetup:
            this->setupSingleVbo(gl, viewMatrices);
            break;
        case kUseTwo_VboSetup:
            this->setupDoubleVbo(gl, viewMatrices);
            break;
        case kUseInstance_VboSetup:
            this->setupInstanceVbo(gl, viewMatrices);
            break;
    }

    // clear screen
    GR_GL_CALL(gl, ClearColor(0.03f, 0.03f, 0.03f, 1.0f));
    GR_GL_CALL(gl, Clear(GR_GL_COLOR_BUFFER_BIT));

    // set us up to draw
    GR_GL_CALL(gl, UseProgram(fProgram));
    GR_GL_CALL(gl, BindVertexArray(fVAO));
}
예제 #14
0
void
WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
{
    if (IsContextLost())
        return;

    if (array == nullptr)
        return;

    if (array->IsDeleted())
        return;

    if (mBoundVertexArray == array)
        BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));

    array->RequestDelete();
}
예제 #15
0
void GLInstancedArraysBench::onPerCanvasPostDraw(SkCanvas* canvas) {
    // This bench exclusively tests GL calls directly
    const GrGLContext* ctx = get_gl_context(canvas);
    if (!ctx) {
        return;
    }

    const GrGLInterface* gl = ctx->interface();

    // teardown
    GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0));
    GR_GL_CALL(gl, BindVertexArray(0));
    GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
    GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
    GR_GL_CALL(gl, DeleteTextures(1, &fTexture));

    this->teardown(gl);
}
예제 #16
0
void GLGpuPosInstancedArraysBench::setup(const GrGLInterface* gl) {
    setup_framebuffer(gl, kScreenWidth, kScreenHeight);

    // compile and use shaders
    GrGLint shaderProgram = compile_shader(gl, gpu_vertex_shader, fragment_shader);

    // translations
    int index = 0;
    GrGLfloat viewMatrices[fNumQuads * fSkMatrixNumCells];
    setup_matrices(fNumQuads, [&index, &viewMatrices](const SkMatrix& m) {
        GrGLGetMatrix<3>(&viewMatrices[index], m);
        index += fSkMatrixNumCells;
    });

    // Constants for our various shader programs
    GrGLfloat quad_vertices[] = {
            // Positions // Colors
            -1.0f,  1.0f,  1.0f, 0.0f, 0.0f,
             1.0f, -1.0f,  0.0f, 1.0f, 0.0f,
            -1.0f, -1.0f,  0.0f, 0.0f, 1.0f,

            -1.0f,  1.0f,  1.0f, 0.0f, 0.0f,
             1.0f, -1.0f,  0.0f, 1.0f, 0.0f,
             1.0f,  1.0f,  0.0f, 1.0f, 1.0f
    };

    // update vertex data
    GrGLuint quadVAO, quadVBO;
    GR_GL_CALL(gl, GenVertexArrays(1, &quadVAO));
    GR_GL_CALL(gl, GenBuffers(1, &quadVBO));
    GR_GL_CALL(gl, BindVertexArray(quadVAO));
    GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, quadVBO));
    GR_GL_CALL(gl, EnableVertexAttribArray(0));
    GR_GL_CALL(gl, VertexAttribPointer(0, 2, GR_GL_FLOAT, GR_GL_FALSE, 5 * sizeof(GrGLfloat), (GrGLvoid*)0));
    GR_GL_CALL(gl, EnableVertexAttribArray(1));
    GR_GL_CALL(gl, VertexAttribPointer(1, 3, GR_GL_FLOAT, GR_GL_FALSE, 5 * sizeof(GrGLfloat), (GrGLvoid*)(2 * sizeof(GrGLfloat))));
    GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(quad_vertices), quad_vertices, GR_GL_STATIC_DRAW));

    // Also set instance data
    GrGLuint instanceVBO;
    GR_GL_CALL(gl, GenBuffers(1, &instanceVBO));
    GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, instanceVBO));
    GR_GL_CALL(gl, BufferData(GR_GL_ARRAY_BUFFER, sizeof(GrGLfloat) * fSkMatrixNumCells * fNumQuads,
                              &viewMatrices[0], GR_GL_STATIC_DRAW));
    GR_GL_CALL(gl, EnableVertexAttribArray(2));
    GR_GL_CALL(gl, EnableVertexAttribArray(3));
    GR_GL_CALL(gl, EnableVertexAttribArray(4));
    GR_GL_CALL(gl, VertexAttribPointer(2, 3, GR_GL_FLOAT, GR_GL_FALSE, 9 * sizeof(GrGLfloat), (GrGLvoid*)0));
    GR_GL_CALL(gl, VertexAttribPointer(3, 3, GR_GL_FLOAT, GR_GL_FALSE, 9 * sizeof(GrGLfloat), (GrGLvoid*)(3 * sizeof(GrGLfloat))));
    GR_GL_CALL(gl, VertexAttribPointer(4, 3, GR_GL_FLOAT, GR_GL_FALSE, 9 * sizeof(GrGLfloat), (GrGLvoid*)(6 * sizeof(GrGLfloat))));
    GR_GL_CALL(gl, VertexAttribDivisor(2, 1));
    GR_GL_CALL(gl, VertexAttribDivisor(3, 1));
    GR_GL_CALL(gl, VertexAttribDivisor(4, 1));

    // draw
    GR_GL_CALL(gl, ClearColor(0.03f, 0.03f, 0.03f, 1.0f));
    GR_GL_CALL(gl, Clear(GR_GL_COLOR_BUFFER_BIT));

    // set us up to draw
    GR_GL_CALL(gl, UseProgram(shaderProgram));
    GR_GL_CALL(gl, BindVertexArray(quadVAO));
}
예제 #17
0
void clGLVertexArray::SetVertexAttribs( clVertexAttribs* Attribs )
{
	iVertexArray::SetVertexAttribs( Attribs );

	FATAL( Attribs->FVertices.size() == 0, "Unable to use zero-size vertex array" );

	const bool UseVBO = true;

#ifdef USE_VAO

	if ( FVAOID )
	{
		LGL3->glDeleteVertexArrays( 1, &FVAOID );
	}

	LGL3->glGenVertexArrays( 1, &FVAOID );
#endif

	// setup 32-bit indices
	if ( UseVBO && Attribs->FIndices.GetPtr() )
	{
		if ( FVBOIndicesID )
		{
			LGL3->glDeleteBuffers( 1, &FVBOIndicesID );
		}

		LGL3->glGenBuffers( 1, &FVBOIndicesID );
		//LGL3->glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, FVBOIndicesID );
		FLocalRenderer->SetActiveVBO( FVBOID, FVBOIndicesID );
		LGL3->glBufferData( GL_ELEMENT_ARRAY_BUFFER,
		                    Attribs->FIndices.size() * sizeof( Luint ),
		                    Attribs->FIndices.GetPtr(),
		                    GL_STATIC_DRAW );
	}

	clVertexAttribs* SrcVA = GetVertexAttribs();
	FEnumeratedStreams = SrcVA->EnumerateVertexStreams();

	// setup vertices
	if ( UseVBO )
	{
		if ( FVBOID )
		{
			LGL3->glDeleteBuffers( 1, &FVBOID );
		}

		size_t VertexCount = Attribs->FVertices.size();

		size_t DataSize = 0;

		for ( int i = 0; i != L_VS_TOTAL_ATTRIBS; i++ )
		{
			DataSize += FEnumeratedStreams[i] ? sizeof( float ) * L_VS_VEC_COMPONENTS[ i ] * VertexCount : 0;
		}

		RegenerateOffsets();

//      Lenum UsageFlag = GetVertexAttribs()->FDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
		Lenum UsageFlag = GetVertexAttribs()->FDynamic ? GL_STREAM_DRAW : GL_STATIC_DRAW;

		LGL3->glGenBuffers( 1, &FVBOID );
//		LGL3->glBindBuffer( GL_ARRAY_BUFFER, FVBOID );
		FLocalRenderer->SetActiveVBO( FVBOID, FVBOIndicesID );
		LGL3->glBufferData( GL_ARRAY_BUFFER, DataSize, NULL, UsageFlag );
#ifdef USE_VAO
		LGL3->glBindVertexArray( FVAOID );
		BindVertexArray( NULL );
		LGL3->glBindVertexArray( 0 );
#endif
	}
	else
	{
		// just use pointers
		FAttribVBOOffset = GetVertexAttribs()->EnumerateVertexStreams();
	}

	CommitChanges();
}
예제 #18
0
void MeshRenderer::InitializeMeshRenderer(const Mesh& mesh, const Material& material){
	SetMesh(mesh);
	SetMaterial(material);

	BindVertexArray();
}
 inline void glBindVertexArray(GLuint array)
 {
     BindVertexArray(array);
 }