Commit e9c5e4f1 by Nicolas Capens Committed by Nicolas Capens

Implement GL_OES_EGL_image_external support.

BUG=14610416 Change-Id: I9ca6d1779c7b6f1b28d5d5665264815881ee01b5 Reviewed-on: https://swiftshader-review.googlesource.com/1071Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 434311cd
...@@ -42,6 +42,7 @@ enum TBasicType ...@@ -42,6 +42,7 @@ enum TBasicType
EbtGuardSamplerBegin, // non type: see implementation of IsSampler() EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
EbtSampler2D, EbtSampler2D,
EbtSamplerCube, EbtSamplerCube,
EbtSamplerExternalOES,
EbtGuardSamplerEnd, // non type: see implementation of IsSampler() EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
EbtStruct, EbtStruct,
EbtAddress, // should be deprecated?? EbtAddress, // should be deprecated??
...@@ -52,14 +53,15 @@ inline const char* getBasicString(TBasicType t) ...@@ -52,14 +53,15 @@ inline const char* getBasicString(TBasicType t)
{ {
switch (t) switch (t)
{ {
case EbtVoid: return "void"; break; case EbtVoid: return "void";
case EbtFloat: return "float"; break; case EbtFloat: return "float";
case EbtInt: return "int"; break; case EbtInt: return "int";
case EbtBool: return "bool"; break; case EbtBool: return "bool";
case EbtSampler2D: return "sampler2D"; break; case EbtSampler2D: return "sampler2D";
case EbtSamplerCube: return "samplerCube"; break; case EbtSamplerCube: return "samplerCube";
case EbtStruct: return "structure"; break; case EbtSamplerExternalOES: return "samplerExternalOES";
default: return "unknown type"; case EbtStruct: return "structure";
default: return "unknown type";
} }
} }
......
...@@ -295,6 +295,15 @@ void InsertBuiltInFunctions(ShShaderType type, const ShBuiltInResources &resourc ...@@ -295,6 +295,15 @@ void InsertBuiltInFunctions(ShShaderType type, const ShBuiltInResources &resourc
symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1); symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1);
} }
TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1);
if(resources.OES_EGL_image_external)
{
symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, float2);
symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float3);
symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float4);
}
TTypeList *members = NewPoolTTypeList(); TTypeList *members = NewPoolTTypeList();
TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
......
...@@ -420,12 +420,9 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt ...@@ -420,12 +420,9 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
// //
// Does the base type allow operation? // Does the base type allow operation?
// //
switch (node->getBasicType()) { if (node->getBasicType() == EbtVoid || IsSampler(node->getBasicType()))
case EbtVoid: {
case EbtSampler2D: return 0;
case EbtSamplerCube:
return 0;
default: break;
} }
// //
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define GL_APICALL #define GL_APICALL
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
namespace sh namespace sh
{ {
...@@ -2280,6 +2281,10 @@ namespace sh ...@@ -2280,6 +2281,10 @@ namespace sh
{ {
return GL_SAMPLER_CUBE; return GL_SAMPLER_CUBE;
} }
else if(type.getBasicType() == EbtSamplerExternalOES)
{
return GL_SAMPLER_EXTERNAL_OES;
}
else UNREACHABLE(); else UNREACHABLE();
return GL_NONE; return GL_NONE;
......
...@@ -326,16 +326,13 @@ bool TParseContext::lValueErrorCheck(int line, const char* op, TIntermTyped* nod ...@@ -326,16 +326,13 @@ bool TParseContext::lValueErrorCheck(int line, const char* op, TIntermTyped* nod
// //
// Type that can't be written to? // Type that can't be written to?
// //
switch (node->getBasicType()) { if(IsSampler(node->getBasicType()))
case EbtSampler2D: {
case EbtSamplerCube:
message = "can't modify a sampler"; message = "can't modify a sampler";
break; }
case EbtVoid: else if(node->getBasicType() == EbtVoid)
{
message = "can't modify void"; message = "can't modify void";
break;
default:
break;
} }
} }
......
...@@ -110,6 +110,7 @@ void ShInitBuiltInResources(ShBuiltInResources* resources) ...@@ -110,6 +110,7 @@ void ShInitBuiltInResources(ShBuiltInResources* resources)
// Extensions. // Extensions.
resources->OES_standard_derivatives = 0; resources->OES_standard_derivatives = 0;
resources->OES_fragment_precision_high = 0; resources->OES_fragment_precision_high = 0;
resources->OES_EGL_image_external = 0;
resources->MaxCallStackDepth = UINT_MAX; resources->MaxCallStackDepth = UINT_MAX;
} }
......
...@@ -52,6 +52,7 @@ void TType::buildMangledName(TString& mangledName) ...@@ -52,6 +52,7 @@ void TType::buildMangledName(TString& mangledName)
case EbtBool: mangledName += 'b'; break; case EbtBool: mangledName += 'b'; break;
case EbtSampler2D: mangledName += "s2"; break; case EbtSampler2D: mangledName += "s2"; break;
case EbtSamplerCube: mangledName += "sC"; break; case EbtSamplerCube: mangledName += "sC"; break;
case EbtSamplerExternalOES: mangledName += "sE"; break;
case EbtStruct: case EbtStruct:
mangledName += "struct-"; mangledName += "struct-";
if (typeName) if (typeName)
......
...@@ -63,6 +63,7 @@ static ShDataType getVariableDataType(const TType& type) ...@@ -63,6 +63,7 @@ static ShDataType getVariableDataType(const TType& type)
} }
case EbtSampler2D: return SH_SAMPLER_2D; case EbtSampler2D: return SH_SAMPLER_2D;
case EbtSamplerCube: return SH_SAMPLER_CUBE; case EbtSamplerCube: return SH_SAMPLER_CUBE;
case EbtSamplerExternalOES: return SH_SAMPLER_EXTERNAL_OES;
default: UNREACHABLE(); default: UNREACHABLE();
} }
return SH_NONE; return SH_NONE;
......
...@@ -133,6 +133,7 @@ O [0-7] ...@@ -133,6 +133,7 @@ O [0-7]
"sampler2D" { context->lexAfterType = true; return SAMPLER2D; } "sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; } "samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
"struct" { context->lexAfterType = true; return(STRUCT); } "struct" { context->lexAfterType = true; return(STRUCT); }
......
...@@ -113,7 +113,7 @@ extern void yyerror(TParseContext* context, const char* reason); ...@@ -113,7 +113,7 @@ extern void yyerror(TParseContext* context, const char* reason);
%token <lex> BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 VEC2 VEC3 VEC4 %token <lex> BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 VEC2 VEC3 VEC4
%token <lex> MATRIX2 MATRIX3 MATRIX4 IN_QUAL OUT_QUAL INOUT_QUAL UNIFORM VARYING %token <lex> MATRIX2 MATRIX3 MATRIX4 IN_QUAL OUT_QUAL INOUT_QUAL UNIFORM VARYING
%token <lex> STRUCT VOID_TYPE WHILE %token <lex> STRUCT VOID_TYPE WHILE
%token <lex> SAMPLER2D SAMPLERCUBE %token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES
%token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT BOOLCONSTANT %token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT BOOLCONSTANT
%token <lex> FIELD_SELECTION %token <lex> FIELD_SELECTION
...@@ -1657,6 +1657,15 @@ type_specifier_nonarray ...@@ -1657,6 +1657,15 @@ type_specifier_nonarray
TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
$$.setBasic(EbtSamplerCube, qual, $1.line); $$.setBasic(EbtSamplerCube, qual, $1.line);
} }
| SAMPLER_EXTERNAL_OES {
if (!context->supportsExtension("GL_OES_EGL_image_external")) {
context->error($1.line, "unsupported type", "samplerExternalOES", "");
context->recover();
}
FRAG_VERT_ONLY("samplerExternalOES", $1.line);
TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
$$.setBasic(EbtSamplerExternalOES, qual, $1.line);
}
| struct_specifier { | struct_specifier {
FRAG_VERT_ONLY("struct", $1.line); FRAG_VERT_ONLY("struct", $1.line);
$$ = $1; $$ = $1;
......
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C /* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Foundation, Inc. Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -78,57 +79,58 @@ ...@@ -78,57 +79,58 @@
WHILE = 295, WHILE = 295,
SAMPLER2D = 296, SAMPLER2D = 296,
SAMPLERCUBE = 297, SAMPLERCUBE = 297,
IDENTIFIER = 298, SAMPLER_EXTERNAL_OES = 298,
TYPE_NAME = 299, IDENTIFIER = 299,
FLOATCONSTANT = 300, TYPE_NAME = 300,
INTCONSTANT = 301, FLOATCONSTANT = 301,
BOOLCONSTANT = 302, INTCONSTANT = 302,
FIELD_SELECTION = 303, BOOLCONSTANT = 303,
LEFT_OP = 304, FIELD_SELECTION = 304,
RIGHT_OP = 305, LEFT_OP = 305,
INC_OP = 306, RIGHT_OP = 306,
DEC_OP = 307, INC_OP = 307,
LE_OP = 308, DEC_OP = 308,
GE_OP = 309, LE_OP = 309,
EQ_OP = 310, GE_OP = 310,
NE_OP = 311, EQ_OP = 311,
AND_OP = 312, NE_OP = 312,
OR_OP = 313, AND_OP = 313,
XOR_OP = 314, OR_OP = 314,
MUL_ASSIGN = 315, XOR_OP = 315,
DIV_ASSIGN = 316, MUL_ASSIGN = 316,
ADD_ASSIGN = 317, DIV_ASSIGN = 317,
MOD_ASSIGN = 318, ADD_ASSIGN = 318,
LEFT_ASSIGN = 319, MOD_ASSIGN = 319,
RIGHT_ASSIGN = 320, LEFT_ASSIGN = 320,
AND_ASSIGN = 321, RIGHT_ASSIGN = 321,
XOR_ASSIGN = 322, AND_ASSIGN = 322,
OR_ASSIGN = 323, XOR_ASSIGN = 323,
SUB_ASSIGN = 324, OR_ASSIGN = 324,
LEFT_PAREN = 325, SUB_ASSIGN = 325,
RIGHT_PAREN = 326, LEFT_PAREN = 326,
LEFT_BRACKET = 327, RIGHT_PAREN = 327,
RIGHT_BRACKET = 328, LEFT_BRACKET = 328,
LEFT_BRACE = 329, RIGHT_BRACKET = 329,
RIGHT_BRACE = 330, LEFT_BRACE = 330,
DOT = 331, RIGHT_BRACE = 331,
COMMA = 332, DOT = 332,
COLON = 333, COMMA = 333,
EQUAL = 334, COLON = 334,
SEMICOLON = 335, EQUAL = 335,
BANG = 336, SEMICOLON = 336,
DASH = 337, BANG = 337,
TILDE = 338, DASH = 338,
PLUS = 339, TILDE = 339,
STAR = 340, PLUS = 340,
SLASH = 341, STAR = 341,
PERCENT = 342, SLASH = 342,
LEFT_ANGLE = 343, PERCENT = 343,
RIGHT_ANGLE = 344, LEFT_ANGLE = 344,
VERTICAL_BAR = 345, RIGHT_ANGLE = 345,
CARET = 346, VERTICAL_BAR = 346,
AMPERSAND = 347, CARET = 347,
QUESTION = 348 AMPERSAND = 348,
QUESTION = 349
}; };
#endif #endif
......
...@@ -53,7 +53,8 @@ typedef enum { ...@@ -53,7 +53,8 @@ typedef enum {
SH_FLOAT_MAT3 = 0x8B5B, SH_FLOAT_MAT3 = 0x8B5B,
SH_FLOAT_MAT4 = 0x8B5C, SH_FLOAT_MAT4 = 0x8B5C,
SH_SAMPLER_2D = 0x8B5E, SH_SAMPLER_2D = 0x8B5E,
SH_SAMPLER_CUBE = 0x8B60 SH_SAMPLER_CUBE = 0x8B60,
SH_SAMPLER_EXTERNAL_OES = 0x8D66
} ShDataType; } ShDataType;
typedef enum { typedef enum {
...@@ -108,6 +109,7 @@ typedef struct ...@@ -108,6 +109,7 @@ typedef struct
// Set to 1 to enable the extension, else 0. // Set to 1 to enable the extension, else 0.
int OES_standard_derivatives; int OES_standard_derivatives;
int OES_fragment_precision_high; int OES_fragment_precision_high;
int OES_EGL_image_external;
unsigned int MaxCallStackDepth; unsigned int MaxCallStackDepth;
} ShBuiltInResources; } ShBuiltInResources;
......
...@@ -126,6 +126,7 @@ Context::Context(const egl::Config *config, const Context *shareContext) : mConf ...@@ -126,6 +126,7 @@ Context::Context(const egl::Config *config, const Context *shareContext) : mConf
mTexture2DZero.set(new Texture2D(0)); mTexture2DZero.set(new Texture2D(0));
mTextureCubeMapZero.set(new TextureCubeMap(0)); mTextureCubeMapZero.set(new TextureCubeMap(0));
mTextureExternalZero.set(new TextureExternal(0));
mState.activeSampler = 0; mState.activeSampler = 0;
bindArrayBuffer(0); bindArrayBuffer(0);
...@@ -206,6 +207,7 @@ Context::~Context() ...@@ -206,6 +207,7 @@ Context::~Context()
mTexture2DZero.set(NULL); mTexture2DZero.set(NULL);
mTextureCubeMapZero.set(NULL); mTextureCubeMapZero.set(NULL);
mTextureExternalZero.set(NULL);
delete mVertexDataManager; delete mVertexDataManager;
delete mIndexDataManager; delete mIndexDataManager;
...@@ -222,8 +224,6 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -222,8 +224,6 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
mVertexDataManager = new VertexDataManager(this); mVertexDataManager = new VertexDataManager(this);
mIndexDataManager = new IndexDataManager(); mIndexDataManager = new IndexDataManager();
initExtensionString();
mState.viewportX = 0; mState.viewportX = 0;
mState.viewportY = 0; mState.viewportY = 0;
mState.viewportWidth = surface->getWidth(); mState.viewportWidth = surface->getWidth();
...@@ -929,6 +929,13 @@ void Context::bindTextureCubeMap(GLuint texture) ...@@ -929,6 +929,13 @@ void Context::bindTextureCubeMap(GLuint texture)
mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].set(getTexture(texture)); mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].set(getTexture(texture));
} }
void Context::bindTextureExternal(GLuint texture)
{
mResourceManager->checkTextureAllocation(texture, TEXTURE_EXTERNAL);
mState.samplerTexture[TEXTURE_EXTERNAL][mState.activeSampler].set(getTexture(texture));
}
void Context::bindReadFramebuffer(GLuint framebuffer) void Context::bindReadFramebuffer(GLuint framebuffer)
{ {
if(!getFramebuffer(framebuffer)) if(!getFramebuffer(framebuffer))
...@@ -1150,6 +1157,11 @@ TextureCubeMap *Context::getTextureCubeMap() ...@@ -1150,6 +1157,11 @@ TextureCubeMap *Context::getTextureCubeMap()
return static_cast<TextureCubeMap*>(getSamplerTexture(mState.activeSampler, TEXTURE_CUBE)); return static_cast<TextureCubeMap*>(getSamplerTexture(mState.activeSampler, TEXTURE_CUBE));
} }
TextureExternal *Context::getTextureExternal()
{
return static_cast<TextureExternal*>(getSamplerTexture(mState.activeSampler, TEXTURE_EXTERNAL));
}
Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type)
{ {
GLuint texid = mState.samplerTexture[type][sampler].id(); GLuint texid = mState.samplerTexture[type][sampler].id();
...@@ -1158,9 +1170,10 @@ Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) ...@@ -1158,9 +1170,10 @@ Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type)
{ {
switch (type) switch (type)
{ {
default: UNREACHABLE(); case TEXTURE_2D: return mTexture2DZero.get();
case TEXTURE_2D: return mTexture2DZero.get(); case TEXTURE_CUBE: return mTextureCubeMapZero.get();
case TEXTURE_CUBE: return mTextureCubeMapZero.get(); case TEXTURE_EXTERNAL: return mTextureExternalZero.get();
default: UNREACHABLE();
} }
} }
...@@ -1457,6 +1470,17 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1457,6 +1470,17 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
*params = mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].id(); *params = mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].id();
} }
break; break;
case GL_TEXTURE_BINDING_EXTERNAL_OES:
{
if(mState.activeSampler < 0 || mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
{
error(GL_INVALID_OPERATION);
return false;
}
*params = mState.samplerTexture[TEXTURE_EXTERNAL][mState.activeSampler].id();
}
break;
default: default:
return false; return false;
} }
...@@ -1546,6 +1570,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu ...@@ -1546,6 +1570,7 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
case GL_IMPLEMENTATION_COLOR_READ_FORMAT: case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
case GL_TEXTURE_BINDING_2D: case GL_TEXTURE_BINDING_2D:
case GL_TEXTURE_BINDING_CUBE_MAP: case GL_TEXTURE_BINDING_CUBE_MAP:
case GL_TEXTURE_BINDING_EXTERNAL_OES:
{ {
*type = GL_INT; *type = GL_INT;
*numParams = 1; *numParams = 1;
...@@ -2065,7 +2090,7 @@ void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture ...@@ -2065,7 +2090,7 @@ void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture
{ {
int levelCount = baseTexture->getLevelCount(); int levelCount = baseTexture->getLevelCount();
if(baseTexture->isTexture2D()) if(baseTexture->getTarget() == GL_TEXTURE_2D || baseTexture->getTarget() == GL_TEXTURE_EXTERNAL_OES)
{ {
Texture2D *texture = static_cast<Texture2D*>(baseTexture); Texture2D *texture = static_cast<Texture2D*>(baseTexture);
...@@ -2086,7 +2111,7 @@ void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture ...@@ -2086,7 +2111,7 @@ void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture
device->setTextureLevel(sampler, 0, mipmapLevel, surface, sw::TEXTURE_2D); device->setTextureLevel(sampler, 0, mipmapLevel, surface, sw::TEXTURE_2D);
} }
} }
else if(baseTexture->isTextureCubeMap()) else if(baseTexture->getTarget() == GL_TEXTURE_CUBE_MAP)
{ {
for(int face = 0; face < 6; face++) for(int face = 0; face < 6; face++)
{ {
...@@ -2724,53 +2749,6 @@ void Context::setVertexAttrib(GLuint index, const GLfloat *values) ...@@ -2724,53 +2749,6 @@ void Context::setVertexAttrib(GLuint index, const GLfloat *values)
mVertexDataManager->dirtyCurrentValue(index); mVertexDataManager->dirtyCurrentValue(index);
} }
void Context::initExtensionString()
{
// Keep list sorted in following order:
// OES extensions
// EXT extensions
// Vendor extensions
mExtensionString += "GL_OES_depth_texture ";
mExtensionString += "GL_OES_depth_texture_cube_map ";
mExtensionString += "GL_OES_element_index_uint ";
mExtensionString += "GL_OES_packed_depth_stencil ";
mExtensionString += "GL_OES_rgb8_rgba8 ";
mExtensionString += "GL_OES_standard_derivatives ";
mExtensionString += "GL_OES_texture_float ";
mExtensionString += "GL_OES_texture_float_linear ";
mExtensionString += "GL_OES_texture_half_float ";
mExtensionString += "GL_OES_texture_half_float_linear ";
mExtensionString += "GL_OES_texture_npot ";
mExtensionString += "GL_EXT_blend_minmax ";
mExtensionString += "GL_EXT_occlusion_query_boolean ";
mExtensionString += "GL_EXT_read_format_bgra ";
if(S3TC_SUPPORT)
{
mExtensionString += "GL_EXT_texture_compression_dxt1 ";
mExtensionString += "GL_ANGLE_texture_compression_dxt3 ";
mExtensionString += "GL_ANGLE_texture_compression_dxt5 ";
}
mExtensionString += "GL_EXT_texture_filter_anisotropic ";
mExtensionString += "GL_EXT_texture_format_BGRA8888 ";
mExtensionString += "GL_ANGLE_framebuffer_blit ";
mExtensionString += "GL_ANGLE_framebuffer_multisample ";
mExtensionString += "GL_NV_fence ";
std::string::size_type end = mExtensionString.find_last_not_of(' ');
if(end != std::string::npos)
{
mExtensionString.resize(end + 1);
}
}
const char *Context::getExtensionString() const
{
return mExtensionString.c_str();
}
void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
GLbitfield mask) GLbitfield mask)
......
...@@ -48,6 +48,7 @@ class Program; ...@@ -48,6 +48,7 @@ class Program;
class Texture; class Texture;
class Texture2D; class Texture2D;
class TextureCubeMap; class TextureCubeMap;
class TextureExternal;
class Framebuffer; class Framebuffer;
class Renderbuffer; class Renderbuffer;
class RenderbufferStorage; class RenderbufferStorage;
...@@ -356,6 +357,7 @@ class Context ...@@ -356,6 +357,7 @@ class Context
void bindElementArrayBuffer(GLuint buffer); void bindElementArrayBuffer(GLuint buffer);
void bindTexture2D(GLuint texture); void bindTexture2D(GLuint texture);
void bindTextureCubeMap(GLuint texture); void bindTextureCubeMap(GLuint texture);
void bindTextureExternal(GLuint texture);
void bindReadFramebuffer(GLuint framebuffer); void bindReadFramebuffer(GLuint framebuffer);
void bindDrawFramebuffer(GLuint framebuffer); void bindDrawFramebuffer(GLuint framebuffer);
void bindRenderbuffer(GLuint renderbuffer); void bindRenderbuffer(GLuint renderbuffer);
...@@ -384,6 +386,7 @@ class Context ...@@ -384,6 +386,7 @@ class Context
Program *getCurrentProgram(); Program *getCurrentProgram();
Texture2D *getTexture2D(); Texture2D *getTexture2D();
TextureCubeMap *getTextureCubeMap(); TextureCubeMap *getTextureCubeMap();
TextureExternal *getTextureExternal();
Texture *getSamplerTexture(unsigned int sampler, TextureType type); Texture *getSamplerTexture(unsigned int sampler, TextureType type);
Framebuffer *getReadFramebuffer(); Framebuffer *getReadFramebuffer();
Framebuffer *getDrawFramebuffer(); Framebuffer *getDrawFramebuffer();
...@@ -410,7 +413,6 @@ class Context ...@@ -410,7 +413,6 @@ class Context
GLenum getError(); GLenum getError();
static int getSupportedMultiSampleDepth(sw::Format format, int requested); static int getSupportedMultiSampleDepth(sw::Format format, int requested);
const char *getExtensionString() const;
void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
...@@ -440,6 +442,7 @@ class Context ...@@ -440,6 +442,7 @@ class Context
BindingPointer<Texture2D> mTexture2DZero; BindingPointer<Texture2D> mTexture2DZero;
BindingPointer<TextureCubeMap> mTextureCubeMapZero; BindingPointer<TextureCubeMap> mTextureCubeMapZero;
BindingPointer<TextureExternal> mTextureExternalZero;
typedef std::map<GLint, Framebuffer*> FramebufferMap; typedef std::map<GLint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap; FramebufferMap mFramebufferMap;
...@@ -453,9 +456,6 @@ class Context ...@@ -453,9 +456,6 @@ class Context
QueryMap mQueryMap; QueryMap mQueryMap;
HandleAllocator mQueryHandleAllocator; HandleAllocator mQueryHandleAllocator;
void initExtensionString();
std::string mExtensionString;
VertexDataManager *mVertexDataManager; VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager; IndexDataManager *mIndexDataManager;
......
...@@ -590,7 +590,8 @@ namespace gl ...@@ -590,7 +590,8 @@ namespace gl
if(targetUniform->type == GL_INT || if(targetUniform->type == GL_INT ||
targetUniform->type == GL_SAMPLER_2D || targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE) targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES)
{ {
memcpy(targetUniform->data + uniformIndex[location].element * sizeof(GLint), memcpy(targetUniform->data + uniformIndex[location].element * sizeof(GLint),
v, sizeof(GLint) * count); v, sizeof(GLint) * count);
...@@ -923,6 +924,7 @@ namespace gl ...@@ -923,6 +924,7 @@ namespace gl
case GL_FLOAT_MAT4: applyUniformMatrix4fv(location, size, f); break; case GL_FLOAT_MAT4: applyUniformMatrix4fv(location, size, f); break;
case GL_SAMPLER_2D: case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
case GL_INT: applyUniform1iv(location, size, i); break; case GL_INT: applyUniform1iv(location, size, i); break;
case GL_INT_VEC2: applyUniform2iv(location, size, i); break; case GL_INT_VEC2: applyUniform2iv(location, size, i); break;
case GL_INT_VEC3: applyUniform3iv(location, size, i); break; case GL_INT_VEC3: applyUniform3iv(location, size, i); break;
...@@ -1313,7 +1315,7 @@ namespace gl ...@@ -1313,7 +1315,7 @@ namespace gl
bool Program::defineUniform(GLenum shader, GLenum type, GLenum precision, const std::string &name, unsigned int arraySize, int registerIndex) bool Program::defineUniform(GLenum shader, GLenum type, GLenum precision, const std::string &name, unsigned int arraySize, int registerIndex)
{ {
if(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE) if(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES)
{ {
int index = registerIndex; int index = registerIndex;
...@@ -1733,8 +1735,9 @@ namespace gl ...@@ -1733,8 +1735,9 @@ namespace gl
if(targetUniform->psRegisterIndex != -1) if(targetUniform->psRegisterIndex != -1)
{ {
if(targetUniform->type == GL_SAMPLER_2D || if(targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE) targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES)
{ {
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
...@@ -1756,7 +1759,8 @@ namespace gl ...@@ -1756,7 +1759,8 @@ namespace gl
if(targetUniform->vsRegisterIndex != -1) if(targetUniform->vsRegisterIndex != -1)
{ {
if(targetUniform->type == GL_SAMPLER_2D || if(targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE) targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES)
{ {
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
......
...@@ -34,6 +34,7 @@ enum TextureType ...@@ -34,6 +34,7 @@ enum TextureType
{ {
TEXTURE_2D, TEXTURE_2D,
TEXTURE_CUBE, TEXTURE_CUBE,
TEXTURE_EXTERNAL,
TEXTURE_TYPE_COUNT, TEXTURE_TYPE_COUNT,
TEXTURE_UNKNOWN TEXTURE_UNKNOWN
......
...@@ -48,27 +48,22 @@ sw::Resource *Texture::getResource() const ...@@ -48,27 +48,22 @@ sw::Resource *Texture::getResource() const
return resource; return resource;
} }
bool Texture::isTexture2D()
{
return false;
}
bool Texture::isTextureCubeMap()
{
return false;
}
// Returns true on successful filter state update (valid enum parameter) // Returns true on successful filter state update (valid enum parameter)
bool Texture::setMinFilter(GLenum filter) bool Texture::setMinFilter(GLenum filter)
{ {
switch(filter) switch(filter)
{ {
case GL_NEAREST:
case GL_LINEAR:
case GL_NEAREST_MIPMAP_NEAREST: case GL_NEAREST_MIPMAP_NEAREST:
case GL_LINEAR_MIPMAP_NEAREST: case GL_LINEAR_MIPMAP_NEAREST:
case GL_NEAREST_MIPMAP_LINEAR: case GL_NEAREST_MIPMAP_LINEAR:
case GL_LINEAR_MIPMAP_LINEAR: case GL_LINEAR_MIPMAP_LINEAR:
if(getTarget() == GL_TEXTURE_EXTERNAL_OES)
{
return false;
}
// Fall through
case GL_NEAREST:
case GL_LINEAR:
mMinFilter = filter; mMinFilter = filter;
return true; return true;
default: default:
...@@ -96,8 +91,13 @@ bool Texture::setWrapS(GLenum wrap) ...@@ -96,8 +91,13 @@ bool Texture::setWrapS(GLenum wrap)
switch(wrap) switch(wrap)
{ {
case GL_REPEAT: case GL_REPEAT:
case GL_CLAMP_TO_EDGE:
case GL_MIRRORED_REPEAT: case GL_MIRRORED_REPEAT:
if(getTarget() == GL_TEXTURE_EXTERNAL_OES)
{
return false;
}
// Fall through
case GL_CLAMP_TO_EDGE:
mWrapS = wrap; mWrapS = wrap;
return true; return true;
default: default:
...@@ -111,8 +111,13 @@ bool Texture::setWrapT(GLenum wrap) ...@@ -111,8 +111,13 @@ bool Texture::setWrapT(GLenum wrap)
switch(wrap) switch(wrap)
{ {
case GL_REPEAT: case GL_REPEAT:
case GL_CLAMP_TO_EDGE:
case GL_MIRRORED_REPEAT: case GL_MIRRORED_REPEAT:
if(getTarget() == GL_TEXTURE_EXTERNAL_OES)
{
return false;
}
// Fall through
case GL_CLAMP_TO_EDGE:
mWrapT = wrap; mWrapT = wrap;
return true; return true;
default: default:
...@@ -312,11 +317,6 @@ Texture2D::~Texture2D() ...@@ -312,11 +317,6 @@ Texture2D::~Texture2D()
mColorbufferProxy = NULL; mColorbufferProxy = NULL;
} }
bool Texture2D::isTexture2D()
{
return true;
}
// We need to maintain a count of references to renderbuffers acting as // We need to maintain a count of references to renderbuffers acting as
// proxies for this texture, so that we do not attempt to use a pointer // proxies for this texture, so that we do not attempt to use a pointer
// to a renderbuffer proxy which has been deleted. // to a renderbuffer proxy which has been deleted.
...@@ -730,11 +730,6 @@ TextureCubeMap::~TextureCubeMap() ...@@ -730,11 +730,6 @@ TextureCubeMap::~TextureCubeMap()
} }
} }
bool TextureCubeMap::isTextureCubeMap()
{
return true;
}
// We need to maintain a count of references to renderbuffers acting as // We need to maintain a count of references to renderbuffers acting as
// proxies for this texture, so that the texture is not deleted while // proxies for this texture, so that the texture is not deleted while
// proxy references still exist. If the reference count drops to zero, // proxy references still exist. If the reference count drops to zero,
...@@ -1127,6 +1122,34 @@ bool TextureCubeMap::isShared(GLenum target, unsigned int level) const ...@@ -1127,6 +1122,34 @@ bool TextureCubeMap::isShared(GLenum target, unsigned int level) const
return image[face][level]->isShared(); return image[face][level]->isShared();
} }
TextureExternal::TextureExternal(GLuint id) : Texture2D(id)
{
mMinFilter = GL_LINEAR;
mMagFilter = GL_LINEAR;
mWrapS = GL_CLAMP_TO_EDGE;
mWrapT = GL_CLAMP_TO_EDGE;
}
TextureExternal::~TextureExternal()
{
}
GLenum TextureExternal::getTarget() const
{
return GL_TEXTURE_EXTERNAL_OES;
}
void TextureExternal::setImage(Image *sharedImage)
{
if(image[0])
{
image[0]->release();
}
sharedImage->addRef();
image[0] = sharedImage;
}
} }
// Exported functions for use by EGL // Exported functions for use by EGL
......
...@@ -53,8 +53,6 @@ public: ...@@ -53,8 +53,6 @@ public:
virtual ~Texture(); virtual ~Texture();
sw::Resource *getResource() const; sw::Resource *getResource() const;
virtual bool isTexture2D();
virtual bool isTextureCubeMap();
virtual void addProxyRef(const Renderbuffer *proxy) = 0; virtual void addProxyRef(const Renderbuffer *proxy) = 0;
virtual void releaseProxy(const Renderbuffer *proxy) = 0; virtual void releaseProxy(const Renderbuffer *proxy) = 0;
...@@ -118,8 +116,6 @@ public: ...@@ -118,8 +116,6 @@ public:
virtual ~Texture2D(); virtual ~Texture2D();
virtual bool isTexture2D();
void addProxyRef(const Renderbuffer *proxy); void addProxyRef(const Renderbuffer *proxy);
void releaseProxy(const Renderbuffer *proxy); void releaseProxy(const Renderbuffer *proxy);
...@@ -153,7 +149,7 @@ public: ...@@ -153,7 +149,7 @@ public:
Image *getImage(unsigned int level); Image *getImage(unsigned int level);
private: protected:
bool isMipmapComplete() const; bool isMipmapComplete() const;
Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS]; Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
...@@ -176,8 +172,6 @@ public: ...@@ -176,8 +172,6 @@ public:
virtual ~TextureCubeMap(); virtual ~TextureCubeMap();
virtual bool isTextureCubeMap();
void addProxyRef(const Renderbuffer *proxy); void addProxyRef(const Renderbuffer *proxy);
void releaseProxy(const Renderbuffer *proxy); void releaseProxy(const Renderbuffer *proxy);
...@@ -227,6 +221,18 @@ private: ...@@ -227,6 +221,18 @@ private:
Renderbuffer *mFaceProxies[6]; Renderbuffer *mFaceProxies[6];
unsigned int mFaceProxyRefs[6]; unsigned int mFaceProxyRefs[6];
}; };
class TextureExternal : public Texture2D
{
public:
explicit TextureExternal(GLuint id);
virtual ~TextureExternal();
virtual GLenum getTarget() const;
void setImage(Image *image);
};
} }
#endif // LIBGLESV2_TEXTURE_H_ #endif // LIBGLESV2_TEXTURE_H_
...@@ -31,6 +31,7 @@ namespace gl ...@@ -31,6 +31,7 @@ namespace gl
case GL_INT: case GL_INT:
case GL_SAMPLER_2D: case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
return 1; return 1;
case GL_BOOL_VEC2: case GL_BOOL_VEC2:
case GL_FLOAT_VEC2: case GL_FLOAT_VEC2:
...@@ -76,6 +77,7 @@ namespace gl ...@@ -76,6 +77,7 @@ namespace gl
case GL_INT: case GL_INT:
case GL_SAMPLER_2D: case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
case GL_INT_VEC2: case GL_INT_VEC2:
case GL_INT_VEC3: case GL_INT_VEC3:
case GL_INT_VEC4: case GL_INT_VEC4:
...@@ -119,6 +121,7 @@ namespace gl ...@@ -119,6 +121,7 @@ namespace gl
case GL_INT_VEC4: case GL_INT_VEC4:
case GL_SAMPLER_2D: case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
return 1; return 1;
case GL_FLOAT_MAT2: case GL_FLOAT_MAT2:
return 2; return 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment