Exemplo n.º 1
0
void FramebufferManager::PokeEFB(EFBAccessType type, const std::vector<EfbPokeData>& data)
{
	switch (type)
	{
	case POKE_COLOR:
	{
		g_renderer->ResetAPIState();

		glBindVertexArray(m_EfbColorPokes_VAO);
		glBindBuffer(GL_ARRAY_BUFFER, m_EfbColorPokes_VBO);
		glBufferData(GL_ARRAY_BUFFER, sizeof(EfbPokeData) * data.size(), data.data(), GL_STREAM_DRAW);
		m_EfbColorPokes.Bind();
		glViewport(0, 0, m_targetWidth, m_targetHeight);
		glDrawArrays(GL_POINTS, 0, (GLsizei)data.size());

		g_renderer->RestoreAPIState();

		// TODO: Could just update the EFB cache with the new value
		ClearEFBCache();
		break;
	}

	default:
		break;
	}
}
Exemplo n.º 2
0
void VertexManager::vFlush()
{
  GLVertexFormat* nativeVertexFmt = (GLVertexFormat*)VertexLoaderManager::GetCurrentVertexFormat();
  u32 stride = nativeVertexFmt->GetVertexStride();

  if (m_last_vao != nativeVertexFmt->VAO)
  {
    glBindVertexArray(nativeVertexFmt->VAO);
    m_last_vao = nativeVertexFmt->VAO;
  }

  PrepareDrawBuffers(stride);

  ProgramShaderCache::SetShader(m_current_primitive_type);

  // upload global constants
  ProgramShaderCache::UploadConstants();

  // setup the pointers
  nativeVertexFmt->SetupVertexPointers();

  if (::BoundingBox::active && !g_Config.BBoxUseFragmentShaderImplementation())
  {
    glEnable(GL_STENCIL_TEST);
  }

  Draw(stride);

  if (::BoundingBox::active && !g_Config.BBoxUseFragmentShaderImplementation())
  {
    OGL::BoundingBox::StencilWasUpdated();
    glDisable(GL_STENCIL_TEST);
  }

#if defined(_DEBUG) || defined(DEBUGFAST)
  if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
  {
    // save the shaders
    ProgramShaderCache::PCacheEntry prog = ProgramShaderCache::GetShaderProgram();
    std::string filename = StringFromFormat(
        "%sps%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId);
    std::ofstream fps;
    File::OpenFStream(fps, filename, std::ios_base::out);
    fps << prog.shader.strpprog;

    filename = StringFromFormat("%svs%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
                                g_ActiveConfig.iSaveTargetId);
    std::ofstream fvs;
    File::OpenFStream(fvs, filename, std::ios_base::out);
    fvs << prog.shader.strvprog;
  }
#endif
  g_Config.iSaveTargetId++;
  ClearEFBCache();
}
Exemplo n.º 3
0
void VertexManager::DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_vertex)
{
  if (::BoundingBox::active && !g_Config.BBoxUseFragmentShaderImplementation())
  {
    glEnable(GL_STENCIL_TEST);
  }

  if (m_current_pipeline_object)
  {
    static_cast<Renderer*>(g_renderer.get())->SetPipeline(m_current_pipeline_object);
    static_cast<Renderer*>(g_renderer.get())->DrawIndexed(base_index, num_indices, base_vertex);
  }

  if (::BoundingBox::active && !g_Config.BBoxUseFragmentShaderImplementation())
  {
    OGL::BoundingBox::StencilWasUpdated();
    glDisable(GL_STENCIL_TEST);
  }

  g_Config.iSaveTargetId++;
  ClearEFBCache();
}
Exemplo n.º 4
0
void FramebufferManager::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points)
{
  g_renderer->ResetAPIState();

  if (type == POKE_Z)
  {
    glDepthMask(GL_TRUE);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_ALWAYS);
  }

  glBindVertexArray(m_EfbPokes_VAO);
  glBindBuffer(GL_ARRAY_BUFFER, m_EfbPokes_VBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(EfbPokeData) * num_points, points, GL_STREAM_DRAW);
  m_EfbPokes.Bind();
  glViewport(0, 0, m_targetWidth, m_targetHeight);
  glDrawArrays(GL_POINTS, 0, (GLsizei)num_points);

  g_renderer->RestoreAPIState();

  // TODO: Could just update the EFB cache with the new value
  ClearEFBCache();
}
Exemplo n.º 5
0
void VertexManager::vFlush(bool useDstAlpha)
{
  GLVertexFormat* nativeVertexFmt = (GLVertexFormat*)VertexLoaderManager::GetCurrentVertexFormat();
  u32 stride = nativeVertexFmt->GetVertexStride();

  if (m_last_vao != nativeVertexFmt->VAO)
  {
    glBindVertexArray(nativeVertexFmt->VAO);
    m_last_vao = nativeVertexFmt->VAO;
  }

  PrepareDrawBuffers(stride);

  // Makes sure we can actually do Dual source blending
  bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;

  // If host supports GL_ARB_blend_func_extended, we can do dst alpha in
  // the same pass as regular rendering.
  if (useDstAlpha && dualSourcePossible)
  {
    ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, current_primitive_type);
  }
  else
  {
    ProgramShaderCache::SetShader(DSTALPHA_NONE, current_primitive_type);
  }

  // upload global constants
  ProgramShaderCache::UploadConstants();

  // setup the pointers
  nativeVertexFmt->SetupVertexPointers();

  Draw(stride);

  // run through vertex groups again to set alpha
  if (useDstAlpha && !dualSourcePossible)
  {
    ProgramShaderCache::SetShader(DSTALPHA_ALPHA_PASS, current_primitive_type);

    // only update alpha
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);

    glDisable(GL_BLEND);

    Draw(stride);

    // restore color mask
    g_renderer->SetColorMask();

    if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
      glEnable(GL_BLEND);
  }

