some prepwork for opengl texture ID importing (skip rendertarget resolve on OGL display method) but there are still problems and it can't be enabled yet

This commit is contained in:
zeromus 2016-02-22 00:23:20 -06:00
parent 37619a8a34
commit 95bc69b448
11 changed files with 106 additions and 34 deletions

View File

@ -38,7 +38,16 @@ namespace BizHawk.Client.Common
{ {
var vp = Global.Emulator.VideoProvider(); var vp = Global.Emulator.VideoProvider();
var buff = vp.GetVideoBuffer(); var buff = vp.GetVideoBuffer();
if (buff.Length == 1)
{
//is a hacky opengl texture ID. can't handle this now!
//need to discuss options
//1. cores must be able to provide a pixels videoprovider in addition to a texture ID, on command (not very hard overall but interface changing and work per core)
//2. SavestateManager must be setup with a mechanism for resolving texture IDs (even less work, but sloppy)
//There are additional problems with AVWriting. They depend on VideoProvider providing pixels.
}
else
{
int out_w = vp.BufferWidth; int out_w = vp.BufferWidth;
int out_h = vp.BufferHeight; int out_h = vp.BufferHeight;
@ -51,6 +60,7 @@ namespace BizHawk.Client.Common
using (new SimpleTime("Save Framebuffer")) using (new SimpleTime("Save Framebuffer"))
bs.PutLump(BinaryStateLump.Framebuffer, (s) => QuickBmpFile.Save(Global.Emulator.VideoProvider(), s, out_w, out_h)); bs.PutLump(BinaryStateLump.Framebuffer, (s) => QuickBmpFile.Save(Global.Emulator.VideoProvider(), s, out_w, out_h));
} }
}
if (Global.MovieSession.Movie.IsActive) if (Global.MovieSession.Movie.IsActive)
{ {

View File

@ -348,7 +348,7 @@ namespace BizHawk.Client.EmuHawk
/// Then it will stuff it into the bound PresentationPanel. /// Then it will stuff it into the bound PresentationPanel.
/// --- /// ---
/// If the int[] is size=1, then it contains an openGL texture ID (and the size should be as specified from videoProvider) /// If the int[] is size=1, then it contains an openGL texture ID (and the size should be as specified from videoProvider)
/// Don't worry about the case where the frontend isnt using opengl; it isnt supported yet, and it will be my responsibility to deal with anyway /// Don't worry about the case where the frontend isnt using opengl; DisplayManager deals with it
/// </summary> /// </summary>
public void UpdateSource(IVideoProvider videoProvider) public void UpdateSource(IVideoProvider videoProvider)
{ {
@ -364,6 +364,20 @@ namespace BizHawk.Client.EmuHawk
UpdateSourceInternal(job); UpdateSourceInternal(job);
} }
public BitmapBuffer RenderVideoProvider(IVideoProvider videoProvider)
{
var job = new JobInfo
{
videoProvider = videoProvider,
simulate = false,
chain_outsize = new Size(videoProvider.BufferWidth, videoProvider.BufferHeight),
offscreen = true,
includeOSD = false
};
UpdateSourceInternal(job);
return job.offscreenBB;
}
public BitmapBuffer RenderOffscreen(IVideoProvider videoProvider, bool includeOSD) public BitmapBuffer RenderOffscreen(IVideoProvider videoProvider, bool includeOSD)
{ {
var job = new JobInfo var job = new JobInfo
@ -653,6 +667,7 @@ namespace BizHawk.Client.EmuHawk
fPresent.TextureSize = new Size(bufferWidth, bufferHeight); fPresent.TextureSize = new Size(bufferWidth, bufferHeight);
fPresent.BackgroundColor = videoProvider.BackgroundColor; fPresent.BackgroundColor = videoProvider.BackgroundColor;
fPresent.GuiRenderer = Renderer; fPresent.GuiRenderer = Renderer;
fPresent.Flip = isGlTextureId;
fPresent.Config_FixAspectRatio = Global.Config.DispFixAspectRatio; fPresent.Config_FixAspectRatio = Global.Config.DispFixAspectRatio;
fPresent.Config_FixScaleInteger = Global.Config.DispFixScaleInteger; fPresent.Config_FixScaleInteger = Global.Config.DispFixScaleInteger;
fPresent.Padding = ClientExtraPadding; fPresent.Padding = ClientExtraPadding;
@ -681,7 +696,7 @@ namespace BizHawk.Client.EmuHawk
//begin rendering on this context //begin rendering on this context
//should this have been done earlier? //should this have been done earlier?
//do i need to check this on an intel video card to see if running excessively is a problem? (it used to be in the FinalTarget command below, shouldnt be a problem) //do i need to check this on an intel video card to see if running excessively is a problem? (it used to be in the FinalTarget command below, shouldnt be a problem)
//GraphicsControl.Begin(); //GraphicsControl.Begin(); //CRITICAL POINT for yabause+GL
GlobalWin.GL.BeginScene(); GlobalWin.GL.BeginScene();
@ -736,6 +751,7 @@ namespace BizHawk.Client.EmuHawk
if (job.offscreen) if (job.offscreen)
{ {
job.offscreenBB = rtCurr.Texture2d.Resolve(); job.offscreenBB = rtCurr.Texture2d.Resolve();
job.offscreenBB.DiscardAlpha();
} }
else else
{ {

View File

@ -178,6 +178,7 @@ namespace BizHawk.Client.EmuHawk.Filters
public Size TextureSize, VirtualTextureSize; public Size TextureSize, VirtualTextureSize;
public int BackgroundColor; public int BackgroundColor;
public IGuiRenderer GuiRenderer; public IGuiRenderer GuiRenderer;
public bool Flip;
public IGL GL; public IGL GL;
bool nop; bool nop;
LetterboxingLogic LL; LetterboxingLogic LL;
@ -238,6 +239,8 @@ namespace BizHawk.Client.EmuHawk.Filters
need = true; need = true;
if (FilterOption != eFilterOption.None) if (FilterOption != eFilterOption.None)
need = true; need = true;
if (Flip)
need = true;
if (!need) if (!need)
{ {
@ -318,7 +321,13 @@ namespace BizHawk.Client.EmuHawk.Filters
} }
GuiRenderer.Draw(InputTexture,LL.vx,LL.vy,LL.vw,LL.vh); GuiRenderer.Modelview.Translate(LL.vx, LL.vy);
if (Flip)
{
GuiRenderer.Modelview.Scale(1, -1);
GuiRenderer.Modelview.Translate(0, -LL.vh);
}
GuiRenderer.Draw(InputTexture,0,0,LL.vw,LL.vh);
GuiRenderer.End(); GuiRenderer.End();
} }

View File

@ -916,7 +916,6 @@ namespace BizHawk.Client.EmuHawk
{ {
using (var bb = GlobalWin.DisplayManager.RenderOffscreen(Global.Emulator.VideoProvider(), Global.Config.Screenshot_CaptureOSD)) using (var bb = GlobalWin.DisplayManager.RenderOffscreen(Global.Emulator.VideoProvider(), Global.Config.Screenshot_CaptureOSD))
{ {
bb.DiscardAlpha();
using (var img = bb.ToSysdrawingBitmap()) using (var img = bb.ToSysdrawingBitmap())
Clipboard.SetImage(img); Clipboard.SetImage(img);
} }
@ -1895,11 +1894,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private static unsafe BitmapBuffer MakeScreenshotImage() private static BitmapBuffer MakeScreenshotImage()
{ {
var bb = new BitmapBuffer(Global.Emulator.VideoProvider().BufferWidth, Global.Emulator.VideoProvider().BufferHeight, Global.Emulator.VideoProvider().GetVideoBuffer()); return GlobalWin.DisplayManager.RenderVideoProvider(Global.Emulator.VideoProvider());
bb.DiscardAlpha();
return bb;
} }
private void SaveSlotSelectedMessage() private void SaveSlotSelectedMessage()

View File

@ -127,7 +127,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.IGL_GL = new Bizware.BizwareGL.Drivers.OpenTK.IGL_TK(2,0,false); GlobalWin.IGL_GL = new Bizware.BizwareGL.Drivers.OpenTK.IGL_TK(2,0,false);
//setup the GL context manager, needed for coping with multiple opengl cores vs opengl display method //setup the GL context manager, needed for coping with multiple opengl cores vs opengl display method
GLManager.CreateInstance(); GLManager.CreateInstance(GlobalWin.IGL_GL);
GlobalWin.GLManager = GLManager.Instance; GlobalWin.GLManager = GLManager.Instance;
GlobalWin.CR_GL = GlobalWin.GLManager.GetContextForIGL(GlobalWin.GL); GlobalWin.CR_GL = GlobalWin.GLManager.GetContextForIGL(GlobalWin.GL);

View File

@ -86,7 +86,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; private set; }
static object glContext; object glContext;
void ActivateGL() void ActivateGL()
{ {
@ -329,7 +329,14 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn
#region IVideoProvider #region IVideoProvider
int[] VideoBuffer = new int[704 * 512]; int[] VideoBuffer = new int[704 * 512];
public int[] GetVideoBuffer() { return VideoBuffer; } int[] TextureIdBuffer = new int[1]; //todo
public int[] GetVideoBuffer() {
//doesn't work yet
//if (SyncSettings.UseGL)
// return new[] { VideoBuffer[0] };
//else
return VideoBuffer;
}
public int VirtualWidth { get { return BufferWidth; } } public int VirtualWidth { get { return BufferWidth; } }
public int VirtualHeight { get { return BufferHeight; } } public int VirtualHeight { get { return BufferHeight; } }
public int BufferWidth { get; private set; } public int BufferWidth { get; private set; }

View File

@ -23,6 +23,7 @@ using BizHawk.Bizware.BizwareGL;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
using otkg = OpenTK.Graphics;
namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
{ {
@ -496,7 +497,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
public Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height) public Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height)
{ {
return new Texture2d(this as IGL, glTexId, width, height); return new Texture2d(this as IGL, glTexId.ToInt32(), width, height);
} }
public void LoadTextureData(Texture2d tex, BitmapBuffer bmp) public void LoadTextureData(Texture2d tex, BitmapBuffer bmp)
@ -590,6 +591,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
var bb = new BitmapBuffer(tex.IntWidth, tex.IntHeight); var bb = new BitmapBuffer(tex.IntWidth, tex.IntHeight);
var bmpdata = bb.LockBits(); var bmpdata = bb.LockBits();
GL.GetTexImage(TextureTarget.Texture2D, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bmpdata.Scan0); GL.GetTexImage(TextureTarget.Texture2D, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bmpdata.Scan0);
var err = GL.GetError();
bb.UnlockBits(bmpdata); bb.UnlockBits(bmpdata);
return bb; return bb;
} }

View File

@ -35,8 +35,11 @@ namespace BizHawk.Bizware.BizwareGL
/// draws the specified Art resource with the specified offset, with the specified size. This could be tricky if youve applied other rotate or scale transforms first. /// draws the specified Art resource with the specified offset, with the specified size. This could be tricky if youve applied other rotate or scale transforms first.
/// </summary> /// </summary>
void Draw(Art art, float x, float y, float width, float height); void Draw(Art art, float x, float y, float width, float height);
void Draw(Texture2d art, float x, float y, float width, float height);
/// <summary>
/// draws the specified Texture with the specified offset, with the specified size. This could be tricky if youve applied other rotate or scale transforms first.
/// </summary>
void Draw(Texture2d art, float x, float y, float width, float height);
/// <summary> /// <summary>
/// draws the specified texture2d resource. /// draws the specified texture2d resource.

View File

@ -52,6 +52,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBYABAUSE_EXPORTS;HAVE_C99_VARIADIC_MACROS;VERSION="LIB";C68K_NO_JUMP_TABLE;HAVE_LIBGL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBYABAUSE_EXPORTS;HAVE_C99_VARIADIC_MACROS;VERSION="LIB";C68K_NO_JUMP_TABLE;HAVE_LIBGL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4244;4996;4018;4146</DisableSpecificWarnings> <DisableSpecificWarnings>4244;4996;4018;4146</DisableSpecificWarnings>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>

View File

@ -280,6 +280,7 @@ PerPad_struct *ctrl2;
extern "C" int vdp2height; extern "C" int vdp2height;
extern "C" int vdp2width; extern "C" int vdp2width;
extern "C" GLuint FboTexture;
/* Tells the yui to exchange front and back video buffers. This may end /* Tells the yui to exchange front and back video buffers. This may end
up being moved to the Video Core. */ up being moved to the Video Core. */
@ -305,6 +306,10 @@ void YuiSwapBuffers(void)
} }
else else
{ {
#ifdef CAN_RETURN_TEXTURE_IDS
//simply write the FboTexture into the videobuffer for later magic detection in frontend
memcpy(vidbuff,&FboTexture,4);
#else
glReadPixels(0, 0, glwidth, glheight, GL_BGRA, GL_UNSIGNED_BYTE, glbuff); glReadPixels(0, 0, glwidth, glheight, GL_BGRA, GL_UNSIGNED_BYTE, glbuff);
u32 *src = (u32*)glbuff; u32 *src = (u32*)glbuff;
@ -318,6 +323,7 @@ void YuiSwapBuffers(void)
src += glwidth; src += glwidth;
dst -= glwidth; dst -= glwidth;
} }
#endif
} }
} }
} }

