void ComponentParticleSystem::Draw(bool show_billboard)
{
    if(alive_particles > 0)
    {
        UpdateInstanceBuffer();

        const ResourceTexture* tex_res = static_cast<const ResourceTexture*>(App->resources->Get(texture_info.texture));

        if(!show_billboard)
        {
            glEnable(GL_BLEND);
            if(blend_mode == AdditiveBlend)
            {
                glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            }
            else
            {
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            }
        }


        glDepthMask(GL_FALSE);

        if(tex_res)
        {
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, tex_res->GetID());
            glUniform1i(TEXTURE_MAP_LOC, 0);
        }

        float4x4 transform = GetGameObject()->GetGlobalTransformation();
        glUniformMatrix4fv(App->programs->GetUniformLocation("model"), 1, GL_TRUE, reinterpret_cast<const float*>(&transform));

        glUniform1i(SHEET_LOC, texture_info.x_tiles);
        glUniform1i(SHEET_LOC+1, texture_info.y_tiles);

        glBindVertexArray(render_buffers.vao);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, render_buffers.ibo);

        if(show_billboard)
        {
            glDrawElementsInstanced(GL_LINE_LOOP, 6, GL_UNSIGNED_INT, nullptr, alive_particles); 
        }
        else
        {
            glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr, alive_particles); 
        }

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
        glBindVertexArray(0);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, 0);

        glDisable(GL_BLEND);
		glDepthMask(GL_TRUE);
    }
}
示例#2
1
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);
			glm::mat4* Pointer = static_cast<glm::mat4*>(glMapBufferRange(GL_UNIFORM_BUFFER,
				0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));

			//glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f);
			glm::mat4 const Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
		
			*Pointer = Projection * this->view();

			// Make sure the uniform buffer is uploaded
			glUnmapBuffer(GL_UNIFORM_BUFFER);
		}

		// Render a textured quad to a sRGB framebuffer object.
		{
			glViewport(0, 0, static_cast<GLsizei>(WindowSize.x) * this->FramebufferScale, static_cast<GLsizei>(WindowSize.y) * this->FramebufferScale);
			glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

			float Depth(1.0f);
			glClearBufferfv(GL_DEPTH, 0, &Depth);
			glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

			glUseProgram(ProgramName[program::TEXTURE]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
			glBindVertexArray(VertexArrayName[program::TEXTURE]);
			glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

			glDrawElementsInstanced(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1);
		}

		// Blit the sRGB framebuffer to the default framebuffer back buffer.
		{
			glDisable(GL_DEPTH_TEST);

			glViewport(0, 0, static_cast<GLsizei>(WindowSize.x), static_cast<GLsizei>(WindowSize.y));
			glBindFramebuffer(GL_FRAMEBUFFER, 0);

			glUseProgram(ProgramName[program::SPLASH]);

			glActiveTexture(GL_TEXTURE0);
			glBindVertexArray(VertexArrayName[program::SPLASH]);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);

			glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);
		}

		return true;
	}
