2009-06-22 07:44:20 +00:00
|
|
|
// Copyright (C) 2003-2009 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPFunctions.h"
|
2009-06-22 07:44:20 +00:00
|
|
|
#include "Globals.h"
|
|
|
|
#include "Profiler.h"
|
|
|
|
#include "Config.h"
|
|
|
|
#include "VertexManager.h"
|
|
|
|
#include "Render.h"
|
|
|
|
#include "TextureMngr.h"
|
|
|
|
#include "TextureConverter.h"
|
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "XFB.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
2009-06-22 09:31:30 +00:00
|
|
|
namespace BPFunctions
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
// ----------------------------------------------
|
|
|
|
// State translation lookup tables
|
|
|
|
// Reference: Yet Another Gamecube Documentation
|
|
|
|
// ----------------------------------------------
|
|
|
|
|
|
|
|
static const GLenum glCmpFuncs[8] = {
|
|
|
|
GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GLenum glLogicOpCodes[16] = {
|
|
|
|
GL_CLEAR, GL_AND, GL_AND_REVERSE, GL_COPY, GL_AND_INVERTED, GL_NOOP, GL_XOR,
|
|
|
|
GL_OR, GL_NOR, GL_EQUIV, GL_INVERT, GL_OR_REVERSE, GL_COPY_INVERTED, GL_OR_INVERTED, GL_NAND, GL_SET
|
|
|
|
};
|
|
|
|
|
|
|
|
void FlushPipeline()
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetGenerationMode(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
// none, ccw, cw, ccw
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.genMode.cullmode > 0)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
glEnable(GL_CULL_FACE);
|
2009-06-22 09:31:30 +00:00
|
|
|
glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW);
|
2009-06-22 07:44:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetScissor(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
if (!Renderer::SetScissorRect())
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bp.address == BPMEM_SCISSORBR)
|
2009-06-22 07:44:20 +00:00
|
|
|
ERROR_LOG(VIDEO, "bad scissor!");
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetLineWidth(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
float fratio = xfregs.rawViewport[0] != 0 ? ((float)Renderer::GetTargetWidth() / EFB_WIDTH) : 1.0f;
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.lineptwidth.linesize > 0)
|
|
|
|
glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths
|
|
|
|
if (bpmem.lineptwidth.pointsize > 0)
|
|
|
|
glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f);
|
2009-06-22 07:44:20 +00:00
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetDepthMode(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.zmode.testenable)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2009-06-22 09:31:30 +00:00
|
|
|
glDepthMask(bpmem.zmode.updateenable ? GL_TRUE : GL_FALSE);
|
|
|
|
glDepthFunc(glCmpFuncs[bpmem.zmode.func]);
|
2009-06-22 07:44:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if the test is disabled write is disabled too
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetBlendMode(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
Renderer::SetBlendMode(false);
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetDitherMode(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.blendmode.dither)
|
2009-06-22 07:44:20 +00:00
|
|
|
glEnable(GL_DITHER);
|
|
|
|
else
|
|
|
|
glDisable(GL_DITHER);
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetLogicOpMode(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.blendmode.logicopenable)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
glEnable(GL_COLOR_LOGIC_OP);
|
2009-06-22 09:31:30 +00:00
|
|
|
glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]);
|
2009-06-22 07:44:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
glDisable(GL_COLOR_LOGIC_OP);
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetColorMask(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
Renderer::SetColorMask();
|
|
|
|
}
|
|
|
|
float GetRendererTargetScaleX()
|
|
|
|
{
|
|
|
|
return Renderer::GetTargetScaleX();
|
|
|
|
}
|
|
|
|
float GetRendererTargetScaleY()
|
|
|
|
{
|
|
|
|
return Renderer::GetTargetScaleY();
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void CopyEFB(const Bypass &bp, const TRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 ©fmt, const bool &scaleByHalf)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2009-06-22 09:31:30 +00:00
|
|
|
// bpmem.zcontrol.pixel_format to PIXELFMT_Z24 is when the game wants to copy from ZBuffer (Zbuffer uses 24-bit Format)
|
2009-06-22 07:44:20 +00:00
|
|
|
if (!g_Config.bEFBCopyDisable)
|
|
|
|
if (g_Config.bCopyEFBToRAM) // To RAM
|
|
|
|
TextureConverter::EncodeToRam(address, fromZBuffer, isIntensityFmt, copyfmt, scaleByHalf, rc);
|
|
|
|
else // To OGL Texture
|
|
|
|
TextureMngr::CopyRenderTargetToTexture(address, fromZBuffer, isIntensityFmt, copyfmt, scaleByHalf, rc);
|
|
|
|
}
|
|
|
|
|
2009-06-29 07:30:48 +00:00
|
|
|
void RenderToXFB(const Bypass &bp, const TRectangle &multirc, const float &yScale, const float &xfbLines, u32 xfbAddr, const u32 &dstWidth, const u32 &dstHeight)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2009-06-29 07:30:48 +00:00
|
|
|
Renderer::RenderToXFB(xfbAddr, dstWidth, dstHeight, multirc);
|
2009-06-22 07:44:20 +00:00
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void ClearScreen(const Bypass &bp, const TRectangle &multirc)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
// Update the view port for clearing the picture
|
|
|
|
glViewport(0, 0, Renderer::GetTargetWidth(), Renderer::GetTargetHeight());
|
|
|
|
|
|
|
|
// Always set the scissor in case it was set by the game and has not been reset
|
|
|
|
glScissor(multirc.left, (Renderer::GetTargetHeight() - multirc.bottom),
|
|
|
|
(multirc.right - multirc.left), (multirc.bottom - multirc.top));
|
|
|
|
// ---------------------------
|
|
|
|
|
|
|
|
VertexShaderManager::SetViewportChanged();
|
|
|
|
|
|
|
|
// Since clear operations use the source rectangle, we have to do
|
|
|
|
// regular renders (glClear clears the entire buffer)
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate || bpmem.zmode.updateenable)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
GLbitfield bits = 0;
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2009-06-22 09:31:30 +00:00
|
|
|
u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB;
|
2009-06-29 00:52:54 +00:00
|
|
|
|
|
|
|
// Alpha may or may not be present depending on the EFB pixel format.
|
|
|
|
GLclampf clearAlpha = (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24) ?
|
|
|
|
((clearColor>>24) & 0xff)*(1/255.0f) : 1.0f;
|
|
|
|
|
2009-06-22 07:44:20 +00:00
|
|
|
glClearColor(((clearColor>>16) & 0xff)*(1/255.0f),
|
|
|
|
((clearColor>>8 ) & 0xff)*(1/255.0f),
|
|
|
|
((clearColor>>0 ) & 0xff)*(1/255.0f),
|
2009-06-29 00:52:54 +00:00
|
|
|
clearAlpha);
|
2009-06-22 07:44:20 +00:00
|
|
|
bits |= GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
if (bpmem.zmode.updateenable)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
2009-06-22 09:31:30 +00:00
|
|
|
glClearDepth((float)(bpmem.clearZValue & 0xFFFFFF) / float(0xFFFFFF));
|
2009-06-22 07:44:20 +00:00
|
|
|
bits |= GL_DEPTH_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
|
|
|
glClear(bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-22 09:31:30 +00:00
|
|
|
void RestoreRenderState(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
Renderer::RestoreGLState();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetConfig(const int &type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CONFIG_ISWII:
|
|
|
|
return g_VideoInitialize.bWii;
|
|
|
|
case CONFIG_DISABLEFOG:
|
|
|
|
return g_Config.bDisableFog;
|
|
|
|
case CONFIG_SHOWEFBREGIONS:
|
|
|
|
return g_Config.bShowEFBCopyRegions;
|
|
|
|
default:
|
|
|
|
PanicAlert("GetConfig Error: Unknown Config Type!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u8 *GetPointer(const u32 &address)
|
|
|
|
{
|
|
|
|
return g_VideoInitialize.pGetMemoryPointer(address);
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetSamplerState(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
2009-06-22 09:31:30 +00:00
|
|
|
void SetInterlacingMode(const Bypass &bp)
|
2009-06-22 07:44:20 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
};
|