#if defined(_DEBUG) || defined(DEBUGFAST)
  if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
  {
    // save the shaders
    ProgramShaderCache::PCacheEntry prog = ProgramShaderCache::GetShaderProgram();
    std::string filename = StringFromFormat(
        "%sps%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId);
    std::ofstream fps;
    OpenFStream(fps, filename, std::ios_base::out);
    fps << prog.shader.strpprog.c_str();

    filename = StringFromFormat("%svs%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
                                g_ActiveConfig.iSaveTargetId);
    std::ofstream fvs;
    OpenFStream(fvs, filename, std::ios_base::out);
    fvs << prog.shader.strvprog.c_str();
  }

  if (g_ActiveConfig.iLog & CONF_SAVETARGETS)
  {
    std::string filename =
        StringFromFormat("%starg%.3d.png", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
                         g_ActiveConfig.iSaveTargetId);
    TargetRectangle tr;
    tr.left = 0;
    tr.right = Renderer::GetTargetWidth();
    tr.top = 0;
    tr.bottom = Renderer::GetTargetHeight();
    g_renderer->SaveScreenshot(filename, tr);
  }
#endif
  g_Config.iSaveTargetId++;

  ClearEFBCache();
}
Exemplo n.º 6
0
void VertexManager::vFlush()
{
	GLVertexFormat *nativeVertexFmt = (GLVertexFormat*)g_nativeVertexFmt;
	u32 stride  = nativeVertexFmt->GetVertexStride();

	if(m_last_vao != nativeVertexFmt->VAO) {
		glBindVertexArray(nativeVertexFmt->VAO);
		m_last_vao = nativeVertexFmt->VAO;
	}

	PrepareDrawBuffers(stride);
	GL_REPORT_ERRORD();

	bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate
		&& bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;

	// Makes sure we can actually do Dual source blending
	bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;

	// finally bind
	if (dualSourcePossible)
	{
		if (useDstAlpha)
		{
			// If host supports GL_ARB_blend_func_extended, we can do dst alpha in
			// the same pass as regular rendering.
			ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, g_nativeVertexFmt->m_components);
		}
		else
		{
			ProgramShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
		}
	}
	else
	{
		ProgramShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
	}

	// upload global constants
	ProgramShaderCache::UploadConstants();

	// setup the pointers
	if (g_nativeVertexFmt)
		g_nativeVertexFmt->SetupVertexPointers();
	GL_REPORT_ERRORD();

	g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
	Draw(stride);
	g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
	//ERROR_LOG(VIDEO, "PerfQuery result: %d", g_perf_query->GetQueryResult(bpmem.zcontrol.early_ztest ? PQ_ZCOMP_OUTPUT_ZCOMPLOC : PQ_ZCOMP_OUTPUT));

	// run through vertex groups again to set alpha
	if (useDstAlpha && !dualSourcePossible)
	{
		ProgramShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);

		// only update alpha
		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);

		glDisable(GL_BLEND);

		Draw(stride);

		// restore color mask
		g_renderer->SetColorMask();

		if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
			glEnable(GL_BLEND);
	}
	GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);

#if defined(_DEBUG) || defined(DEBUGFAST)
	if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
	{
		// save the shaders
		ProgramShaderCache::PCacheEntry prog = ProgramShaderCache::GetShaderProgram();
		char strfile[255];
		sprintf(strfile, "%sps%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId);
		std::ofstream fps;
		OpenFStream(fps, strfile, std::ios_base::out);
		fps << prog.shader.strpprog.c_str();
		sprintf(strfile, "%svs%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId);
		std::ofstream fvs;
		OpenFStream(fvs, strfile, std::ios_base::out);
		fvs << prog.shader.strvprog.c_str();
	}

	if (g_ActiveConfig.iLog & CONF_SAVETARGETS)
	{
		char str[128];
		sprintf(str, "%starg%.3d.png", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId);
		TargetRectangle tr;
		tr.left = 0;
		tr.right = Renderer::GetTargetWidth();
		tr.top = 0;
		tr.bottom = Renderer::GetTargetHeight();
		g_renderer->SaveScreenshot(str, tr);
	}
#endif
	g_Config.iSaveTargetId++;

	ClearEFBCache();

	GL_REPORT_ERRORD();
}
Exemplo n.º 7
0
void VertexManager::vFlush(bool useDstAlpha)
{
	GLVertexFormat* nativeVertexFmt = (GLVertexFormat*)VertexLoaderManager::GetCurrentVertexFormat();
	u32 stride = nativeVertexFmt->GetVertexStride();
	BBox::Update();
	// Makes sure we can actually do Dual source blending
	bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;

	// If host supports GL_ARB_blend_func_extended, we can do dst alpha in
	// the same pass as regular rendering.
	if (useDstAlpha && dualSourcePossible)
	{
		ProgramShaderCache::SetShader(PSRM_DUAL_SOURCE_BLEND, VertexLoaderManager::g_current_components, current_primitive_type);
	}
	else
	{
		ProgramShaderCache::SetShader(PSRM_DEFAULT, VertexLoaderManager::g_current_components, current_primitive_type);
	}

	// upload global constants
	ProgramShaderCache::UploadConstants();

	// setup the pointers
	nativeVertexFmt->SetupVertexPointers();
	if (m_last_vao != nativeVertexFmt->VAO)
	{
		glBindVertexArray(nativeVertexFmt->VAO);
		m_last_vao = nativeVertexFmt->VAO;
	}
	PrepareDrawBuffers(stride);
	g_renderer->ApplyState(false);
	Draw(stride);
	// If the GPU does not support dual-source blending, we can approximate the effect by drawing
	// the object a second time, with the write mask set to alpha only using a shader that outputs
	// the destination/constant alpha value (which would normally be SRC_COLOR.a).
	//
	// This is also used when logic ops and destination alpha is enabled, since we can't enable
	// blending and logic ops concurrently.
	const bool logic_op_enabled = bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != BlendMode::LogicOp::COPY && !bpmem.blendmode.blendenable;
	// run through vertex groups again to set alpha
	if (useDstAlpha && (!dualSourcePossible || logic_op_enabled))
	{
		ProgramShaderCache::SetShader(PSRM_ALPHA_PASS, VertexLoaderManager::g_current_components, current_primitive_type);

		// only update alpha
		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);

		glDisable(GL_BLEND);
		if (logic_op_enabled)
			glDisable(GL_COLOR_LOGIC_OP);

		Draw(stride);

		// restore color mask
		g_renderer->SetColorMask();

		if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
			glEnable(GL_BLEND);
		if (logic_op_enabled)
			glEnable(GL_COLOR_LOGIC_OP);
	}
	g_Config.iSaveTargetId++;

	ClearEFBCache();
}