View File

@ -57,6 +57,7 @@ extern int vdp1cog;
extern int vdp1cob; extern int vdp1cob;
GLuint DefaultFrameBuffer; GLuint DefaultFrameBuffer;
GLuint FboTexture, MainFbo;
#ifdef HAVE_GLXGETPROCADDRESS #ifdef HAVE_GLXGETPROCADDRESS
void STDCALL * (*yglGetProcAddress)(const char *szProcName) = (void STDCALL *(*)(const char *))glXGetProcAddress; void STDCALL * (*yglGetProcAddress)(const char *szProcName) = (void STDCALL *(*)(const char *))glXGetProcAddress;
@ -563,6 +564,26 @@ int YglGLInit(int width, int height) {
glBindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBuffer);
glBindTexture(GL_TEXTURE_2D,_Ygl->texture); glBindTexture(GL_TEXTURE_2D,_Ygl->texture);
//bizhawk code: create a texture for reading from the main FBO
//if the alternate 'main' FBO isn't created yet, now's the time
if(MainFbo == 0)
{
glGenFramebuffers(1,&MainFbo);
glBindFramebuffer(GL_FRAMEBUFFER, MainFbo);
DefaultFrameBuffer = MainFbo;
}
//delete existing texture if we already have it
if( FboTexture != 0 ) glDeleteTextures(1,&FboTexture);
glGenTextures(1, &FboTexture);
glBindTexture(GL_TEXTURE_2D, FboTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GlWidth, GlHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FboTexture, 0);
glBindTexture(GL_TEXTURE_2D, 0);
return 0; return 0;
} }