2009-06-12 19:09:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* 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; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GSdx.h"
|
|
|
|
#include "GSDeviceOGL.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
GSDeviceOGL::GSDeviceOGL()
|
|
|
|
: m_hDC(NULL)
|
|
|
|
, m_hGLRC(NULL)
|
2009-06-13 19:41:34 +00:00
|
|
|
, m_vbo(0)
|
|
|
|
, m_fbo(0)
|
2009-06-17 11:24:42 +00:00
|
|
|
, m_context(0)
|
2009-06-13 19:41:34 +00:00
|
|
|
, m_topology(-1)
|
2009-06-17 11:24:42 +00:00
|
|
|
, m_ps_ss(NULL)
|
|
|
|
, m_scissor(0, 0, 0, 0)
|
|
|
|
, m_viewport(0, 0)
|
|
|
|
, m_dss(NULL)
|
|
|
|
, m_bs(NULL)
|
|
|
|
, m_bf(-1)
|
2009-06-16 01:42:08 +00:00
|
|
|
, m_rt((GLuint)-1)
|
|
|
|
, m_ds((GLuint)-1)
|
2009-06-12 19:09:17 +00:00
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
m_vertices.stride = 0;
|
|
|
|
m_vertices.start = 0;
|
|
|
|
m_vertices.count = 0;
|
|
|
|
m_vertices.limit = 0;
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSDeviceOGL::~GSDeviceOGL()
|
|
|
|
{
|
2009-06-17 11:24:42 +00:00
|
|
|
if(m_context) cgDestroyContext(m_context);
|
2009-06-13 19:41:34 +00:00
|
|
|
if(m_vbo) glDeleteBuffers(1, &m_vbo);
|
|
|
|
if(m_fbo) glDeleteFramebuffers(1, &m_fbo);
|
|
|
|
|
2009-06-12 19:09:17 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
if(m_hGLRC) {wglMakeCurrent(NULL, NULL); wglDeleteContext(m_hGLRC);}
|
|
|
|
if(m_hDC) ReleaseDC((HWND)m_wnd->GetHandle(), m_hDC);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::OnCgError(CGcontext ctx, CGerror err)
|
|
|
|
{
|
|
|
|
printf("%s\n", cgGetErrorString(err));
|
|
|
|
printf("%s\n", cgGetLastListing(ctx)); // ?
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync)
|
|
|
|
{
|
|
|
|
if(!__super::Create(wnd, vsync))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cgSetErrorHandler(OnStaticCgError, this);
|
|
|
|
|
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
|
|
|
|
memset(&pfd, 0, sizeof(pfd));
|
|
|
|
|
|
|
|
pfd.nSize = sizeof(pfd);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 32;
|
|
|
|
pfd.cDepthBits = 32; // 24?
|
|
|
|
pfd.cStencilBits = 8;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
|
|
|
|
m_hDC = GetDC((HWND)m_wnd->GetHandle());
|
|
|
|
|
|
|
|
if(!m_hDC) return false;
|
|
|
|
|
|
|
|
if(!SetPixelFormat(m_hDC, ChoosePixelFormat(m_hDC, &pfd), &pfd))
|
2009-06-13 19:41:34 +00:00
|
|
|
{
|
2009-06-12 19:09:17 +00:00
|
|
|
return false;
|
2009-06-13 19:41:34 +00:00
|
|
|
}
|
2009-06-12 19:09:17 +00:00
|
|
|
|
|
|
|
m_hGLRC = wglCreateContext(m_hDC);
|
|
|
|
|
|
|
|
if(!m_hGLRC) return false;
|
|
|
|
|
|
|
|
if(!wglMakeCurrent(m_hDC, m_hGLRC))
|
2009-06-13 19:41:34 +00:00
|
|
|
{
|
2009-06-12 19:09:17 +00:00
|
|
|
return false;
|
2009-06-13 19:41:34 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 19:09:17 +00:00
|
|
|
#endif
|
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
if(glewInit() != GLEW_OK)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
if(WGLEW_EXT_swap_control)
|
|
|
|
{
|
|
|
|
wglSwapIntervalEXT(vsync ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const char* vendor = (const char*)glGetString(GL_VENDOR);
|
|
|
|
const char* renderer = (const char*)glGetString(GL_RENDERER);
|
|
|
|
const char* version = (const char*)glGetString(GL_VERSION);
|
|
|
|
const char* exts = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
|
|
|
|
printf("%s, %s, OpenGL %s\n", vendor, renderer, version);
|
|
|
|
|
|
|
|
const char* str = strstr(exts, "ARB_texture_non_power_of_two");
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glGenBuffers(1, &m_vbo); CheckError();
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
// TODO: setup layout?
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-17 11:24:42 +00:00
|
|
|
m_context = cgCreateContext();
|
|
|
|
|
|
|
|
// cgGLSetDebugMode(CG_FALSE); CheckCgError();
|
|
|
|
|
|
|
|
cgSetParameterSettingMode(m_context, CG_DEFERRED_PARAMETER_SETTING); CheckCgError();
|
|
|
|
/*
|
|
|
|
struct {CGprofile vs, gs, ps;} m_profile;
|
|
|
|
m_profile.vs = cgGLGetLatestProfile(CG_GL_VERTEX); CheckCgError();
|
|
|
|
m_profile.gs = cgGLGetLatestProfile(CG_GL_GEOMETRY); CheckCgError();
|
|
|
|
m_profile.ps = cgGLGetLatestProfile(CG_GL_FRAGMENT); CheckCgError();
|
|
|
|
*/
|
2009-06-13 19:41:34 +00:00
|
|
|
GSVector4i r = wnd->GetClientRect();
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-07-04 15:14:04 +00:00
|
|
|
Reset(r.width(), r.height(), Windowed);
|
2009-06-12 19:09:17 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-04 15:14:04 +00:00
|
|
|
bool GSDeviceOGL::Reset(int w, int h, int mode)
|
2009-06-12 19:09:17 +00:00
|
|
|
{
|
2009-07-04 15:14:04 +00:00
|
|
|
if(!__super::Reset(w, h, mode))
|
2009-06-12 19:09:17 +00:00
|
|
|
return false;
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glCullFace(GL_FRONT_AND_BACK); CheckError();
|
|
|
|
glDisable(GL_LIGHTING); CheckError();
|
|
|
|
glDisable(GL_ALPHA_TEST); CheckError();
|
|
|
|
glEnable(GL_SCISSOR_TEST); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glMatrixMode(GL_PROJECTION); CheckError();
|
|
|
|
glLoadIdentity(); CheckError();
|
|
|
|
glMatrixMode(GL_MODELVIEW); CheckError();
|
|
|
|
glLoadIdentity(); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
// glViewport(0, 0, w, h);
|
|
|
|
|
|
|
|
if(m_fbo) {glDeleteFramebuffersEXT(1, &m_fbo); m_fbo = 0;}
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glGenFramebuffers(1, &m_fbo); CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
|
|
|
|
if(m_fbo == 0) return false;
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-16 21:36:07 +00:00
|
|
|
void GSDeviceOGL::Present(const GSVector4i& r, int shader, bool limit)
|
2009-06-16 01:42:08 +00:00
|
|
|
{
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); CheckError();
|
|
|
|
|
|
|
|
// TODO: m_current => backbuffer
|
|
|
|
|
2009-07-16 21:36:07 +00:00
|
|
|
Flip(limit);
|
2009-06-16 01:42:08 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 21:36:07 +00:00
|
|
|
void GSDeviceOGL::Flip(bool limit)
|
2009-06-12 19:09:17 +00:00
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
SwapBuffers(m_hDC);
|
|
|
|
|
|
|
|
#endif
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::BeginScene()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::DrawPrimitive()
|
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
glDrawArrays(m_topology, m_vertices.count, m_vertices.start); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::EndScene()
|
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
m_vertices.start += m_vertices.count;
|
|
|
|
m_vertices.count = 0;
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c)
|
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
GLuint texture = *(GSTextureOGL*)t;
|
|
|
|
|
|
|
|
if(texture == 0)
|
|
|
|
{
|
|
|
|
// TODO: backbuffer
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, texture); CheckError();
|
|
|
|
}
|
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
// TODO: disable scissor, color mask
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glClearColor(c.r, c.g, c.b, c.a); CheckError();
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, uint32 c)
|
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
ClearRenderTarget(t, GSVector4(c) * (1.0f / 255));
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::ClearDepth(GSTexture* t, float c)
|
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT, *(GSTextureOGL*)t); CheckError();
|
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
// TODO: disable scissor, depth mask
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glClearDepth(c); CheckError();
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::ClearStencil(GSTexture* t, uint8 c)
|
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX, *(GSTextureOGL*)t); CheckError();
|
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
// TODO: disable scissor, depth (?) mask
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glClearStencil((GLint)c); CheckError();
|
|
|
|
glClear(GL_STENCIL_BUFFER_BIT); CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::Create(int type, int w, int h, int format)
|
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
GLuint texture = 0;
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GSTexture::RenderTarget:
|
2009-06-16 01:42:08 +00:00
|
|
|
glGenTextures(1, &texture); CheckError();
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture); CheckError();
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
break;
|
|
|
|
case GSTexture::DepthStencil:
|
2009-06-16 01:42:08 +00:00
|
|
|
glGenRenderbuffers(1, &texture); CheckError();
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, texture); CheckError();
|
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH32F_STENCIL8, w, h); CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
// TODO: depth textures?
|
|
|
|
break;
|
|
|
|
case GSTexture::Texture:
|
2009-06-16 01:42:08 +00:00
|
|
|
glGenTextures(1, &texture); CheckError();
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture); CheckError();
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
break;
|
|
|
|
case GSTexture::Offscreen:
|
|
|
|
// TODO: ???
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!texture) return false;
|
|
|
|
|
|
|
|
GSTextureOGL* t = new GSTextureOGL(texture, type, w, h, format);
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GSTexture::RenderTarget:
|
|
|
|
ClearRenderTarget(t, 0);
|
|
|
|
break;
|
|
|
|
case GSTexture::DepthStencil:
|
|
|
|
ClearDepth(t, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::CreateRenderTarget(int w, int h, int format)
|
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
return __super::CreateRenderTarget(w, h, format ? format : GL_RGBA8);
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::CreateDepthStencil(int w, int h, int format)
|
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
return __super::CreateDepthStencil(w, h, format ? format : GL_DEPTH32F_STENCIL8); // TODO: GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::CreateTexture(int w, int h, int format)
|
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
return __super::CreateTexture(w, h, format ? format : GL_RGBA8);
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::CreateOffscreen(int w, int h, int format)
|
|
|
|
{
|
2009-06-13 19:41:34 +00:00
|
|
|
return __super::CreateOffscreen(w, h, format ? format : GL_RGBA8);
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture* GSDeviceOGL::CopyOffscreen(GSTexture* src, const GSVector4& sr, int w, int h, int format)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
void GSDeviceOGL::CopyRect(GSTexture* st, GSTexture* dt, const GSVector4i& r)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2009-06-12 19:09:17 +00:00
|
|
|
void GSDeviceOGL::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader, bool linear)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::DoMerge(GSTexture* st[2], GSVector4* sr, GSVector4* dr, GSTexture* dt, bool slbg, bool mmod, const GSVector4& c)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool linear, float yoffset)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
2009-06-13 19:41:34 +00:00
|
|
|
|
|
|
|
void GSDeviceOGL::IASetVertexBuffer(const void* vertices, size_t stride, size_t count)
|
|
|
|
{
|
|
|
|
ASSERT(m_vertices.count == 0);
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); CheckError();
|
|
|
|
|
|
|
|
bool growbuffer = false;
|
|
|
|
bool discard = false; // in opengl 3.x this should be a flag to glMapBuffer, as I read somewhere
|
2009-06-13 19:41:34 +00:00
|
|
|
|
|
|
|
if(count * stride > m_vertices.limit * m_vertices.stride)
|
|
|
|
{
|
|
|
|
m_vertices.start = 0;
|
|
|
|
m_vertices.count = 0;
|
2009-07-04 15:14:04 +00:00
|
|
|
m_vertices.limit = std::max<int>(count * 3 / 2, 10000);
|
2009-06-16 01:42:08 +00:00
|
|
|
|
|
|
|
growbuffer = true;
|
2009-06-13 19:41:34 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
if(m_vertices.start + count > m_vertices.limit || stride != m_vertices.stride)
|
2009-06-13 19:41:34 +00:00
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
m_vertices.start = 0;
|
2009-06-13 19:41:34 +00:00
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
discard = true;
|
2009-06-13 19:41:34 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
if(growbuffer || discard)
|
2009-06-13 19:41:34 +00:00
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
glBufferData(GL_ARRAY_BUFFER, m_vertices.limit * stride, NULL, GL_DYNAMIC_DRAW); CheckError(); // GL_STREAM_DRAW?
|
2009-06-13 19:41:34 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, m_vertices.start * stride, count * stride, vertices); CheckError();
|
|
|
|
/*
|
2009-06-13 19:41:34 +00:00
|
|
|
if(GLvoid* v = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY))
|
|
|
|
{
|
|
|
|
GSVector4i::storent((uint8*)v + m_vertices.start * stride, vertices, count * stride);
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER); CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
}
|
2009-06-16 01:42:08 +00:00
|
|
|
*/
|
2009-06-13 19:41:34 +00:00
|
|
|
m_vertices.count = count;
|
|
|
|
m_vertices.stride = stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::IASetInputLayout()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::IASetPrimitiveTopology(int topology)
|
|
|
|
{
|
|
|
|
m_topology = topology;
|
|
|
|
}
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
void GSDeviceOGL::PSSetShaderResources(GSTexture* sr0, GSTexture* sr1)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2009-06-17 11:24:42 +00:00
|
|
|
void GSDeviceOGL::PSSetSamplerState(SamplerStateOGL* ss)
|
|
|
|
{
|
|
|
|
if(ss && m_ps_ss != ss)
|
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
m_ps_ss = ss;
|
|
|
|
|
2009-06-17 11:24:42 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ss->wrap.s);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, ss->wrap.t);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ss->filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ss->filter);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ss->wrap.s);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, ss->wrap.t);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ss->filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ss->filter);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE2);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_POINT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_POINT);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE3);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_POINT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_POINT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::OMSetDepthStencilState(DepthStencilStateOGL* dss)
|
|
|
|
{
|
|
|
|
if(m_dss != dss)
|
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
m_dss = dss;
|
|
|
|
|
2009-06-17 11:24:42 +00:00
|
|
|
if(dss->depth.enable)
|
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST); CheckError();
|
|
|
|
glDepthFunc(dss->depth.func); CheckError();
|
|
|
|
glDepthMask(dss->depth.write); CheckError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_DEPTH_TEST); CheckError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dss->stencil.enable)
|
|
|
|
{
|
|
|
|
glEnable(GL_STENCIL_TEST); CheckError();
|
|
|
|
glStencilFunc(dss->stencil.func, dss->stencil.ref, dss->stencil.mask); CheckError();
|
|
|
|
glStencilOp(dss->stencil.sfail, dss->stencil.dpfail, dss->stencil.dppass); CheckError();
|
|
|
|
glStencilMask(dss->stencil.wmask); CheckError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_STENCIL_TEST); CheckError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSDeviceOGL::OMSetBlendState(BlendStateOGL* bs, float bf)
|
|
|
|
{
|
|
|
|
if(m_bs != bs || m_bf != bf)
|
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
m_bs = bs;
|
|
|
|
m_bf = bf;
|
|
|
|
|
2009-06-17 11:24:42 +00:00
|
|
|
if(bs->enable)
|
|
|
|
{
|
|
|
|
glEnable(GL_BLEND); CheckError();
|
|
|
|
glBlendEquationSeparate(bs->modeRGB, bs->modeAlpha); CheckError();
|
|
|
|
glBlendFuncSeparate(bs->srcRGB, bs->dstRGB, bs->srcAlpha, bs->dstAlpha); CheckError();
|
|
|
|
glBlendColor(bf, bf, bf, 0); CheckError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDisable(GL_BLEND); CheckError();
|
|
|
|
}
|
|
|
|
|
|
|
|
glColorMask(bs->mask.r, bs->mask.g, bs->mask.b, bs->mask.a); CheckError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
void GSDeviceOGL::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor)
|
2009-06-16 01:42:08 +00:00
|
|
|
{
|
|
|
|
GLuint rti = 0;
|
|
|
|
GLuint dsi = 0;
|
|
|
|
|
|
|
|
if(rt) rti = *(GSTextureOGL*)rt;
|
|
|
|
if(ds) dsi = *(GSTextureOGL*)ds;
|
|
|
|
|
2009-06-17 11:24:42 +00:00
|
|
|
if(m_rt != rti)
|
2009-06-16 01:42:08 +00:00
|
|
|
{
|
2009-06-17 11:24:42 +00:00
|
|
|
m_rt = rti;
|
2009-07-22 03:55:28 +00:00
|
|
|
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rti); CheckError();
|
2009-06-16 01:42:08 +00:00
|
|
|
}
|
|
|
|
|
2009-06-17 11:24:42 +00:00
|
|
|
if(m_ds != dsi)
|
2009-06-16 01:42:08 +00:00
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
m_ds = dsi;
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT, dsi); CheckError();
|
2009-07-22 03:55:28 +00:00
|
|
|
}
|
2009-06-16 01:42:08 +00:00
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
if(m_viewport != rt->m_size)
|
|
|
|
{
|
|
|
|
m_viewport = rt->m_size;
|
|
|
|
|
|
|
|
glViewport(0, 0, rt->m_size.x, rt->m_size.y); CheckError();
|
|
|
|
}
|
|
|
|
|
|
|
|
GSVector4i r = scissor ? *scissor : GSVector4i(rt->m_size).zwxy();
|
|
|
|
|
|
|
|
if(!m_scissor.eq(r))
|
|
|
|
{
|
|
|
|
m_scissor = r;
|
|
|
|
|
|
|
|
glScissor(r.left, r.top, r.width(), r.height()); CheckError();
|
2009-06-16 01:42:08 +00:00
|
|
|
}
|
|
|
|
}
|