Moved the Texture and Quad Lua wrapper files out of the opengl graphics implementation folder.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2015-03-01 03:51:44 -04:00
parent c572b1af19
commit 3830a0969c
28 changed files with 79 additions and 202 deletions
+2
View File
@@ -100,6 +100,8 @@ public:
virtual const Vertex *getVertices() const;
virtual const void *getHandle() const = 0;
// The default filter.
static void setDefaultFilter(const Filter &f);
static const Filter &getDefaultFilter();
+6 -12
View File
@@ -301,7 +301,7 @@ void Canvas::drawv(const Matrix &t, const Vertex *v)
OpenGL::TempTransform transform(gl);
transform.get() *= t;
predraw();
gl.bindTexture(texture);
glEnableVertexAttribArray(ATTRIB_POS);
glEnableVertexAttribArray(ATTRIB_TEXCOORD);
@@ -314,8 +314,6 @@ void Canvas::drawv(const Matrix &t, const Vertex *v)
glDisableVertexAttribArray(ATTRIB_TEXCOORD);
glDisableVertexAttribArray(ATTRIB_POS);
postdraw();
}
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
@@ -350,7 +348,8 @@ bool Canvas::setWrap(const Texture::Wrap &w)
bool success = true;
wrap = w;
if (hasLimitedNpot() && (width != next_p2(width) || height != next_p2(height)))
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
&& (width != next_p2(width) || height != next_p2(height)))
{
if (wrap.s != WRAP_CLAMP || wrap.t != WRAP_CLAMP)
success = false;
@@ -365,14 +364,9 @@ bool Canvas::setWrap(const Texture::Wrap &w)
return success;
}
GLuint Canvas::getGLTexture() const
const void *Canvas::getHandle() const
{
return texture;
}
void Canvas::predraw()
{
gl.bindTexture(texture);
return &texture;
}
void Canvas::setupGrab()
@@ -459,7 +453,7 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
for (int i = 0; i < (int) canvases.size(); i++)
{
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 + i,
GL_TEXTURE_2D, canvases[i]->getGLTexture(), 0);
GL_TEXTURE_2D, *(GLuint *) canvases[i]->getHandle(), 0);
drawbuffers.push_back(GL_COLOR_ATTACHMENT1 + i);
}
+4 -4
View File
@@ -28,7 +28,8 @@
#include "common/Matrix.h"
#include "common/StringMap.h"
#include "common/int.h"
#include "Texture.h"
#include "graphics/Texture.h"
#include "graphics/Volatile.h"
#include "OpenGL.h"
namespace love
@@ -38,7 +39,7 @@ namespace graphics
namespace opengl
{
class Canvas : public Texture
class Canvas : public Texture, public Volatile
{
public:
@@ -73,8 +74,7 @@ public:
virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
virtual void setFilter(const Texture::Filter &f);
virtual bool setWrap(const Texture::Wrap &w);
virtual GLuint getGLTexture() const;
virtual void predraw();
virtual const void *getHandle() const;
/**
* @param canvases A list of other canvases to temporarily attach to this one,
+1
View File
@@ -40,6 +40,7 @@
#include "Font.h"
#include "Image.h"
#include "graphics/Quad.h"
#include "graphics/Texture.h"
#include "SpriteBatch.h"
#include "ParticleSystem.h"
#include "Canvas.h"
+12 -27
View File
@@ -149,7 +149,7 @@ void Image::loadDefaultTexture()
{
usingDefaultTexture = true;
bind();
gl.bindTexture(texture);
setFilter(filter);
// A nice friendly checkerboard to signify invalid textures...
@@ -224,7 +224,8 @@ bool Image::loadVolatile()
}
// NPOT textures don't support mipmapping without full NPOT support.
if (hasLimitedNpot() && (width != next_p2(width) || height != next_p2(height)))
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
&& (width != next_p2(width) || height != next_p2(height)))
{
flags.mipmaps = false;
filter.mipmap = FILTER_NONE;
@@ -323,7 +324,7 @@ bool Image::refresh(int xoffset, int yoffset, int w, int h)
throw love::Exception("Invalid rectangle dimensions.");
}
bind();
gl.bindTexture(texture);
if (isCompressed())
loadTextureFromCompressedData();
@@ -344,21 +345,12 @@ bool Image::refresh(int xoffset, int yoffset, int w, int h)
return true;
}
void Image::predraw()
{
bind();
}
void Image::postdraw()
{
}
void Image::drawv(const Matrix &t, const Vertex *v)
{
OpenGL::TempTransform transform(gl);
transform.get() *= t;
predraw();
gl.bindTexture(texture);
glEnableVertexAttribArray(ATTRIB_POS);
glEnableVertexAttribArray(ATTRIB_TEXCOORD);
@@ -371,8 +363,6 @@ void Image::drawv(const Matrix &t, const Vertex *v)
glDisableVertexAttribArray(ATTRIB_TEXCOORD);
glDisableVertexAttribArray(ATTRIB_POS);
postdraw();
}
void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
@@ -391,9 +381,9 @@ void Image::drawq(Quad *quad, float x, float y, float angle, float sx, float sy,
drawv(t, quad->getVertices());
}
GLuint Image::getGLTexture() const
const void *Image::getHandle() const
{
return texture;
return &texture;
}
love::image::ImageData *Image::getImageData() const
@@ -425,7 +415,7 @@ void Image::setFilter(const Texture::Filter &f)
filter.min = filter.mag = FILTER_NEAREST;
}
bind();
gl.bindTexture(texture);
gl.setTextureFilter(filter);
}
@@ -434,7 +424,8 @@ bool Image::setWrap(const Texture::Wrap &w)
bool success = true;
wrap = w;
if (hasLimitedNpot() && (width != next_p2(width) || height != next_p2(height)))
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
&& (width != next_p2(width) || height != next_p2(height)))
{
if (wrap.s != WRAP_CLAMP || wrap.t != WRAP_CLAMP)
success = false;
@@ -443,7 +434,7 @@ bool Image::setWrap(const Texture::Wrap &w)
wrap.s = wrap.t = WRAP_CLAMP;
}
bind();
gl.bindTexture(texture);
gl.setTextureWrap(w);
return success;
@@ -458,7 +449,7 @@ void Image::setMipmapSharpness(float sharpness)
// LOD bias has the range (-maxbias, maxbias)
mipmapSharpness = std::min(std::max(sharpness, -maxMipmapSharpness + 0.01f), maxMipmapSharpness - 0.01f);
bind();
gl.bindTexture(texture);
// negative bias is sharper
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -mipmapSharpness);
@@ -469,12 +460,6 @@ float Image::getMipmapSharpness() const
return mipmapSharpness;
}
void Image::bind() const
{
if (texture != 0)
gl.bindTexture(texture);
}
const Image::Flags &Image::getFlags() const
{
return flags;
+4 -13
View File
@@ -29,7 +29,8 @@
#include "common/math.h"
#include "image/ImageData.h"
#include "image/CompressedData.h"
#include "Texture.h"
#include "graphics/Texture.h"
#include "graphics/Volatile.h"
// OpenGL
#include "OpenGL.h"
@@ -47,7 +48,7 @@ namespace opengl
*
* @author Anders Ruud
**/
class Image : public Texture
class Image : public Texture, public Volatile
{
public:
@@ -97,15 +98,7 @@ public:
**/
void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
/**
* Call before using this Image's texture to draw. Binds the texture,
* globally scales texture coordinates if the Image has NPOT dimensions and
* NPOT isn't supported, etc.
**/
virtual void predraw();
virtual void postdraw();
virtual GLuint getGLTexture() const;
virtual const void *getHandle() const;
love::image::ImageData *getImageData() const;
love::image::CompressedData *getCompressedData() const;
@@ -121,8 +114,6 @@ public:
**/
bool isCompressed() const;
void bind() const;
/**
* Re-uploads the ImageData or CompressedData associated with this Image to
* the GPU.
+1 -4
View File
@@ -318,7 +318,7 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
return;
if (texture.get())
texture->predraw();
gl.bindTexture(*(GLuint *) texture->getHandle());
else
gl.bindTexture(gl.getDefaultTexture());
@@ -394,9 +394,6 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
// Using the color array leaves the GL constant color undefined.
gl.setColor(gl.getColor());
}
if (texture.get())
texture->postdraw();
}
GLenum Mesh::getGLDrawMode(DrawMode mode) const
+1 -1
View File
@@ -27,7 +27,7 @@
#include "common/math.h"
#include "common/StringMap.h"
#include "graphics/Drawable.h"
#include "Texture.h"
#include "graphics/Texture.h"
#include "VertexBuffer.h"
// C++
@@ -876,7 +876,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
p = p->next;
}
texture->predraw();
gl.bindTexture(*(GLuint *) texture->getHandle());
gl.prepareDraw();
glEnableVertexAttribArray(ATTRIB_COLOR);
@@ -896,8 +896,6 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
glDisableVertexAttribArray(ATTRIB_POS);
glDisableVertexAttribArray(ATTRIB_COLOR);
texture->postdraw();
gl.setColor(curcolor);
}
+1 -1
View File
@@ -28,7 +28,7 @@
#include "graphics/Drawable.h"
#include "graphics/Color.h"
#include "graphics/Quad.h"
#include "Texture.h"
#include "graphics/Texture.h"
#include "VertexBuffer.h"
// STL
+1 -1
View File
@@ -536,7 +536,7 @@ void Shader::sendMatrix(const std::string &name, int size, const GLfloat *m, int
void Shader::sendTexture(const std::string &name, Texture *texture)
{
GLuint gltex = texture->getGLTexture();
GLuint gltex = *(GLuint *) texture->getHandle();
TemporaryAttacher attacher(this);
+2 -1
View File
@@ -25,8 +25,9 @@
#include "common/Object.h"
#include "common/StringMap.h"
#include "graphics/Graphics.h"
#include "graphics/Texture.h"
#include "graphics/Volatile.h"
#include "OpenGL.h"
#include "Texture.h"
// STL
#include <string>
+2 -4
View File
@@ -26,7 +26,7 @@
// LOVE
#include "VertexBuffer.h"
#include "Texture.h"
#include "graphics/Texture.h"
// C++
#include <algorithm>
@@ -238,7 +238,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
OpenGL::TempTransform transform(gl);
transform.get() *= t;
texture->predraw();
gl.bindTexture(*(GLuint *) texture->getHandle());
VertexBuffer::Bind array_bind(*array_buf);
VertexBuffer::Bind element_bind(*element_buf.getVertexBuffer());
@@ -273,8 +273,6 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
glDisableVertexAttribArray(ATTRIB_COLOR);
gl.setColor(curcolor);
}
texture->postdraw();
}
void SpriteBatch::addv(const Vertex *v, const Matrix &m, int index)
+3 -2
View File
@@ -38,12 +38,13 @@ namespace love
{
namespace graphics
{
namespace opengl
{
// Forward declarations.
class Texture;
namespace opengl
{
class SpriteBatch : public Drawable
{
public:
-73
View File
@@ -1,73 +0,0 @@
/**
* Copyright (c) 2006-2015 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_OPENGL_TEXTURE_H
#define LOVE_GRAPHICS_OPENGL_TEXTURE_H
// LOVE
#include "graphics/Texture.h"
#include "graphics/Volatile.h"
#include "OpenGL.h"
namespace love
{
namespace graphics
{
namespace opengl
{
class Texture : public love::graphics::Texture, public Volatile
{
public:
virtual ~Texture() {}
/**
* Gets the OpenGL id for this texture.
**/
virtual GLuint getGLTexture() const = 0;
/**
* Any setup the texture might need to do before drawing, e.g. binding
* the OpenGL texture for use.
**/
virtual void predraw() {}
/**
* Any cleanup the texture might need to do directly after drawing.
**/
virtual void postdraw() {}
/**
* Unextended OpenGL ES 2 doesn't support non-clamp wrap modes or mipmapping
* with non-power-of-two textures.
**/
static bool hasLimitedNpot()
{
return GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot);
}
}; // Texture
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_TEXTURE_H
+1 -1
View File
@@ -24,7 +24,7 @@
// LOVE
#include "common/runtime.h"
#include "Canvas.h"
#include "wrap_Texture.h"
#include "graphics/wrap_Texture.h"
namespace love
{
+1 -1
View File
@@ -24,7 +24,7 @@
// LOVE
#include "wrap_Font.h"
#include "wrap_Image.h"
#include "wrap_Quad.h"
#include "graphics/wrap_Quad.h"
#include "wrap_SpriteBatch.h"
#include "wrap_ParticleSystem.h"
#include "wrap_Canvas.h"
+1 -1
View File
@@ -24,7 +24,7 @@
// LOVE
#include "common/runtime.h"
#include "Image.h"
#include "wrap_Texture.h"
#include "graphics/wrap_Texture.h"
namespace love
{
+1 -1
View File
@@ -22,7 +22,7 @@
#include "wrap_Mesh.h"
#include "Image.h"
#include "Canvas.h"
#include "wrap_Texture.h"
#include "graphics/wrap_Texture.h"
// C++
#include <typeinfo>
@@ -24,7 +24,7 @@
#include "Image.h"
#include "Canvas.h"
#include "wrap_Texture.h"
#include "graphics/wrap_Texture.h"
// C
#include <cstring>
+1 -1
View File
@@ -19,7 +19,7 @@
**/
#include "wrap_Shader.h"
#include "wrap_Texture.h"
#include "graphics/wrap_Texture.h"
#include <string>
#include <iostream>
@@ -22,7 +22,7 @@
#include "wrap_SpriteBatch.h"
#include "Image.h"
#include "Canvas.h"
#include "wrap_Texture.h"
#include "graphics/wrap_Texture.h"
// C++
#include <typeinfo>
@@ -25,8 +25,6 @@ namespace love
{
namespace graphics
{
namespace opengl
{
Quad *luax_checkquad(lua_State *L, int idx)
{
@@ -78,6 +76,5 @@ extern "C" int luaopen_quad(lua_State *L)
return luax_register_type(L, "Quad", functions);
}
} // opengl
} // graphics
} // love
@@ -18,27 +18,24 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
#define LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
#ifndef LOVE_GRAPHICS_WRAP_QUAD_H
#define LOVE_GRAPHICS_WRAP_QUAD_H
// LOVE
#include "common/runtime.h"
#include "graphics/Quad.h"
#include "Quad.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Quad *luax_checkquad(lua_State *L, int idx);
int w_Quad_setViewport(lua_State *L);
int w_Quad_getViewport(lua_State *L);
extern "C" int luaopen_quad(lua_State *L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
#endif // LOVE_GRAPHICS_WRAP_QUAD_H
@@ -24,8 +24,6 @@ namespace love
{
namespace graphics
{
namespace opengl
{
Texture *luax_checktexture(lua_State *L, int idx)
{
@@ -127,7 +125,5 @@ int w_Texture_getWrap(lua_State *L)
return 2;
}
} // opengl
} // graphics
} // love
@@ -18,8 +18,8 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_TEXTURE_H
#define LOVE_GRAPHICS_OPENGL_WRAP_TEXTURE_H
#ifndef LOVE_GRAPHICS_WRAP_TEXTURE_H
#define LOVE_GRAPHICS_WRAP_TEXTURE_H
#include "Texture.h"
#include "common/runtime.h"
@@ -28,8 +28,6 @@ namespace love
{
namespace graphics
{
namespace opengl
{
Texture *luax_checktexture(lua_State *L, int idx);
int w_Texture_getWidth(lua_State *L);
@@ -40,8 +38,7 @@ int w_Texture_getFilter(lua_State *L);
int w_Texture_setWrap(lua_State *L);
int w_Texture_getWrap(lua_State *L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_TEXTURE_H
#endif // LOVE_GRAPHICS_WRAP_TEXTURE_H