summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/chromium/GLES2Texture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/chromium/GLES2Texture.cpp')
-rw-r--r--WebCore/platform/graphics/chromium/GLES2Texture.cpp58
1 files changed, 30 insertions, 28 deletions
diff --git a/WebCore/platform/graphics/chromium/GLES2Texture.cpp b/WebCore/platform/graphics/chromium/GLES2Texture.cpp
index 26c8bf7..5e8a141 100644
--- a/WebCore/platform/graphics/chromium/GLES2Texture.cpp
+++ b/WebCore/platform/graphics/chromium/GLES2Texture.cpp
@@ -34,14 +34,15 @@
#include "GLES2Texture.h"
-#include <GLES2/gl2.h>
+#include "GraphicsContext3D.h"
#include <wtf/OwnArrayPtr.h>
namespace WebCore {
-GLES2Texture::GLES2Texture(unsigned int textureId, Format format, int width, int height)
- : m_textureId(textureId)
+GLES2Texture::GLES2Texture(GraphicsContext3D* context, unsigned textureId, Format format, int width, int height)
+ : m_context(context)
+ , m_textureId(textureId)
, m_format(format)
, m_width(width)
, m_height(height)
@@ -50,25 +51,26 @@ GLES2Texture::GLES2Texture(unsigned int textureId, Format format, int width, int
GLES2Texture::~GLES2Texture()
{
- glDeleteTextures(1, &m_textureId);
+ m_context->deleteTexture(m_textureId);
}
-PassRefPtr<GLES2Texture> GLES2Texture::create(Format format, int width, int height)
+PassRefPtr<GLES2Texture> GLES2Texture::create(GraphicsContext3D* context, Format format, int width, int height)
{
- GLuint textureId;
- glGenTextures(1, &textureId);
- if (!textureId)
+ int max;
+ context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &max);
+ if (width > max || height > max) {
+ ASSERT(!"texture too big");
return 0;
+ }
- glBindTexture(GL_TEXTURE_2D, textureId);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ unsigned textureId = context->createTexture();
+ if (!textureId)
+ return 0;
- int max;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
- if (width > max || height > max)
- ASSERT(!"texture too big");
+ context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId);
+ context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, width, height, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, 0);
- return adoptRef(new GLES2Texture(textureId, format, width, height));
+ return adoptRef(new GLES2Texture(context, textureId, format, width, height));
}
static void convertFormat(GLES2Texture::Format format, unsigned int* glFormat, unsigned int* glType, bool* swizzle)
@@ -76,14 +78,14 @@ static void convertFormat(GLES2Texture::Format format, unsigned int* glFormat, u
*swizzle = false;
switch (format) {
case GLES2Texture::RGBA8:
- *glFormat = GL_RGBA;
- *glType = GL_UNSIGNED_BYTE;
+ *glFormat = GraphicsContext3D::RGBA;
+ *glType = GraphicsContext3D::UNSIGNED_BYTE;
break;
case GLES2Texture::BGRA8:
// FIXME: Once we have support for extensions, we should check for EXT_texture_format_BGRA8888,
// and use that if present.
- *glFormat = GL_RGBA;
- *glType = GL_UNSIGNED_BYTE;
+ *glFormat = GraphicsContext3D::RGBA;
+ *glType = GraphicsContext3D::UNSIGNED_BYTE;
*swizzle = true;
break;
default:
@@ -97,9 +99,9 @@ void GLES2Texture::load(void* pixels)
unsigned int glFormat, glType;
bool swizzle;
convertFormat(m_format, &glFormat, &glType, &swizzle);
- glBindTexture(GL_TEXTURE_2D, m_textureId);
+ m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
if (swizzle) {
- ASSERT(glFormat == GL_RGBA && glType == GL_UNSIGNED_BYTE);
+ ASSERT(glFormat == GraphicsContext3D::RGBA && glType == GraphicsContext3D::UNSIGNED_BYTE);
// FIXME: This could use PBO's to save doing an extra copy here.
int size = m_width * m_height;
unsigned* pixels32 = static_cast<unsigned*>(pixels);
@@ -109,18 +111,18 @@ void GLES2Texture::load(void* pixels)
unsigned pixel = pixels32[i];
bufptr[i] = pixel & 0xFF00FF00 | ((pixel & 0x00FF0000) >> 16) | ((pixel & 0x000000FF) << 16);
}
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, buf.get());
+ m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, buf.get());
} else
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, pixels);
+ m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, pixels);
}
void GLES2Texture::bind()
{
- glBindTexture(GL_TEXTURE_2D, m_textureId);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
}
}