summaryrefslogtreecommitdiff
path: root/Source/Plugins/Plugin_VideoOGL
diff options
context:
space:
mode:
authorhrydgard <hrydgard@gmail.com>2009-09-03 19:24:16 +0000
committerhrydgard <hrydgard@gmail.com>2009-09-03 19:24:16 +0000
commit562a4e25acd3bd4eb7183fbb5cd04891c4535423 (patch)
tree298988fd772ec9ebf89710cb0f954997ee4fa996 /Source/Plugins/Plugin_VideoOGL
parent2091fb3ceb1f3adbb4a39513dab894c99a98be34 (diff)
Some housecleaning around the D3D plugin, start of preparations to share even more code with the GL plugin.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4183 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Plugins/Plugin_VideoOGL')
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj10
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp2
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/Render.cpp77
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/Render.h9
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/SConscript1
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.cpp738
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.h36
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp10
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp4
9 files changed, 46 insertions, 841 deletions
diff --git a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj
index 163790c0c3..d01801ae9d 100644
--- a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj
+++ b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="9,00"
+ Version="9.00"
Name="Plugin_VideoOGL"
ProjectGUID="{CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160}"
RootNamespace="Plugin_VideoOGL"
@@ -933,14 +933,6 @@
>
</File>
<File
- RelativePath=".\Src\TextureConversionShader.cpp"
- >
- </File>
- <File
- RelativePath=".\Src\TextureConversionShader.h"
- >
- </File>
- <File
RelativePath=".\Src\TextureConverter.cpp"
>
</File>
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp
index 2a4f7d1d19..274926c08b 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp
@@ -148,7 +148,7 @@ void ClearScreen(const BPCmd &bp, const EFBRectangle &rc)
void RestoreRenderState(const BPCmd &bp)
{
- Renderer::RestoreGLState();
+ Renderer::RestoreAPIState();
}
bool GetConfig(const int &type)
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
index 47e2770906..23b2847e63 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
@@ -362,40 +362,6 @@ bool Renderer::Init()
cgGLSetDebugMode(GL_FALSE);
#endif
- if (!InitializeGL())
- return false;
-
- return glGetError() == GL_NO_ERROR && bSuccess;
-}
-
-void Renderer::Shutdown(void)
-{
- delete s_pfont;
- s_pfont = 0;
-
- if (g_cgcontext) {
- cgDestroyContext(g_cgcontext);
- g_cgcontext = 0;
- }
-
- glDeleteFramebuffersEXT(1, &s_tempScreenshotFramebuffer);
- s_tempScreenshotFramebuffer = 0;
-
- s_framebufferManager.Shutdown();
-
-#ifdef _WIN32
- if(s_bAVIDumping) {
- AVIDump::Stop();
- }
-#else
- if(f_pFrameDump != NULL) {
- fclose(f_pFrameDump);
- }
-#endif
-}
-
-bool Renderer::InitializeGL()
-{
glStencilFunc(GL_ALWAYS, 0, 0);
glBlendFunc(GL_ONE, GL_ONE);
@@ -432,9 +398,34 @@ bool Renderer::InitializeGL()
glClientActiveTexture(GL_TEXTURE0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- return GL_REPORT_ERROR() == GL_NO_ERROR;
+ return glGetError() == GL_NO_ERROR && bSuccess;
}
+void Renderer::Shutdown(void)
+{
+ delete s_pfont;
+ s_pfont = 0;
+
+ if (g_cgcontext) {
+ cgDestroyContext(g_cgcontext);
+ g_cgcontext = 0;
+ }
+
+ glDeleteFramebuffersEXT(1, &s_tempScreenshotFramebuffer);
+ s_tempScreenshotFramebuffer = 0;
+
+ s_framebufferManager.Shutdown();
+
+#ifdef _WIN32
+ if(s_bAVIDumping) {
+ AVIDump::Stop();
+ }
+#else
+ if(f_pFrameDump != NULL) {
+ fclose(f_pFrameDump);
+ }
+#endif
+}
// Return the rendering window width and height
int Renderer::GetTargetWidth()
@@ -467,7 +458,7 @@ void Renderer::SetFramebuffer(GLuint fb)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb != 0 ? fb : s_framebufferManager.GetEFBFramebuffer());
}
-void Renderer::ResetGLState()
+void Renderer::ResetAPIState()
{
// Gets us to a reasonably sane state where it's possible to do things like
// image copies with textured quads, etc.
@@ -484,7 +475,7 @@ void Renderer::ResetGLState()
void UpdateViewport();
-void Renderer::RestoreGLState()
+void Renderer::RestoreAPIState()
{
// Gets us back into a more game-like state.
@@ -832,7 +823,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
OpenGL_Update(); // just updates the render window position and the backbuffer size
DVSTARTPROFILE();
- ResetGLState();
+ ResetAPIState();
TargetRectangle back_rc;
ComputeBackbufferRectangle(&back_rc);
@@ -1038,7 +1029,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
// Why save this as s_bNativeResolution if we updated it every frame?
s_bNativeResolution = g_Config.bNativeResolution;
- RestoreGLState();
+ RestoreAPIState();
GL_REPORT_ERRORD();
g_Config.iSaveTargetId = 0;
@@ -1436,16 +1427,16 @@ void UpdateViewport()
(rawViewport[5] - rawViewport[2]) / 16777215.0f, rawViewport[5] / 16777215.0f);*/
// --------
- int scissorXOff = bpmem.scissorOffset.x * 2 - 342;
- int scissorYOff = bpmem.scissorOffset.y * 2 - 342;
+ int scissorXOff = bpmem.scissorOffset.x * 2; // 342
+ int scissorYOff = bpmem.scissorOffset.y * 2; // 342
// -------------------------------------
float MValueX = Renderer::GetTargetScaleX();
float MValueY = Renderer::GetTargetScaleY();
// Stretch picture with increased internal resolution
- int GLx = (int)ceil((xfregs.rawViewport[3] - xfregs.rawViewport[0] - 342 - scissorXOff) * MValueX);
- int GLy = (int)ceil(Renderer::GetTargetHeight() - ((int)(xfregs.rawViewport[4] - xfregs.rawViewport[1] - 342 - scissorYOff)) * MValueY);
+ int GLx = (int)ceil((xfregs.rawViewport[3] - xfregs.rawViewport[0] - scissorXOff) * MValueX);
+ int GLy = (int)ceil(Renderer::GetTargetHeight() - ((int)(xfregs.rawViewport[4] - xfregs.rawViewport[1] - scissorYOff)) * MValueY);
int GLWidth = (int)ceil(abs((int)(2 * xfregs.rawViewport[0])) * MValueX);
int GLHeight = (int)ceil(abs((int)(2 * xfregs.rawViewport[1])) * MValueY);
double GLNear = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777215.0f;
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.h b/Source/Plugins/Plugin_VideoOGL/Src/Render.h
index 99e0cde1d4..058d6a9e67 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/Render.h
+++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.h
@@ -47,15 +47,12 @@ public:
static bool Init();
static void Shutdown();
- // initialize opengl standard values (like viewport)
- static bool InitializeGL();
-
- static void ResetGLState();
- static void RestoreGLState();
+ // What's the real difference between these? Too similar names.
+ static void ResetAPIState();
+ static void RestoreAPIState();
static void SwapBuffers();
- static bool IsBlack();
static void SetColorMask();
static void SetBlendMode(bool forceUpdate);
static bool SetScissorRect();
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SConscript b/Source/Plugins/Plugin_VideoOGL/Src/SConscript
index 3885ac2831..492006df2c 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/SConscript
+++ b/Source/Plugins/Plugin_VideoOGL/Src/SConscript
@@ -23,7 +23,6 @@ files = [
'VertexManager.cpp',
'VertexLoaderManager.cpp',
'XFB.cpp',
- 'TextureConversionShader.cpp',
'OnScreenDisplay.cpp',
'PostProcessing.cpp',
'FramebufferManager.cpp',
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.cpp
deleted file mode 100644
index b66feeeab3..0000000000
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.cpp
+++ /dev/null
@@ -1,738 +0,0 @@
-// Copyright (C) 2003-2000 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/
-
-
-#include "TextureConversionShader.h"
-#include "TextureDecoder.h"
-#include "PixelShaderManager.h"
-#include "PixelShaderGen.h"
-#include "BPMemory.h"
-
-#include <stdio.h>
-#include <math.h>
-#include "Common.h"
-
-#define WRITE p+=sprintf
-
-static char text[16384];
-
-namespace TextureConversionShader
-{
-
-
-u16 GetEncodedSampleCount(u32 format)
-{
- switch (format) {
- case GX_TF_I4: return 8;
- case GX_TF_I8: return 4;
- case GX_TF_IA4: return 4;
- case GX_TF_IA8: return 2;
- case GX_TF_RGB565: return 2;
- case GX_TF_RGB5A3: return 2;
- case GX_TF_RGBA8: return 1;
- case GX_CTF_R4: return 8;
- case GX_CTF_RA4: return 4;
- case GX_CTF_RA8: return 2;
- case GX_CTF_A8: return 4;
- case GX_CTF_R8: return 4;
- case GX_CTF_G8: return 4;
- case GX_CTF_B8: return 4;
- case GX_CTF_RG8: return 2;
- case GX_CTF_GB8: return 2;
- case GX_TF_Z8: return 4;
- case GX_TF_Z16: return 2;
- case GX_TF_Z24X8: return 1;
- case GX_CTF_Z4: return 8;
- case GX_CTF_Z8M: return 4;
- case GX_CTF_Z8L: return 4;
- case GX_CTF_Z16L: return 2;
- default: return 1;
- }
-}
-
-// block dimensions : widthStride, heightStride
-// texture dims : width, height, x offset, y offset
-void WriteSwizzler(char*& p, u32 format)
-{
- WRITE(p, "uniform float4 blkDims : register(c%d);\n", C_COLORMATRIX);
- WRITE(p, "uniform float4 textureDims : register(c%d);\n", C_COLORMATRIX + 1);
-
- float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
- float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
- float samples = (float)GetEncodedSampleCount(format);
-
- WRITE(p,
- "uniform samplerRECT samp0 : register(s0);\n"
- "void main(\n"
- " out float4 ocol0 : COLOR0,\n"
- " in float2 uv0 : TEXCOORD0)\n"
- "{\n"
- " float2 sampleUv;\n"
- " float2 uv1 = floor(uv0);\n");
-
- WRITE(p, " uv1.x = uv1.x * %f;\n", samples);
-
- WRITE(p, " float xl = floor(uv1.x / %f);\n", blkW);
- WRITE(p, " float xib = uv1.x - (xl * %f);\n", blkW);
- WRITE(p, " float yl = floor(uv1.y / %f);\n", blkH);
- WRITE(p, " float yb = yl * %f;\n", blkH);
- WRITE(p, " float yoff = uv1.y - yb;\n");
- WRITE(p, " float xp = uv1.x + (yoff * textureDims.x);\n");
- WRITE(p, " float xel = floor(xp / %f);\n", blkW);
- WRITE(p, " float xb = floor(xel / %f);\n", blkH);
- WRITE(p, " float xoff = xel - (xb * %f);\n", blkH);
-
- WRITE(p, " sampleUv.x = xib + (xb * %f);\n", blkW);
- WRITE(p, " sampleUv.y = yb + xoff;\n");
-
- WRITE(p, " sampleUv = sampleUv * blkDims.xy;\n"
- " sampleUv.y = textureDims.y - sampleUv.y;\n"
-
- " sampleUv.x = sampleUv.x + textureDims.z;\n"
- " sampleUv.y = sampleUv.y + textureDims.w;\n");
-}
-
-// block dimensions : widthStride, heightStride
-// texture dims : width, height, x offset, y offset
-void Write32BitSwizzler(char*& p, u32 format)
-{
- WRITE(p, "uniform float4 blkDims : register(c%d);\n", C_COLORMATRIX);
- WRITE(p, "uniform float4 textureDims : register(c%d);\n", C_COLORMATRIX + 1);
-
- float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
- float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
-
- // 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments
-
- WRITE(p,
- "uniform samplerRECT samp0 : register(s0);\n"
- "void main(\n"
- " out float4 ocol0 : COLOR0,\n"
- " in float2 uv0 : TEXCOORD0)\n"
- "{\n"
- " float2 sampleUv;\n"
- " float2 uv1 = floor(uv0);\n");
-
- WRITE(p, " float yl = floor(uv1.y / %f);\n", blkH);
- WRITE(p, " float yb = yl * %f;\n", blkH);
- WRITE(p, " float yoff = uv1.y - yb;\n");
- WRITE(p, " float xp = uv1.x + (yoff * textureDims.x);\n");
- WRITE(p, " float xel = floor(xp / 2);\n");
- WRITE(p, " float xb = floor(xel / %f);\n", blkH);
- WRITE(p, " float xoff = xel - (xb * %f);\n", blkH);
-
- WRITE(p, " float x2 = uv1.x * 2;\n");
- WRITE(p, " float xl = floor(x2 / %f);\n", blkW);
- WRITE(p, " float xib = x2 - (xl * %f);\n", blkW);
- WRITE(p, " float halfxb = floor(xb / 2);\n");
-
-
- WRITE(p, " sampleUv.x = xib + (halfxb * %f);\n", blkW);
- WRITE(p, " sampleUv.y = yb + xoff;\n");
- WRITE(p, " sampleUv = sampleUv * blkDims.xy;\n");
- WRITE(p, " sampleUv.y = textureDims.y - sampleUv.y;\n");
-
- WRITE(p, " sampleUv.x = sampleUv.x + textureDims.z;\n");
- WRITE(p, " sampleUv.y = sampleUv.y + textureDims.w;\n");
-}
-
-void WriteSampleColor(char*& p, const char* colorComp, const char* dest)
-{
- WRITE(p, " %s = texRECT(samp0, sampleUv).%s;\n", dest, colorComp);
-}
-
-void WriteColorToIntensity(char*& p, const char* src, const char* dest)
-{
- WRITE(p, " %s = (0.257f * %s.r) + (0.504f * %s.g) + (0.098f * %s.b) + 0.0625f;\n", dest, src, src, src);
-}
-
-void WriteIncrementSampleX(char*& p)
-{
- WRITE(p, " sampleUv.x = sampleUv.x + blkDims.x;\n");
-}
-
-void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest)
-{
- float result = pow(2.0f, depth) - 1.0f;
- WRITE(p, " %s = floor(%s * %ff);\n", dest, src, result);
-}
-
-void WriteI8Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_I8);
- WRITE(p, " float3 texSample;\n");
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "ocol0.b");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "ocol0.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "ocol0.r");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "ocol0.a");
-
- WRITE(p, "}\n");
-}
-
-void WriteI4Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_I4);
- WRITE(p, " float3 texSample;\n");
- WRITE(p, " float4 color0;\n");
- WRITE(p, " float4 color1;\n");
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color0.b");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color1.b");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color0.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color1.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color0.r");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color1.r");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color0.a");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteColorToIntensity(p, "texSample", "color1.a");
-
- WriteToBitDepth(p, 4, "color0", "color0");
- WriteToBitDepth(p, 4, "color1", "color1");
-
- WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
- WRITE(p, "}\n");
-}
-
-void WriteIA8Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_IA8);
- WRITE(p, " float4 texSample;\n");
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " ocol0.b = texSample.a;\n");
- WriteColorToIntensity(p, "texSample", "ocol0.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " ocol0.r = texSample.a;\n");
- WriteColorToIntensity(p, "texSample", "ocol0.a");
-
- WRITE(p, "}\n");
-}
-
-void WriteIA4Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_IA4);
- WRITE(p, " float4 texSample;\n");
- WRITE(p, " float4 color0;\n");
- WRITE(p, " float4 color1;\n");
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " color0.b = texSample.a;\n");
- WriteColorToIntensity(p, "texSample", "color1.b");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " color0.g = texSample.a;\n");
- WriteColorToIntensity(p, "texSample", "color1.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " color0.r = texSample.a;\n");
- WriteColorToIntensity(p, "texSample", "color1.r");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " color0.a = texSample.a;\n");
- WriteColorToIntensity(p, "texSample", "color1.a");
-
- WriteToBitDepth(p, 4, "color0", "color0");
- WriteToBitDepth(p, 4, "color1", "color1");
-
- WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
- WRITE(p, "}\n");
-}
-
-void WriteRGB565Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_RGB565);
-
- WRITE(p, " float3 texSample;\n");
- WRITE(p, " float gInt;\n");
- WRITE(p, " float gUpper;\n");
- WRITE(p, " float gLower;\n");
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteToBitDepth(p, 6, "texSample.g", "gInt");
- WRITE(p, " gUpper = floor(gInt / 8.0f);\n");
- WRITE(p, " gLower = gInt - gUpper * 8.0f;\n");
-
- WriteToBitDepth(p, 5, "texSample.r", "ocol0.b");
- WRITE(p, " ocol0.b = ocol0.b * 8.0f + gUpper;\n");
- WriteToBitDepth(p, 5, "texSample.b", "ocol0.g");
- WRITE(p, " ocol0.g = ocol0.g + gLower * 32.0f;\n");
-
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgb", "texSample");
- WriteToBitDepth(p, 6, "texSample.g", "gInt");
- WRITE(p, " gUpper = floor(gInt / 8.0f);\n");
- WRITE(p, " gLower = gInt - gUpper * 8.0f;\n");
-
- WriteToBitDepth(p, 5, "texSample.r", "ocol0.r");
- WRITE(p, " ocol0.r = ocol0.r * 8.0f + gUpper;\n");
- WriteToBitDepth(p, 5, "texSample.b", "ocol0.a");
- WRITE(p, " ocol0.a = ocol0.a + gLower * 32.0f;\n");
-
- WRITE(p, " ocol0 = ocol0 / 255.0f;\n");
- WRITE(p, "}\n");
-}
-
-void WriteRGB5A3Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_RGB5A3);
-
- WRITE(p, " float4 texSample;\n");
- WRITE(p, " float color0;\n");
- WRITE(p, " float gUpper;\n");
- WRITE(p, " float gLower;\n");
-
- WriteSampleColor(p, "rgba", "texSample");
-
- // 0.8784 = 224 / 255 which is the maximum alpha value that can be represented in 3 bits
- WRITE(p, "if(texSample.a > 0.878f) {\n");
-
- WriteToBitDepth(p, 5, "texSample.g", "color0");
- WRITE(p, " gUpper = floor(color0 / 8.0f);\n");
- WRITE(p, " gLower = color0 - gUpper * 8.0f;\n");
-
- WriteToBitDepth(p, 5, "texSample.r", "ocol0.b");
- WRITE(p, " ocol0.b = ocol0.b * 4.0f + gUpper + 128.0f;\n");
- WriteToBitDepth(p, 5, "texSample.b", "ocol0.g");
- WRITE(p, " ocol0.g = ocol0.g + gLower * 32.0f;\n");
-
- WRITE(p, "} else {\n");
-
- WriteToBitDepth(p, 4, "texSample.r", "ocol0.b");
- WriteToBitDepth(p, 4, "texSample.b", "ocol0.g");
-
- WriteToBitDepth(p, 3, "texSample.a", "color0");
- WRITE(p, "ocol0.b = ocol0.b + color0 * 16.0f;\n");
- WriteToBitDepth(p, 4, "texSample.g", "color0");
- WRITE(p, "ocol0.g = ocol0.g + color0 * 16.0f;\n");
-
- WRITE(p, "}\n");
-
-
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgba", "texSample");
-
- WRITE(p, "if(texSample.a > 0.878f) {\n");
-
- WriteToBitDepth(p, 5, "texSample.g", "color0");
- WRITE(p, " gUpper = floor(color0 / 8.0f);\n");
- WRITE(p, " gLower = color0 - gUpper * 8.0f;\n");
-
- WriteToBitDepth(p, 5, "texSample.r", "ocol0.r");
- WRITE(p, " ocol0.r = ocol0.r * 4.0f + gUpper + 128.0f;\n");
- WriteToBitDepth(p, 5, "texSample.b", "ocol0.a");
- WRITE(p, " ocol0.a = ocol0.a + gLower * 32.0f;\n");
-
- WRITE(p, "} else {\n");
-
- WriteToBitDepth(p, 4, "texSample.r", "ocol0.r");
- WriteToBitDepth(p, 4, "texSample.b", "ocol0.a");
-
- WriteToBitDepth(p, 3, "texSample.a", "color0");
- WRITE(p, "ocol0.r = ocol0.r + color0 * 16.0f;\n");
- WriteToBitDepth(p, 4, "texSample.g", "color0");
- WRITE(p, "ocol0.a = ocol0.a + color0 * 16.0f;\n");
-
- WRITE(p, "}\n");
-
- WRITE(p, " ocol0 = ocol0 / 255.0f;\n");
- WRITE(p, "}\n");
-}
-
-void WriteRGBA4443Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_RGB5A3);
-
- WRITE(p, " float4 texSample;\n");
- WRITE(p, " float4 color0;\n");
- WRITE(p, " float4 color1;\n");
-
- WriteSampleColor(p, "rgba", "texSample");
- WriteToBitDepth(p, 3, "texSample.a", "color0.b");
- WriteToBitDepth(p, 4, "texSample.r", "color1.b");
- WriteToBitDepth(p, 4, "texSample.g", "color0.g");
- WriteToBitDepth(p, 4, "texSample.b", "color1.g");
-
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgba", "texSample");
- WriteToBitDepth(p, 3, "texSample.a", "color0.r");
- WriteToBitDepth(p, 4, "texSample.r", "color1.r");
- WriteToBitDepth(p, 4, "texSample.g", "color0.a");
- WriteToBitDepth(p, 4, "texSample.b", "color1.a");
-
- WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
- WRITE(p, "}\n");
-}
-
-void WriteRGBA8Encoder(char* p)
-{
- Write32BitSwizzler(p, GX_TF_RGBA8);
-
- WRITE(p, " float cl1 = xb - (halfxb * 2);\n");
- WRITE(p, " float cl0 = 1.0f - cl1;\n");
-
- WRITE(p, " float4 texSample;\n");
- WRITE(p, " float4 color0;\n");
- WRITE(p, " float4 color1;\n");
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " color0.b = texSample.a;\n");
- WRITE(p, " color0.g = texSample.r;\n");
- WRITE(p, " color1.b = texSample.g;\n");
- WRITE(p, " color1.g = texSample.b;\n");
-
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "rgba", "texSample");
- WRITE(p, " color0.r = texSample.a;\n");
- WRITE(p, " color0.a = texSample.r;\n");
- WRITE(p, " color1.r = texSample.g;\n");
- WRITE(p, " color1.a = texSample.b;\n");
-
- WRITE(p, " ocol0 = (cl0 * color0) + (cl1 * color1);\n");
-
- WRITE(p, "}\n");
-}
-
-void WriteC4Encoder(char* p, const char* comp)
-{
- WriteSwizzler(p, GX_CTF_R4);
- WRITE(p, " float4 color0;\n");
- WRITE(p, " float4 color1;\n");
-
- WriteSampleColor(p, comp, "color0.b");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "color1.b");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "color0.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "color1.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "color0.r");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "color1.r");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "color0.a");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "color1.a");
-
- WriteToBitDepth(p, 4, "color0", "color0");
- WriteToBitDepth(p, 4, "color1", "color1");
-
- WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
- WRITE(p, "}\n");
-}
-
-void WriteC8Encoder(char* p, const char* comp)
-{
- WriteSwizzler(p, GX_CTF_R8);
-
- WriteSampleColor(p, comp, "ocol0.b");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "ocol0.g");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "ocol0.r");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "ocol0.a");
-
- WRITE(p, "}\n");
-}
-
-void WriteCC4Encoder(char* p, const char* comp)
-{
- WriteSwizzler(p, GX_CTF_RA4);
- WRITE(p, " float2 texSample;\n");
- WRITE(p, " float4 color0;\n");
- WRITE(p, " float4 color1;\n");
-
- WriteSampleColor(p, comp, "texSample");
- WRITE(p, " color0.b = texSample.x;\n");
- WRITE(p, " color1.b = texSample.y;\n");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "texSample");
- WRITE(p, " color0.g = texSample.x;\n");
- WRITE(p, " color1.g = texSample.y;\n");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "texSample");
- WRITE(p, " color0.r = texSample.x;\n");
- WRITE(p, " color1.r = texSample.y;\n");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "texSample");
- WRITE(p, " color0.a = texSample.x;\n");
- WRITE(p, " color1.a = texSample.y;\n");
-
- WriteToBitDepth(p, 4, "color0", "color0");
- WriteToBitDepth(p, 4, "color1", "color1");
-
- WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
- WRITE(p, "}\n");
-}
-
-void WriteCC8Encoder(char* p, const char* comp)
-{
- WriteSwizzler(p, GX_CTF_RA8);
-
- WriteSampleColor(p, comp, "ocol0.bg");
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, comp, "ocol0.ra");
-
- WRITE(p, "}\n");
-}
-
-void WriteZ8Encoder(char* p, const char* multiplier)
-{
- WriteSwizzler(p, GX_CTF_Z8M);
-
- WRITE(p, " float depth;\n");
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier);
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier);
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier);
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier);
-
- WRITE(p, "}\n");
-}
-
-void WriteZ16Encoder(char* p)
-{
- WriteSwizzler(p, GX_TF_Z16);
-
- WRITE(p, " float depth;\n");
-
- // byte order is reversed
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, " ocol0.b = frac(depth * 256.0f);\n");
- WRITE(p, " ocol0.g = depth;\n");
-
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, " ocol0.r = frac(depth * 256.0f);\n");
- WRITE(p, " ocol0.a = depth;\n");
-
- WRITE(p, "}\n");
-}
-
-void WriteZ16LEncoder(char* p)
-{
- WriteSwizzler(p, GX_CTF_Z16L);
-
- WRITE(p, " float depth;\n");
-
- // byte order is reversed
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, " ocol0.b = frac(depth * 65536.0f);\n");
- WRITE(p, " ocol0.g = frac(depth * 256.0f);\n");
-
- WriteIncrementSampleX(p);
-
- WriteSampleColor(p, "b", "depth");
- WRITE(p, " ocol0.r = frac(depth * 65536.0f);\n");
- WRITE(p, " ocol0.a = frac(depth * 256.0f);\n");
-
- WRITE(p, "}\n");
-}
-
-void WriteZ24Encoder(char* p)
-{
- Write32BitSwizzler(p, GX_TF_Z24X8);
-
- WRITE(p, " float cl = xb - (halfxb * 2);\n");
-
- WRITE(p, " float depth0;\n");
- WRITE(p, " float depth1;\n");
-
- WriteSampleColor(p, "b", "depth0");
- WriteIncrementSampleX(p);
- WriteSampleColor(p, "b", "depth1");
-
- WRITE(p, " if(cl > 0.5f) {\n");
- // upper 16
- WRITE(p, " ocol0.b = frac(depth0 * 256.0f);\n");
- WRITE(p, " ocol0.g = depth0\n");
- WRITE(p, " ocol0.r = frac(depth1 * 256.0f);\n");
- WRITE(p, " ocol0.a = depth1\n");
- WRITE(p, " } else {\n");
- // lower 8
- WRITE(p, " ocol0.b = 1.0f;\n");
- WRITE(p, " ocol0.g = frac(depth0 * 65536.0f)\n");
- WRITE(p, " ocol0.r = 1.0f);\n");
- WRITE(p, " ocol0.a = frac(depth0 * 65536.0f)\n");
- WRITE(p, " }\n"
- "}\n");
-}
-
-const char *GenerateEncodingShader(u32 format)
-{
- text[sizeof(text) - 1] = 0x7C; // canary
-
- char *p = text;
-
- switch(format)
- {
- case GX_TF_I4:
- WriteI4Encoder(p);
- break;
- case GX_TF_I8:
- WriteI8Encoder(p);
- break;
- case GX_TF_IA4:
- WriteIA4Encoder(p);
- break;
- case GX_TF_IA8:
- WriteIA8Encoder(p);
- break;
- case GX_TF_RGB565:
- WriteRGB565Encoder(p);
- break;
- case GX_TF_RGB5A3:
- WriteRGB5A3Encoder(p);
- break;
- case GX_TF_RGBA8:
- WriteRGBA8Encoder(p);
- break;
- case GX_CTF_R4:
- WriteC4Encoder(p, "r");
- break;
- case GX_CTF_RA4:
- WriteCC4Encoder(p, "ar");
- break;
- case GX_CTF_RA8:
- WriteCC8Encoder(p, "ar");
- break;
- case GX_CTF_A8:
- WriteC8Encoder(p, "a");
- break;
- case GX_CTF_R8:
- WriteC8Encoder(p, "r");
- break;
- case GX_CTF_G8:
- WriteC8Encoder(p, "g");
- break;
- case GX_CTF_B8:
- WriteC8Encoder(p, "b");
- break;
- case GX_CTF_RG8:
- WriteCC8Encoder(p, "rg");
- break;
- case GX_CTF_GB8:
- WriteCC8Encoder(p, "gb");
- break;
- case GX_TF_Z8:
- WriteC8Encoder(p, "b");
- break;
- case GX_TF_Z16:
- WriteZ16Encoder(p);
- break;
- case GX_TF_Z24X8:
- WriteZ24Encoder(p);
- break;
- case GX_CTF_Z4:
- WriteC4Encoder(p, "b");
- break;
- case GX_CTF_Z8M:
- WriteZ8Encoder(p, "256.0f");
- break;
- case GX_CTF_Z8L:
- WriteZ8Encoder(p, "65536.0f" );
- break;
- case GX_CTF_Z16L:
- WriteZ16LEncoder(p);
- break;
- default:
- PanicAlert("Unknown texture copy format: 0x%x\n", format);
- break;
- }
-
- if (text[sizeof(text) - 1] != 0x7C)
- PanicAlert("TextureConversionShader generator - buffer too small, canary has been eaten!");
-
- return text;
-}
-
-void SetShaderParameters(float width, float height, float offsetX, float offsetY, float widthStride, float heightStride)
-{
- SetPSConstant4f(C_COLORMATRIX, widthStride, heightStride, 0.0f, 0.0f);
- SetPSConstant4f(C_COLORMATRIX + 1, width, (height - 1), offsetX, offsetY);
-}
-
-} // namespace
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.h
deleted file mode 100644
index 5874c16671..0000000000
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConversionShader.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2003 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/
-
-#ifndef _TEXTURECONVERSIONSHADER_H_
-#define _TEXTURECONVERSIONSHADER_H_
-
-#include "Common.h"
-#include "TextureDecoder.h"
-#include <Cg/cg.h>
-
-namespace TextureConversionShader
-{
-u16 GetEncodedSampleCount(u32 format);
-
-const char *GenerateEncodingShader(u32 format);
-
-void SetShaderParameters(float width, float height, float offsetX, float offsetY, float widthStride, float heightStride);
-
-}
-
-#endif // _TEXTURECONVERSIONSHADER_H_
-
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
index 2c00b30d8c..3ea35dcbb3 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
@@ -169,7 +169,7 @@ void Shutdown()
void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const TargetRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight, bool linearFilter)
{
- Renderer::ResetGLState();
+ Renderer::ResetAPIState();
// switch to texture converter frame buffer
// attach render buffer as color destination
@@ -218,13 +218,13 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar
GL_REPORT_ERRORD();
Renderer::SetFramebuffer(0);
- Renderer::RestoreGLState();
+ Renderer::RestoreAPIState();
VertexShaderManager::SetViewportChanged();
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
TextureMngr::DisableStage(0);
- Renderer::RestoreGLState();
+ Renderer::RestoreAPIState();
GL_REPORT_ERRORD();
}
@@ -314,7 +314,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
return;
}
- Renderer::ResetGLState();
+ Renderer::ResetAPIState();
float srcFormatFactor = 0.5f;
float srcFmtWidth = srcWidth * srcFormatFactor;
@@ -362,7 +362,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
Renderer::SetFramebuffer(0);
- Renderer::RestoreGLState();
+ Renderer::RestoreAPIState();
GL_REPORT_ERRORD();
}
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp
index 4cc66480b4..a26e8260bd 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp
@@ -686,7 +686,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
GL_REPORT_ERRORD();
// We have to run a pixel shader, for color conversion.
- Renderer::ResetGLState(); // reset any game specific settings
+ Renderer::ResetAPIState(); // reset any game specific settings
if (s_TempFramebuffer == 0)
glGenFramebuffersEXT(1, (GLuint *)&s_TempFramebuffer);
@@ -725,7 +725,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
// Return to the EFB.
Renderer::SetFramebuffer(0);
- Renderer::RestoreGLState();
+ Renderer::RestoreAPIState();
VertexShaderManager::SetViewportChanged();
TextureMngr::DisableStage(0);