示例#3
0
// http://www.packtpub.com/article/tips-tricks-getting-started-with-opengl-glsl-4'
// http://www.packtpub.com/article/opengl-glsl-4-shaders-basics
// http://sol.gfxile.net/instancing.html
void RenderGroup(std::vector<Coordinate> coordinates, Color color, int modelNum)
{
	CreateInstancedTransformMatrices(coordinates);

	// Upload uniform data
	glUniform3f(ModelShaderColorId, color.R, color.G, color.B);

	// Draw
	glEnableVertexAttribArray(0);

	// 1rst attribute buffer : vertices
	glBindBuffer(GL_ARRAY_BUFFER, VertexBufferId);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBufferId);

	// Draw the triangle !
	glVertexAttribPointer(
		0,                  // attribute. No particular reason for 0, but must match the layout in the shader.
		3,                  // size
		GL_FLOAT,           // type
		GL_FALSE,           // normalized?
		0,                  // stride
		(void*)0            // array buffer offset
		);

	glDrawElementsInstanced(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, 0, coordinates.size());
	//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, (void*)0);

	glDisableVertexAttribArray(0);
}
示例#4
0
文件: cube.cpp 项目: LeuhFahn/OpenGL
void CCube::Draw(float fDeltatime)
{
	m_fTime += fDeltatime;

		// Get camera matrices
	glm::mat4 projection = CScene::ms_Camera.projection; 
	glm::mat4 worldToView = CScene::ms_Camera.worldToView;
    glm::mat4 objectToWorld;
    glm::mat4 worldToScreen = CScene::ms_Camera.worldToScreen;
    glm::mat4 screenToWorld = glm::transpose(glm::inverse(worldToScreen));

	glUseProgram(m_Shader.program);
	glUniform1f(timeLocation, m_fTime);
	glUniform1i(sqrtNbInstanceLocation, sqrtf(m_nNbInstance));
	glUniformMatrix4fv(projectionLocation, 1, 0, glm::value_ptr(projection));
	glUniformMatrix4fv(viewLocation, 1, 0, glm::value_ptr(worldToView));
	glUniformMatrix4fv(objectLocation, 1, 0, glm::value_ptr(objectToWorld));

	glUniform1i(diffuseLocation, 0);

	// Bind textures
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, m_pTextures[0]);

	// Render vaos
    glBindVertexArray(m_Vao);
    glDrawElementsInstanced(GL_TRIANGLES, m_nNbVertices * 3, GL_UNSIGNED_INT, (void*)0, m_nNbInstance);
}
示例#5
0
void ChOpenGLMesh::Draw(const mat4& projection, const mat4& view) {
    if (GLReturnedError("ChOpenGLMesh::Draw - on entry"))
        return;

    // Enable the shader
    shader->Use();
    GLReturnedError("ChOpenGLMesh::Draw - after use");
    // Send our common uniforms to the shader
    shader->CommonSetup(value_ptr(projection), value_ptr(view));

    GLReturnedError("ChOpenGLMesh::Draw - after common setup");
    // Bind and draw! (in this case we draw as triangles)
    glBindVertexArray(this->vertex_array_handle);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_data_handle);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_ambient_handle);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_diffuse_handle);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_model_handle);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->vertex_element_handle);

    GLReturnedError("ChOpenGLMesh::Draw - before draw");
    glDrawElementsInstanced(GL_TRIANGLES, (GLsizei)this->vertex_indices.size(), GL_UNSIGNED_INT, (void*)0, size);
    GLReturnedError("ChOpenGLMesh::Draw - after draw");
    // unbind everything and cleanup
    glBindVertexArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glUseProgram(0);

    if (GLReturnedError("ChOpenGLMesh::Draw - on exit"))
        return;
}
示例#6
0
文件: Mesh.cpp 项目: fohr/Graphtane
void Mesh::render()
{
	int vertexAttributeCount = m_vertexAttributes.size();
	for (int i = 0; i < vertexAttributeCount; i++)
	{
		m_vertexAttributes[i].applyState();
	}

	// Index buffer
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);

	if (m_glPrimitiveType == GL_PATCHES)
	{
		glPatchParameteri(GL_PATCH_VERTICES, m_patchVertCount);
	}

	if (m_instanceCount > 1)
	{
		glDrawElementsInstanced(m_glPrimitiveType, m_indexCount, GL_UNSIGNED_INT,
			(void*)0, 			// element array buffer offset
			m_instanceCount
		);
	}
	else
	{
		glDrawElements(m_glPrimitiveType, m_indexCount, GL_UNSIGNED_INT,
			(void*)0			// element array buffer offset
		);
	}

	for (int i = 0; i < vertexAttributeCount; i++)
	{
		m_vertexAttributes[i].unapplyState();
	}
}
void			neb::gfx::mesh::instanced::draw(
		neb::gfx::mesh::instanced::program_type*		program,
		std::shared_ptr<neb::gfx::glsl::buffer::instanced>	buf)
{
	LOG(lg, neb::gfx::sl, debug) << __PRETTY_FUNCTION__;

	assert(instances_);

	//auto buf_mesh = mesh_.getBuffer(program);
	auto bt = mesh_.getBufferTuple(program);

	buf->vertexAttribPointer();
	//buf_mesh->vertexAttribPointer();
	
	mesh_.vertexAttribPointer(bt);

	LOG(lg, neb::gfx::sl, debug) << "instances size = " << instances_->size();
	LOG(lg, neb::gfx::sl, debug) << "mesh size      = " << mesh_.getNbIndices();

	mesh_.bind(bt);

	auto s = instances_->size();

	glDrawElementsInstanced(
			GL_TRIANGLES,
			mesh_.getNbIndices(),
			GL_UNSIGNED_SHORT,
			0,
			s);

	checkerror("glDrawElementsInstanced");

	mesh_.unbind(bt);
}
示例#8
0
			void OBJMesh::OBJShape::draw(size_t numInstances) const
			{
				glBindVertexArray(vao);
				glDrawElementsInstanced(GL_TRIANGLES, static_cast<GLsizei>(shape.mesh.indices.size()), GL_UNSIGNED_INT, 0, static_cast<GLsizei>(numInstances));
				glBindVertexArray(0);
				PGA_Rendering_GL_checkError();
			}
示例#9
0
void RenderTarget::draw( const RenderCommand& command )
{
	if( command.instanceCount != 0 )
		glDrawElementsInstanced( static_cast< GLenum >( command.primitive ), command.count, GL_UNSIGNED_INT, reinterpret_cast< const GLvoid* >( command.offset * 4 ), command.instanceCount );
	else
		glDrawElements( static_cast< GLenum >( command.primitive ), command.count, GL_UNSIGNED_INT, reinterpret_cast< const GLvoid* >( command.offset * 4 ) );
}
示例#10
0
void InstanceSet::draw(const CameraInterface *camera,
                       ponos::Transform transform) {
  // bind buffers and locate attributes
  shader_.begin();
  baseMesh_.bind();
  baseMesh_.vertexBuffer()->locateAttributes(shader_);
  for (size_t i = 0; i < buffers_.size(); i++) {
    bind(i);
    buffers_[i]->locateAttributes(shader_, 1);
  }
  shader_.setUniform("model_view_matrix",
                     ponos::transpose(camera->getViewTransform().matrix()));
  shader_.setUniform(
      "projection_matrix",
      ponos::transpose(camera->getProjectionTransform().matrix()));
  CHECK_GL_ERRORS;
  //  shader_.setUniform("mvp",
  //  ponos::transpose((camera->getProjectionTransform() *
  //      camera->getViewTransform() * camera->getModelTransform()).matrix()));
  glDrawElementsInstanced(
      baseMesh_.indexBuffer()->bufferDescriptor.elementType,
      baseMesh_.indexBuffer()->bufferDescriptor.elementSize *
          baseMesh_.indexBuffer()->bufferDescriptor.elementCount,
      baseMesh_.indexBuffer()->bufferDescriptor.dataType, 0, count_);
  CHECK_GL_ERRORS;
  shader_.end();
  baseMesh_.unbind();
}
// This function runs every frame
void renderScene()
{
	// Clear the color buffer and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Clear the screen to white
	glClearColor(1.0, 1.0, 1.0, 1.0);

	// Tell OpenGL to use the shader program you've created.
	glUseProgram(program);

	// This sets our uniform MVP matrix within our shader to the MVP value.
	// Parameters are: Location within the shader, size (in case we're passing in multiple matrices via a single pointer), whether or not to transpose the matrix, and a pointer 
	// to the matrix value we're passing in.
	glUniformMatrix4fv(uniMVP, 1, GL_FALSE, glm::value_ptr(MVP));
	glUniformMatrix4fv(uniMVP2, 1, GL_FALSE, glm::value_ptr(MVP2));
	// In this case, we're setting the individual matrices in the array (size 2) by their specific reference.

	// Draw 36 vertices from the buffer as GL_TRIANGLES
	// There are several different drawing modes, GL_TRIANGLES takes every 3 vertices and makes them a triangle.
	// For reference, GL_TRIANGLE_STRIP would take each additional vertex after the first 3 and consider that a 
	// triangle with the previous 2 vertices (so you could make 2 triangles with 4 vertices)
	// The second parameter is the number of vertices, the third parameter is the type of the element buffer data, and the fourth parameter is the offset.
	// The fifth parameter is the number of instances to draw, which in this case is just 2. The instance is then passed in as gl_InstanceID to the Vertex Shader so that it may 
	// reference the proper matrix from the array.
	glDrawElementsInstanced(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0, 2);
	// This will draw two cubes using the same buffer and same draw call, but different uniform matrice.s
}
示例#12
0
void GModel::DrawInstansing(const GLuint vboInstPos, int instCount){

	glBindVertexArray(vao);		//Bind Model VAO

	int attrLoc = 3;		////@@Todo glGetAttribLocation  

	glEnableVertexAttribArray(attrLoc);	//enable attribute Location  
	glVertexAttribPointer(
		attrLoc,					// attribute 0. No particular reason for 0, but must match the layout in the shader.
		3,				// size	(Specifies the number of components)
		GL_FLOAT,			// type
		GL_FALSE,			// normalized?
		0,				// stride (Specifies the byte offset between consecutive generic vertex attributes)
		(void*)0		// array buffer offset (Specifies a pointer to the first generic vertex attribute in the array)
		);


	// これらの関数はglDrawArrays *Instanced* 特有です。
	// 最初のパラメータは注目してる属性バッファです。
	// 二つ目のパラメータは、複数のインスタンスを描画するときに一般的な頂点属性が進む割合を意味します。
	// http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribDivisor.xml

	// インスタンスを有効化し除数を指定する
	glVertexAttribDivisor(attrLoc, 1); // 位置:modelごとに一つ(中心)->1

	GLsizei elements = (GLsizei)Index.size()*sizeof(u16vec3);
	glDrawElementsInstanced(GL_TRIANGLES, elements, GL_UNSIGNED_SHORT, 0, instCount);

	glBindVertexArray(0);

}
示例#13
0
//-----------------------------------------------------------------------
void GraphicsContextGL4::DrawIndexedInstanced(
    std::size_t indexCount,
    std::size_t instanceCount)
{
    ApplyPipelineState();

    // Bind index buffer
    POMDOG_ASSERT(indexBuffer);
    auto indexBufferGL = dynamic_cast<IndexBufferGL4*>(indexBuffer->NativeIndexBuffer());
    POMDOG_ASSERT(indexBufferGL != nullptr);
    indexBufferGL->BindBuffer();

    // Draw
    POMDOG_ASSERT(indexCount > 0);
    POMDOG_ASSERT(indexCount <= indexBuffer->IndexCount());
    POMDOG_ASSERT(instanceCount > 0);
    POMDOG_ASSERT(instanceCount < static_cast<decltype(instanceCount)>(std::numeric_limits<GLsizei>::max()));

    glDrawElementsInstanced(
        primitiveTopology.value,
        static_cast<GLsizei>(indexCount),
        ToIndexElementType(indexBuffer->ElementSize()),
        nullptr,
        static_cast<GLsizei>(instanceCount));
    POMDOG_CHECK_ERROR_GL4("glDrawElementsInstanced");
}
示例#14
0
void MyView::geometryPass()
{
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gbuffer_fbo_);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LESS);
	glDisable(GL_BLEND);

	//G-buffer geometry pass
	glCullFace(GL_BACK);
	glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_ALWAYS, 0, ~0);
	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);

	GLuint program = shaderPrograms_[PRE_SHADER];
	glUseProgram(program);

	Mesh mesh;

	for (int i = 0; i < meshes_.size(); i++)
	{
		mesh = meshes_[i];
		glBindVertexArray(mesh.vao);
		glDrawElementsInstanced(GL_TRIANGLES, mesh.element_count, GL_UNSIGNED_INT, 0, mesh.instanceIDs.size());
	}
}
示例#15
0
void CGLGraphics::DrawInstanced(PrimitiveType primitive, size_t instanceCount, S_CBuffer elementBuffer) {
    if (m_currentBuffer == nullptr) {
        fprintf(stderr, "Tried to draw instanced with nullptr buffer!! Did you forget to call SetDrawBuffer?\n");
        return;
    }

    S_CGLProgram gl_prog = std::static_pointer_cast<CGLProgram>(m_drawProgram);
    glUseProgram(gl_prog->GetOpenGLHandle());

    GLenum gl_primitive = CGLGraphics::GetOpenGLPrimitiveTypeEnum(primitive);

    if (elementBuffer != nullptr) {
        S_CGLBuffer gl_elementBuffer = std::static_pointer_cast<CGLBuffer>(elementBuffer);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_elementBuffer->GetOpenGLHandle());

        glDrawElementsInstanced(
            gl_primitive,
            (GLsizei)instanceCount,
            GL_UNSIGNED_SHORT,
            NULL,
            (GLsizei)gl_elementBuffer->GetElementCount()
        );
    } else {
        glDrawArraysInstanced(
            gl_primitive,
            0,
            (GLsizei)m_currentBuffer->GetElementCount(),
            (GLsizei)instanceCount
        );
    }
}
示例#16
0
void Cube::RenderCube()
{
	glBindBuffer( GL_ARRAY_BUFFER, matrixId );
    glm::mat4* matrixBuf = (glm::mat4*)glMapBufferRange( GL_ARRAY_BUFFER, 0, sizeof(glm::mat4*)*(dimension*dimension*dimension), GL_MAP_WRITE_BIT);
    static float l = 0;
    TransformObj->TransformRotate(l++, 1, 1, 1);
    TransformObj->TransformTranslate(-distance*dimension/4,  -distance*dimension/4, -distance*dimension/4);
    glm::mat4 projectionMatrix  = *TransformObj->TransformGetProjectionMatrix();
    glm::mat4 modelMatrix       = *TransformObj->TransformGetModelMatrix();
    glm::mat4 viewMatrix        = *TransformObj->TransformGetViewMatrix();
    int instance = 0;
    for ( int i = 0; i < dimension; i++ )
    {
        for ( int j = 0; j < dimension; j++ )
        {
            for ( int k = 0; k < dimension; k++ )
            {
                matrixBuf[instance++] = projectionMatrix * viewMatrix * glm::translate(modelMatrix, glm::vec3( i*distance , j*distance, k*distance)) * glm::rotate( modelMatrix, l, glm::vec3(1.0, 0.0, 0.0));
            }
        }
    }
    glUnmapBuffer ( GL_ARRAY_BUFFER );

    glBindVertexArray(Vertex_VAO_Id);
    glDrawElementsInstanced(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, (void*)0, dimension*dimension*dimension);
}
示例#17
0
 void Mesh::DrawInstanced (Shader* shader, unsigned instCount)
 {
   shader->UseShader ();
   m_vao->Bind ();
   glDrawElementsInstanced (GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0, instCount);
   m_vao->Unbind ();
   shader->DisableShader ();
 }
			void CGraphicsContext::DrawInstanced(SharedPointer<IPipelineState> State, uint const InstanceCount)
			{
				Window->MakeContextCurrent();
				InternalDrawSetup(State);
				SharedPointer<GL::CPipelineState> PipelineState = std::dynamic_pointer_cast<GL::CPipelineState>(State);
				CheckedGLCall(glDrawElementsInstanced(GL_TRIANGLES, (int) PipelineState->IndexBuffer->Size, GL_UNSIGNED_INT, 0, InstanceCount));
				InternalDrawTeardown(State);
			}
