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 "GSTextureOGL.h"
|
2009-06-16 01:42:08 +00:00
|
|
|
#include "GSDeviceOGL.h"
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
GSTextureOGL::GSTextureOGL(GLuint texture, int type, int width, int height, int format)
|
2009-06-12 19:09:17 +00:00
|
|
|
: m_texture(texture)
|
2009-06-13 19:41:34 +00:00
|
|
|
, m_type(type)
|
|
|
|
, m_format(format)
|
2009-06-12 19:09:17 +00:00
|
|
|
{
|
2009-07-16 21:36:07 +00:00
|
|
|
m_size.x = width;
|
|
|
|
m_size.y = height;
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
// TODO: offscreen type should be just a memory array, also returned in Map
|
|
|
|
|
|
|
|
glGenBuffers(1, &m_pbo); GSDeviceOGL::CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
}
|
2009-06-12 19:09:17 +00:00
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
GSTextureOGL::~GSTextureOGL()
|
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
if(m_pbo)
|
|
|
|
{
|
|
|
|
glDeleteBuffers(1, &m_pbo); GSDeviceOGL::CheckError();
|
|
|
|
}
|
|
|
|
|
2009-06-13 19:41:34 +00:00
|
|
|
if(m_texture)
|
|
|
|
{
|
|
|
|
switch(m_type)
|
|
|
|
{
|
|
|
|
case DepthStencil:
|
2009-06-16 01:42:08 +00:00
|
|
|
glDeleteRenderbuffers(1, &m_texture); GSDeviceOGL::CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-06-16 01:42:08 +00:00
|
|
|
glDeleteTextures(1, &m_texture); GSDeviceOGL::CheckError();
|
2009-06-13 19:41:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 19:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GSTextureOGL::GetType() const
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GSTextureOGL::GetFormat() const
|
|
|
|
{
|
|
|
|
return m_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch)
|
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo); GSDeviceOGL::CheckError();
|
|
|
|
|
|
|
|
int w = r.width();
|
|
|
|
int h = r.height();
|
|
|
|
int bpp = 32; // TODO: should be in sync with m_format
|
|
|
|
int dstpitch = w * bpp >> 3;
|
|
|
|
|
|
|
|
glBufferData(GL_PIXEL_UNPACK_BUFFER, h * dstpitch, NULL, GL_STREAM_DRAW); GSDeviceOGL::CheckError();
|
|
|
|
|
|
|
|
if(uint8* dst = (uint8*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY))
|
|
|
|
{
|
|
|
|
uint8* src = (uint8*)data;
|
|
|
|
|
|
|
|
for(int i = 0; i < h; i++, src += pitch, dst += dstpitch)
|
|
|
|
{
|
|
|
|
memcpy(dst, src, dstpitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); GSDeviceOGL::CheckError();
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, m_texture); GSDeviceOGL::CheckError();
|
|
|
|
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, r.left, r.top, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0); GSDeviceOGL::CheckError();
|
|
|
|
|
|
|
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); GSDeviceOGL::CheckError();
|
2009-06-12 19:09:17 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSTextureOGL::Map(GSMap& m, const GSVector4i* r)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSTextureOGL::Unmap()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSTextureOGL::Save(const string& fn, bool dds)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|