diff options
author | Alejandro Marzini | 2010-07-20 04:32:31 +0000 |
---|---|---|
committer | Alejandro Marzini | 2010-07-20 04:32:31 +0000 |
commit | 302400a701187eba6d0dee2daa253da87b29d83f (patch) | |
tree | 14ef4ab769860d534fa56a40949eb4e31e355db9 /backends/graphics/opengl/gltexture.cpp | |
parent | 014d7b791c03c0c754ebc2d4ef2f2a961420a63a (diff) | |
download | scummvm-rg350-302400a701187eba6d0dee2daa253da87b29d83f.tar.gz scummvm-rg350-302400a701187eba6d0dee2daa253da87b29d83f.tar.bz2 scummvm-rg350-302400a701187eba6d0dee2daa253da87b29d83f.zip |
OPENGL: Implement fullscreen mode.
svn-id: r51049
Diffstat (limited to 'backends/graphics/opengl/gltexture.cpp')
-rw-r--r-- | backends/graphics/opengl/gltexture.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/backends/graphics/opengl/gltexture.cpp b/backends/graphics/opengl/gltexture.cpp index e1fb5ba00d..e3760ee2d8 100644 --- a/backends/graphics/opengl/gltexture.cpp +++ b/backends/graphics/opengl/gltexture.cpp @@ -77,7 +77,10 @@ GLTexture::GLTexture(byte bpp, GLenum format, GLenum type) _glFormat(format), _glType(type), _textureWidth(0), - _textureHeight(0) { + _textureHeight(0), + _realWidth(0), + _realHeight(0), + _refresh(false) { // Generates the texture ID for GL CHECK_GL_ERROR( glGenTextures(1, &_textureName) ); @@ -91,22 +94,20 @@ GLTexture::GLTexture(byte bpp, GLenum format, GLenum type) } GLTexture::~GLTexture() { - debug("Destroying texture %u", _textureName); CHECK_GL_ERROR( glDeleteTextures(1, &_textureName) ); } void GLTexture::refresh() { // Generates the texture ID for GL - //CHECK_GL_ERROR( glGenTextures(1, &_textureName) ); - //updateBuffer(_surface.pixels, _surface.bytesPerPixel, 0, 0, _surface.w, _surface.h); + CHECK_GL_ERROR( glGenTextures(1, &_textureName) ); + _refresh = true; } void GLTexture::allocBuffer(GLuint w, GLuint h) { - _surface.w = w; - _surface.h = h; - _surface.bytesPerPixel = _bytesPerPixel; - - if (w <= _textureWidth && h <= _textureHeight) + _realWidth = w; + _realHeight = h; + + if (w <= _textureWidth && h <= _textureHeight && !_refresh) // Already allocated a sufficiently large buffer return; @@ -117,9 +118,6 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) { _textureWidth = nextHigher2(w); _textureHeight = nextHigher2(h); } - _surface.pitch = _textureWidth * _bytesPerPixel; - - //_surface.create(w, h, _bytesPerPixel); // Allocate room for the texture now, but pixel data gets uploaded // later (perhaps with multiple TexSubImage2D operations). @@ -130,6 +128,11 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) { CHECK_GL_ERROR( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) ); CHECK_GL_ERROR( glTexImage2D(GL_TEXTURE_2D, 0, _glFormat, _textureWidth, _textureHeight, 0, _glFormat, _glType, NULL) ); + + if (_surface.w != _textureWidth || _surface.h != _textureHeight) + _surface.create(_textureWidth, _textureHeight, _bytesPerPixel); + + _refresh = false; } void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLuint w, GLuint h) { @@ -138,15 +141,13 @@ void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLu if (static_cast<int>(w) * _bytesPerPixel == pitch) { CHECK_GL_ERROR( glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, _glFormat, _glType, buf) ); - //memcpy(_surface.pixels, buf, w * pitch); + memcpy(_surface.getBasePtr(x, y), buf, h * pitch); } else { - // GLES removed the ability to specify pitch, so we - // have to do this row by row. const byte* src = static_cast<const byte*>(buf); do { CHECK_GL_ERROR( glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, 1, _glFormat, _glType, src) ); - //memcpy(_surface.pixels, src, pitch); + memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel); ++y; src += pitch; } while (--h); @@ -154,19 +155,17 @@ void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLu } void GLTexture::fillBuffer(byte x) { - byte* tmpbuf = new byte[_surface.h * _surface.w * _bytesPerPixel]; - memset(tmpbuf, x, _surface.h * _surface.w * _bytesPerPixel); + memset(_surface.pixels, x, _surface.h * _surface.pitch); CHECK_GL_ERROR( glBindTexture(GL_TEXTURE_2D, _textureName) ); CHECK_GL_ERROR( glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _surface.w, _surface.h, - _glFormat, _glType, tmpbuf) ); - delete[] tmpbuf; + _glFormat, _glType, _surface.pixels) ); } void GLTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) { CHECK_GL_ERROR( glBindTexture(GL_TEXTURE_2D, _textureName) ); - const GLfloat texWidth = (GLfloat)_surface.w / _textureWidth;//xdiv(_surface.w, _textureWidth); - const GLfloat texHeight = (GLfloat)_surface.h / _textureHeight;//xdiv(_surface.h, _textureHeight); + const GLfloat texWidth = (GLfloat)_realWidth / _textureWidth;//xdiv(_surface.w, _textureWidth); + const GLfloat texHeight = (GLfloat)_realHeight / _textureHeight;//xdiv(_surface.h, _textureHeight); const GLfloat texcoords[] = { 0, 0, texWidth, 0, |