示例#19
0
void QuadDrawer::DrawQuads(int amount)
{
	if (!instance)
		Initialise();
	glBindVertexArray(instance->vaoID);
	glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, (void*)0, amount);
	glBindVertexArray(0);
}
示例#20
0
void VertexBuffer::DrawElementsInstanced(GLenum mode, GLsizei count,
	GLenum type, GLsizei instanceCount, int offset)
{
	ProgramObject *p = rc->GetCurProgram();
	if (p) p->updateMatrices();
	Bind();
	glDrawElementsInstanced(mode, count, type, (void *)offset, instanceCount);
}
示例#21
0
文件: mesh.cpp 项目: ezhangle/fplbase
void Mesh::DrawElement(Renderer &renderer, int32_t count, int32_t instances) {
  if (instances == 1) {
    GL_CALL(glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0));
  } else {
    (void)renderer;
    assert(renderer.feature_level() == Renderer::kFeatureLevel30);
    GL_CALL(glDrawElementsInstanced(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0,
                                    instances));
  }
}
示例#22
0
void AFK_3DEdgeShapeBase::draw(size_t instanceCount) const
{
    glDrawElementsInstanced(
        GL_LINE_STRIP_ADJACENCY,
        static_cast<GLsizei>(indices.size()),
        GL_UNSIGNED_SHORT,
        0,
        static_cast<GLsizei>(instanceCount));
    AFK_GLCHK("3d edge shape draw")
}
GLvoid CInstancedRenderer::Render(std::list<CEntity> entities)
{
	if (!entities.empty())
	{
		Models::CRawModel model = entities.front().GetTexturedModel().GetRawModel();
		glBindVertexArray(model.GetVaoId());
		glDrawElementsInstanced(GL_TRIANGLES, model.GetVertexCount(), GL_UNSIGNED_INT, 0, entities.size());
		glBindVertexArray(0);
	}	
}
示例#24
0
void DrawInstance::Render(){
    glClearColor(0.0f, 0.25f, 0.0f, 1.0f);
    glClearDepth(1.0f);
    glPointSize(15.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBindVertexArray(vao);
    m_pg->UseProgram();
    //glColorMask(0, 0, 0, 0);
    glDrawElementsInstanced(GL_POINTS, 1, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0), INSTANCE_COUNT);
}
示例#25
0
void IndexBuffer::draw(size_t s, VertexMode primitive, size_t nbInstance=0) const
{
    bind();
    s = std::min(s, size());

    if(nbInstance>0)
        glDrawElementsInstanced(IndexBuffer::GLPrimitive[primitive], s, GL_UNSIGNED_INT, 0, nbInstance);
    else
        glDrawElements(IndexBuffer::GLPrimitive[primitive], s, GL_UNSIGNED_INT, 0);
}
示例#26
0
// loop for drawing the planet and asteroids
void game_loop_model(GLFWwindow* win, const int option, const Shader& shad) {
    Model m_planet {model_path + "planet/planet.obj"};
    Model m_rock {model_path + "rock/rock.obj"};
    GLuint n {};
    double radius {}, offset {};
    if (option == 2) {
        n = 2000;
        radius = 50;
        offset = 2.5;
    } else {
        main_cam = Camera {glm::vec3{0, 5, 200}};
        n = 10000;
        radius = 150;
        offset = 25;
    }
    static const auto mod_mats = transform_mats(n, radius, offset);

    Shader rock_shad {shad_path + "model_loading_04.vs",
        shad_path + "model_loading_01.frag"};
    if (option == 3)
        bind_mat4(m_rock, mod_mats);

    const static auto win_asp = window_aspect_ratio(win);
    const auto idx = shad.id();
    while (!glfwWindowShouldClose(win)) {
        const auto curr_time = glfwGetTime();
        delta_frame_time = curr_time - last_frame_time;
        last_frame_time  = curr_time;
        glfwPollEvents();
        do_movement();
        glClearColor(0.2, 0.2, 0.2, 1);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        handle_camera_matrices(shad, rock_shad, win_asp, option);

        m_planet.draw(shad);
        if (option == 2) { // drawing rocks
            for (GLuint i {0}; i < n; ++i) {
                glUniformMatrix4fv(glGetUniformLocation(idx, "model"), 1,
                        GL_FALSE, glm::value_ptr(mod_mats[i]));
                m_rock.draw(shad);
            }
        } else {
            rock_shad.use();
            glBindTexture(GL_TEXTURE_2D, m_rock.texture_id(0));
            for (GLuint i {0}; i < m_rock.num_meshes(); ++i) {
                glBindVertexArray(m_rock.mesh_vao(i));
                glDrawElementsInstanced(GL_TRIANGLES,
                        m_rock.num_mesh_vertices(i), GL_UNSIGNED_INT, 0, n);
                glBindVertexArray(0);
            }
        }
        glfwSwapBuffers(win);
    }
}
示例#27
0
// Render the mesh
void Mesh::DrawInstanced(GLuint shader, int amount)
{
	setupTextures(shader);

	// Draw mesh
	glBindVertexArray(this->VAO);
	glDrawElementsInstanced(GL_TRIANGLES, this->indices.size(), GL_UNSIGNED_INT, 0, amount);
	glBindVertexArray(0);

	deactivateTextures();
}
示例#28
0
void Quads::draw() const
{
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuf);
    glDrawElementsInstanced(
        GL_TRIANGLES,
        indexDataCount(),
        Quads::IndexTypeID,
        0,
        transformDataCount()
    );
}
示例#29
0
void CDecalsDrawerGL4::DrawDecals()
{
	vboVertices.Bind(GL_ARRAY_BUFFER);
	vboIndices.Bind(GL_ELEMENT_ARRAY_BUFFER);
		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3, GL_FLOAT, 0, vboVertices.GetPtr());
			glDrawElementsInstanced(GL_TRIANGLES, vboIndices.GetSize(), GL_UNSIGNED_BYTE, vboIndices.GetPtr(), groups.size());
		glDisableClientState(GL_VERTEX_ARRAY);
	vboIndices.Unbind();
	vboVertices.Unbind();
}
void veParticleSphereRenderer::draw(veRenderCommand &command)
{
    if (!isNeedRendering())
        return;
    
    if (!command.pass->apply(command))
        return;
    
    glBindVertexArray(_vaoBuffer->getData(command.contextID));
    glDrawElementsInstanced(GL_TRIANGLES, GLsizei(_indices.size()), GL_UNSIGNED_SHORT, nullptr, _instanceCount);
}