mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
Merge branch 'master' into GLSL-master
Conflicts: CMakeLists.txt Source/Core/DolphinWX/Dolphin.vcxproj Source/Core/DolphinWX/Src/GLInterface/WX.cpp Source/Core/DolphinWX/Src/GLInterface/WX.h Source/Core/VideoCommon/Src/TextureCacheBase.cpp Source/Core/VideoCommon/Src/TextureCacheBase.h Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp Source/Plugins/Plugin_VideoDX11/Src/TextureCache.h Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h Source/Plugins/Plugin_VideoOGL/Src/Render.cpp Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp Source/Plugins/Plugin_VideoOGL/Src/TextureCache.h Source/Plugins/Plugin_VideoSoftware/Src/SWmain.cpp damn mipmap_fixes ...
This commit is contained in:
@ -128,58 +128,6 @@ static const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB
|
||||
static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT];
|
||||
static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR
|
||||
|
||||
static const GLenum glSrcFactors[8] =
|
||||
{
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_DST_COLOR,
|
||||
GL_ONE_MINUS_DST_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
GL_DST_ALPHA,
|
||||
GL_ONE_MINUS_DST_ALPHA
|
||||
};
|
||||
|
||||
static const GLenum glDestFactors[8] = {
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_SRC_COLOR,
|
||||
GL_ONE_MINUS_SRC_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
GL_DST_ALPHA,
|
||||
GL_ONE_MINUS_DST_ALPHA
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
int GetNumMSAASamples(int MSAAMode)
|
||||
{
|
||||
@ -334,21 +282,8 @@ Renderer::Renderer()
|
||||
s_backbuffer_height = (int)GLInterface->GetBackBufferHeight();
|
||||
|
||||
// Handle VSync on/off
|
||||
#ifdef __APPLE__
|
||||
int swapInterval = g_ActiveConfig.bVSync ? 1 : 0;
|
||||
NSOpenGLContext *ctx = GLWin.cocoaCtx;
|
||||
[ctx setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
|
||||
#elif defined _WIN32
|
||||
if (WGLEW_EXT_swap_control)
|
||||
wglSwapIntervalEXT(g_ActiveConfig.bVSync ? 1 : 0);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
if (glXSwapIntervalSGI)
|
||||
glXSwapIntervalSGI(g_ActiveConfig.bVSync ? 1 : 0);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
||||
#endif
|
||||
GLInterface->SwapInterval(swapInterval);
|
||||
|
||||
// check the max texture width and height
|
||||
GLint max_texture_size;
|
||||
@ -949,6 +884,32 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
&& bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
bool useDualSource = useDstAlpha && g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
||||
|
||||
// Our render target always uses an alpha channel, so we need to override the blend functions to assume a destination alpha of 1 if the render target isn't supposed to have an alpha channel
|
||||
// Example: D3DBLEND_DESTALPHA needs to be D3DBLEND_ONE since the result without an alpha channel is assumed to always be 1.
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
const GLenum glSrcFactors[8] =
|
||||
{
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_DST_COLOR,
|
||||
GL_ONE_MINUS_DST_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
(target_has_alpha) ? GL_DST_ALPHA : (GLenum)GL_ONE,
|
||||
(target_has_alpha) ? GL_ONE_MINUS_DST_ALPHA : (GLenum)GL_ZERO
|
||||
};
|
||||
const GLenum glDestFactors[8] =
|
||||
{
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_SRC_COLOR,
|
||||
GL_ONE_MINUS_SRC_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
(target_has_alpha) ? GL_DST_ALPHA : (GLenum)GL_ONE,
|
||||
(target_has_alpha) ? GL_ONE_MINUS_DST_ALPHA : (GLenum)GL_ZERO
|
||||
};
|
||||
|
||||
// blend mode bit mask
|
||||
// 0 - blend enable
|
||||
// 1 - dst alpha enabled
|
||||
@ -980,41 +941,33 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
GLenum equation = newval & 4 ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD;
|
||||
GLenum equationAlpha = useDualSource ? GL_FUNC_ADD : equation;
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsDualSourceBlend)
|
||||
glBlendEquationSeparate(equation, equationAlpha);
|
||||
else
|
||||
glBlendEquation(newval & 4 ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD);
|
||||
glBlendEquationSeparate(equation, equationAlpha);
|
||||
}
|
||||
|
||||
if (changes & 0x1FA)
|
||||
{
|
||||
if (g_ActiveConfig.backend_info.bSupportsDualSourceBlend)
|
||||
GLenum srcFactor = glSrcFactors[(newval >> 3) & 7];
|
||||
GLenum dstFactor = glDestFactors[(newval >> 6) & 7];
|
||||
GLenum srcFactorAlpha = srcFactor;
|
||||
GLenum dstFactorAlpha = dstFactor;
|
||||
if (useDualSource)
|
||||
{
|
||||
GLenum srcFactor = glSrcFactors[(newval >> 3) & 7];
|
||||
GLenum srcFactorAlpha = srcFactor;
|
||||
GLenum dstFactor = glDestFactors[(newval >> 6) & 7];
|
||||
GLenum dstFactorAlpha = dstFactor;
|
||||
if (useDualSource)
|
||||
{
|
||||
srcFactorAlpha = GL_ONE;
|
||||
dstFactorAlpha = GL_ZERO;
|
||||
srcFactorAlpha = GL_ONE;
|
||||
dstFactorAlpha = GL_ZERO;
|
||||
|
||||
if (srcFactor == GL_SRC_ALPHA)
|
||||
srcFactor = GL_SRC1_ALPHA;
|
||||
else if (srcFactor == GL_ONE_MINUS_SRC_ALPHA)
|
||||
srcFactor = GL_ONE_MINUS_SRC1_ALPHA;
|
||||
if (srcFactor == GL_SRC_ALPHA)
|
||||
srcFactor = GL_SRC1_ALPHA;
|
||||
else if (srcFactor == GL_ONE_MINUS_SRC_ALPHA)
|
||||
srcFactor = GL_ONE_MINUS_SRC1_ALPHA;
|
||||
|
||||
if (dstFactor == GL_SRC_ALPHA)
|
||||
dstFactor = GL_SRC1_ALPHA;
|
||||
else if (dstFactor == GL_ONE_MINUS_SRC_ALPHA)
|
||||
dstFactor = GL_ONE_MINUS_SRC1_ALPHA;
|
||||
}
|
||||
|
||||
// blend RGB change
|
||||
glBlendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
|
||||
if (dstFactor == GL_SRC_ALPHA)
|
||||
dstFactor = GL_SRC1_ALPHA;
|
||||
else if (dstFactor == GL_ONE_MINUS_SRC_ALPHA)
|
||||
dstFactor = GL_ONE_MINUS_SRC1_ALPHA;
|
||||
}
|
||||
else
|
||||
glBlendFunc(glSrcFactors[(newval >> 3) & 7], glDestFactors[(newval >> 6) & 7]);
|
||||
|
||||
// blend RGB change
|
||||
glBlendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
|
||||
}
|
||||
|
||||
s_blendMode = newval;
|
||||
@ -1289,10 +1242,10 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight)
|
||||
{
|
||||
xfbchanged = true;
|
||||
unsigned int w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth;
|
||||
unsigned int h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
|
||||
FramebufferManagerBase::SetLastXfbWidth(w);
|
||||
FramebufferManagerBase::SetLastXfbHeight(h);
|
||||
unsigned int const last_w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth;
|
||||
unsigned int const last_h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
|
||||
FramebufferManagerBase::SetLastXfbWidth(last_w);
|
||||
FramebufferManagerBase::SetLastXfbHeight(last_h);
|
||||
}
|
||||
|
||||
bool WindowResized = false;
|
||||
@ -1436,6 +1389,18 @@ void Renderer::SetGenerationMode()
|
||||
|
||||
void Renderer::SetDepthMode()
|
||||
{
|
||||
const GLenum glCmpFuncs[8] =
|
||||
{
|
||||
GL_NEVER,
|
||||
GL_LESS,
|
||||
GL_EQUAL,
|
||||
GL_LEQUAL,
|
||||
GL_GREATER,
|
||||
GL_NOTEQUAL,
|
||||
GL_GEQUAL,
|
||||
GL_ALWAYS
|
||||
};
|
||||
|
||||
if (bpmem.zmode.testenable)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
@ -1452,7 +1417,27 @@ void Renderer::SetDepthMode()
|
||||
|
||||
void Renderer::SetLogicOpMode()
|
||||
{
|
||||
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
|
||||
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
|
||||
};
|
||||
|
||||
if (bpmem.blendmode.logicopenable)
|
||||
{
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]);
|
||||
|
@ -75,24 +75,6 @@ static std::map<u64,VBOCache> s_VBO;
|
||||
|
||||
static u32 s_TempFramebuffer = 0;
|
||||
|
||||
static const GLint c_MinLinearFilter[8] = {
|
||||
GL_NEAREST,
|
||||
GL_NEAREST_MIPMAP_NEAREST,
|
||||
GL_NEAREST_MIPMAP_LINEAR,
|
||||
GL_NEAREST,
|
||||
GL_LINEAR,
|
||||
GL_LINEAR_MIPMAP_NEAREST,
|
||||
GL_LINEAR_MIPMAP_LINEAR,
|
||||
GL_LINEAR,
|
||||
};
|
||||
|
||||
static const GLint c_WrapSettings[4] = {
|
||||
GL_CLAMP_TO_EDGE,
|
||||
GL_REPEAT,
|
||||
GL_MIRRORED_REPEAT,
|
||||
GL_REPEAT,
|
||||
};
|
||||
|
||||
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level)
|
||||
{
|
||||
int width = std::max(virtual_width >> level, 1);
|
||||
@ -241,7 +223,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
||||
}
|
||||
|
||||
void TextureCache::TCacheEntry::Load(unsigned int stage, unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int level, bool autogen_mips)
|
||||
unsigned int expanded_width, unsigned int level)
|
||||
{
|
||||
if(s_ActiveTexture != stage)
|
||||
glActiveTexture(GL_TEXTURE0 + stage);
|
||||
@ -259,9 +241,6 @@ void TextureCache::TCacheEntry::Load(unsigned int stage, unsigned int width, uns
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
||||
|
||||
if (autogen_mips)
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
if (expanded_width != width)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
@ -412,15 +391,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
srcRect);
|
||||
|
||||
u8* dst = Memory::GetPointer(addr);
|
||||
u64 hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
|
||||
u64 const new_hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
|
||||
|
||||
// Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
|
||||
if (!g_ActiveConfig.bEFBCopyCacheEnable)
|
||||
TextureCache::MakeRangeDynamic(addr,encoded_size);
|
||||
else if (!TextureCache::Find(addr, hash))
|
||||
else if (!TextureCache::Find(addr, new_hash))
|
||||
TextureCache::MakeRangeDynamic(addr,encoded_size);
|
||||
|
||||
this->hash = hash;
|
||||
hash = new_hash;
|
||||
}
|
||||
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
@ -440,37 +419,43 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
|
||||
void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1)
|
||||
{
|
||||
currmode = newmode;
|
||||
currmode1 = newmode1;
|
||||
|
||||
// TODO: not used anywhere
|
||||
TexMode0 mode = newmode;
|
||||
//mode1 = newmode1;
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
(newmode.mag_filter || g_Config.bForceFiltering) ? GL_LINEAR : GL_NEAREST);
|
||||
|
||||
if (m_tex_levels != 1)
|
||||
const GLint c_MinLinearFilter[8] =
|
||||
{
|
||||
// TODO: not used anywhere
|
||||
if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4)
|
||||
mode.min_filter += 4; // take equivalent forced linear
|
||||
GL_NEAREST,
|
||||
GL_NEAREST_MIPMAP_NEAREST,
|
||||
GL_NEAREST_MIPMAP_LINEAR,
|
||||
GL_NEAREST,
|
||||
GL_LINEAR,
|
||||
GL_LINEAR_MIPMAP_NEAREST,
|
||||
GL_LINEAR_MIPMAP_LINEAR,
|
||||
GL_LINEAR,
|
||||
};
|
||||
const GLint c_WrapSettings[4] =
|
||||
{
|
||||
GL_CLAMP_TO_EDGE,
|
||||
GL_REPEAT,
|
||||
GL_MIRRORED_REPEAT,
|
||||
GL_REPEAT,
|
||||
};
|
||||
|
||||
int filt = newmode.min_filter;
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & 7]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, newmode1.min_lod >> 4);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, newmode1.max_lod >> 4);
|
||||
}
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
(g_ActiveConfig.bForceFiltering || newmode.min_filter >= 4) ? GL_LINEAR : GL_NEAREST);
|
||||
int filt = newmode.min_filter;
|
||||
if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4)
|
||||
filt += 4; // take equivalent forced linear
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & 7]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (newmode.mag_filter || g_Config.bForceFiltering) ? GL_LINEAR : GL_NEAREST);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, newmode1.min_lod / 16.f);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, newmode1.max_lod / 16.f);
|
||||
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, (s32)newmode.lod_bias / 32.0f);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, c_WrapSettings[newmode.wrap_s]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, c_WrapSettings[newmode.wrap_t]);
|
||||
|
||||
// TODO: Reset anisotrop when changed to 1
|
||||
if (g_Config.iMaxAnisotropy >= 1)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
(float)(1 << g_ActiveConfig.iMaxAnisotropy));
|
||||
(float)(1 << g_ActiveConfig.iMaxAnisotropy));
|
||||
}
|
||||
|
||||
TextureCache::TextureCache()
|
||||
|
@ -56,7 +56,7 @@ private:
|
||||
~TCacheEntry();
|
||||
|
||||
void Load(unsigned int stage, unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int level, bool autogen_mips = false);
|
||||
unsigned int expanded_width, unsigned int level);
|
||||
|
||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
|
@ -223,8 +223,8 @@ void VertexManager::vFlush()
|
||||
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||
tex.texTlut[i&3].tlut_format,
|
||||
(tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8),
|
||||
tex.texMode1[i&3].max_lod >> 4,
|
||||
(tex.texMode0[i&3].min_filter & 3),
|
||||
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
||||
tex.texImage1[i&3].image_type);
|
||||
|
||||
if (tentry)
|
||||
|
Reference in New Issue
Block a user