OPENGL: Implement fullscreen mode.
svn-id: r51049
This commit is contained in:
parent
014d7b791c
commit
302400a701
6 changed files with 75 additions and 58 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue