GL: Added support for texture array.

This commit is contained in:
Branimir Karadžić 2016-08-21 14:03:16 -07:00
parent 9527c756da
commit 7537b705e5
17 changed files with 636 additions and 348 deletions

View File

@ -139,7 +139,7 @@ struct BgfxCallback : public bgfx::CallbackI
virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) BX_OVERRIDE
{
dbgPrintf("%s (%d): ", _filePath, _line);
dbgPrintfVargs(_format, _argList);
dbgPrintf(_format, _argList);
}
virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE

View File

@ -109,7 +109,7 @@ static void updateTextureCubeRectBgra8(bgfx::TextureHandle _handle, uint8_t _sid
data += 4;
}
bgfx::updateTextureCube(_handle, _side, 0, _x, _y, _width, _height, mem);
bgfx::updateTextureCube(_handle, 0, _side, 0, _x, _y, _width, _height, mem);
}
static const uint32_t m_textureside = 512;
@ -409,7 +409,7 @@ public:
// Pitch here makes possible to pass data from source to destination
// without need for m_textures and allocated memory to be the same size.
bgfx::updateTexture2D(m_texture2d, 0, tx, ty, tw, th, mem, pitch);
bgfx::updateTexture2D(m_texture2d, 0, 0, tx, ty, tw, th, mem, pitch);
}
}

View File

@ -278,7 +278,7 @@ class ExampleTerrain : public entry::AppI
}
mem = bgfx::makeRef(&m_terrain.m_heightMap[0], sizeof(uint8_t) * s_terrainSize * s_terrainSize);
bgfx::updateTexture2D(m_heightTexture, 0, 0, 0, s_terrainSize, s_terrainSize, mem);
bgfx::updateTexture2D(m_heightTexture, 0, 0, 0, 0, s_terrainSize, s_terrainSize, mem);
break;
}
}

View File

@ -443,7 +443,7 @@ void Atlas::updateRegion(const AtlasRegion& _region, const uint8_t* _bitmapBuffe
}
}
bgfx::updateTextureCube(m_textureHandle, (uint8_t)_region.getFaceIndex(), 0, _region.x, _region.y, _region.width, _region.height, mem);
bgfx::updateTextureCube(m_textureHandle, 0, (uint8_t)_region.getFaceIndex(), 0, _region.x, _region.y, _region.width, _region.height, mem);
}
}

View File

@ -337,7 +337,9 @@ namespace
if (NULL != mem)
{
bgfx::updateTexture2D(tex->id
bgfx::updateTexture2D(
tex->id
, 0
, 0
, 0
, 0
@ -368,7 +370,9 @@ namespace
uint32_t bytesPerPixel = NVG_TEXTURE_RGBA == tex->type ? 4 : 1;
uint32_t pitch = tex->width * bytesPerPixel;
bgfx::updateTexture2D(tex->id
bgfx::updateTexture2D(
tex->id
, 0
, 0
, x
, y

View File

@ -1686,6 +1686,7 @@ namespace bgfx
/// Update 2D texture.
///
/// @param[in] _handle Texture handle.
/// @param[in] _layer Layers in texture array.
/// @param[in] _mip Mip level.
/// @param[in] _x X offset in texture.
/// @param[in] _y Y offset in texture.
@ -1699,6 +1700,7 @@ namespace bgfx
///
void updateTexture2D(
TextureHandle _handle
, uint16_t _layer
, uint8_t _mip
, uint16_t _x
, uint16_t _y
@ -1737,6 +1739,7 @@ namespace bgfx
/// Update Cube texture.
///
/// @param[in] _handle Texture handle.
/// @param[in] _layer Layers in texture array.
/// @param[in] _side Cubemap side `BGFX_CUBE_MAP_<POSITIVE or NEGATIVE>_<X, Y or Z>`,
/// where 0 is +X, 1 is -X, 2 is +Y, 3 is -Y, 4 is +Z, and 5 is -Z.
///
@ -1770,6 +1773,7 @@ namespace bgfx
///
void updateTextureCube(
TextureHandle _handle
, uint16_t _layer
, uint8_t _side
, uint8_t _mip
, uint16_t _x

View File

@ -6,7 +6,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(18)
#define BGFX_API_VERSION UINT32_C(19)
///
#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write.

View File

@ -674,13 +674,13 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_
BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
/**/
BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
/**/
BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);
/**/
BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
/**/
BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data);

View File

@ -98,6 +98,7 @@ typedef struct bgfx_interface_vtbl
void (*set_debug)(uint32_t _debug);
void (*dbg_text_clear)(uint8_t _attr, bool _small);
void (*dbg_text_printf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...);
void (*dbg_text_vprintf)(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList);
void (*dbg_text_image)(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch);
bgfx_index_buffer_handle_t (*create_index_buffer)(const bgfx_memory_t* _mem, uint16_t _flags);
void (*destroy_index_buffer)(bgfx_index_buffer_handle_t _handle);
@ -133,9 +134,9 @@ typedef struct bgfx_interface_vtbl
bgfx_texture_handle_t (*create_texture_2d_scaled)(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags);
bgfx_texture_handle_t (*create_texture_3d)(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
bgfx_texture_handle_t (*create_texture_cube)(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem);
void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*update_texture_2d)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*update_texture_3d)(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem);
void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*update_texture_cube)(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch);
void (*destroy_texture)(bgfx_texture_handle_t _handle);
bgfx_frame_buffer_handle_t (*create_frame_buffer)(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags);
bgfx_frame_buffer_handle_t (*create_frame_buffer_scaled)(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags);

View File

@ -1101,6 +1101,8 @@ namespace bgfx
CAPS_FLAGS(BGFX_CAPS_OCCLUSION_QUERY),
CAPS_FLAGS(BGFX_CAPS_ALPHA_TO_COVERAGE),
CAPS_FLAGS(BGFX_CAPS_CONSERVATIVE_RASTER),
CAPS_FLAGS(BGFX_CAPS_TEXTURE_2D_ARRAY),
CAPS_FLAGS(BGFX_CAPS_TEXTURE_CUBE_ARRAY),
#undef CAPS_FLAGS
};
@ -2977,7 +2979,7 @@ error:
tc.m_width = _width;
tc.m_height = _height;
tc.m_depth = 0;
tc.m_numLayers = 1;
tc.m_numLayers = _numLayers;
tc.m_numMips = numMips;
tc.m_format = _format;
tc.m_cubeMap = false;
@ -3076,7 +3078,7 @@ error:
tc.m_width = _size;
tc.m_height = _size;
tc.m_depth = 0;
tc.m_numLayers = 1;
tc.m_numLayers = _numLayers;
tc.m_numMips = numMips;
tc.m_format = _format;
tc.m_cubeMap = true;
@ -3092,7 +3094,7 @@ error:
s_ctx->destroyTexture(_handle);
}
void updateTexture2D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch)
void updateTexture2D(TextureHandle _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch)
{
BGFX_CHECK_MAIN_THREAD();
BX_CHECK(NULL != _mem, "_mem can't be NULL");
@ -3103,7 +3105,7 @@ error:
}
else
{
s_ctx->updateTexture(_handle, 0, _mip, _x, _y, 0, _width, _height, 1, _pitch, _mem);
s_ctx->updateTexture(_handle, 0, _mip, _x, _y, _layer, _width, _height, 1, _pitch, _mem);
}
}
@ -3125,7 +3127,7 @@ error:
}
}
void updateTextureCube(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch)
void updateTextureCube(TextureHandle _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch)
{
BGFX_CHECK_MAIN_THREAD();
BX_CHECK(NULL != _mem, "_mem can't be NULL");
@ -3137,7 +3139,7 @@ error:
}
else
{
s_ctx->updateTexture(_handle, _side, _mip, _x, _y, 0, _width, _height, 1, _pitch, _mem);
s_ctx->updateTexture(_handle, _side, _mip, _x, _y, _layer, _width, _height, 1, _pitch, _mem);
}
}
@ -4186,10 +4188,10 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _
return handle.c;
}
BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch)
BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch)
{
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
bgfx::updateTexture2D(handle.cpp, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch);
bgfx::updateTexture2D(handle.cpp, _layer, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch);
}
BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem)
@ -4198,10 +4200,10 @@ BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _m
bgfx::updateTexture3D(handle.cpp, _mip, _x, _y, _z, _width, _height, _depth, (const bgfx::Memory*)_mem);
}
BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch)
BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch)
{
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
bgfx::updateTextureCube(handle.cpp, _side, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch);
bgfx::updateTextureCube(handle.cpp, _layer, _side, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch);
}
BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data)
@ -4650,6 +4652,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
BGFX_IMPORT_FUNC(set_debug) \
BGFX_IMPORT_FUNC(dbg_text_clear) \
BGFX_IMPORT_FUNC(dbg_text_printf) \
BGFX_IMPORT_FUNC(dbg_text_vprintf) \
BGFX_IMPORT_FUNC(dbg_text_image) \
BGFX_IMPORT_FUNC(create_index_buffer) \
BGFX_IMPORT_FUNC(destroy_index_buffer) \

View File

@ -3215,7 +3215,19 @@ namespace bgfx
}
}
BGFX_API_FUNC(void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, uint16_t _pitch, const Memory* _mem) )
BGFX_API_FUNC(void updateTexture(
TextureHandle _handle
, uint8_t _side
, uint8_t _mip
, uint16_t _x
, uint16_t _y
, uint16_t _z
, uint16_t _width
, uint16_t _height
, uint16_t _depth
, uint16_t _pitch
, const Memory* _mem
) )
{
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::UpdateTexture);
cmdbuf.write(_handle);

View File

@ -386,44 +386,20 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name
# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name
# define SAMPLER2DARRAY(_name, _reg) uniform sampler2DArray _name
# define SAMPLER2DMSARRAY(_name, _reg) uniform sampler2DMSArray _name
# define SAMPLERCUBEARRAY(_name, _reg) uniform samplerCubeArray _name
# define SAMPLER2DARRAYSHADOW(_name, _reg) uniform sampler2DArrayShadow _name
# if BGFX_SHADER_LANGUAGE_GLSL >= 130
# define ISAMPLER2D(_name, _reg) uniform isampler2D _name
# define USAMPLER2D(_name, _reg) uniform usampler2D _name
# define ISAMPLER3D(_name, _reg) uniform isampler3D _name
# define USAMPLER3D(_name, _reg) uniform usampler3D _name
vec4 bgfxTexture2D(sampler2D _sampler, vec2 _coord)
{
return texture(_sampler, _coord);
}
ivec4 bgfxTexture2D(isampler2D _sampler, vec2 _coord)
{
return texture(_sampler, _coord);
}
uvec4 bgfxTexture2D(usampler2D _sampler, vec2 _coord)
{
return texture(_sampler, _coord);
}
vec4 bgfxTexture3D(sampler3D _sampler, vec3 _coord)
{
return texture(_sampler, _coord);
}
ivec4 bgfxTexture3D(isampler3D _sampler, vec3 _coord)
{
return texture(_sampler, _coord);
}
uvec4 bgfxTexture3D(usampler3D _sampler, vec3 _coord)
{
return texture(_sampler, _coord);
}
# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord)
# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord)
# define texture2D(_sampler, _coord) texture(_sampler, _coord)
# define texture2DArray(_sampler, _coord) texture(_sampler, _coord)
# define texture3D(_sampler, _coord) texture(_sampler, _coord)
# endif // BGFX_SHADER_LANGUAGE_GLSL >= 130
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); }

View File

@ -2516,6 +2516,7 @@ namespace bgfx
_imageContainer.m_width = _width;
_imageContainer.m_height = _height;
_imageContainer.m_depth = _depth;
_imageContainer.m_numLayers = 1;
_imageContainer.m_numMips = numMips;
_imageContainer.m_hasAlpha = false;
_imageContainer.m_cubeMap = _cubeMap;
@ -2879,6 +2880,7 @@ namespace bgfx
_imageContainer.m_height = height;
_imageContainer.m_depth = depth;
_imageContainer.m_format = format;
_imageContainer.m_numLayers = 1;
_imageContainer.m_numMips = uint8_t( (caps[0] & DDSCAPS_MIPMAP) ? mips : 1);
_imageContainer.m_hasAlpha = hasAlpha;
_imageContainer.m_cubeMap = cubeMap;
@ -3185,6 +3187,7 @@ namespace bgfx
_imageContainer.m_height = height;
_imageContainer.m_depth = depth;
_imageContainer.m_format = format;
_imageContainer.m_numLayers = 1;
_imageContainer.m_numMips = uint8_t(bx::uint32_max(numMips, 1) );
_imageContainer.m_hasAlpha = hasAlpha;
_imageContainer.m_cubeMap = numFaces > 1;
@ -3334,6 +3337,7 @@ namespace bgfx
_imageContainer.m_height = height;
_imageContainer.m_depth = depth;
_imageContainer.m_format = format;
_imageContainer.m_numLayers = 1;
_imageContainer.m_numMips = uint8_t(bx::uint32_max(numMips, 1) );
_imageContainer.m_hasAlpha = hasAlpha;
_imageContainer.m_cubeMap = numFaces > 1;
@ -3381,6 +3385,7 @@ namespace bgfx
_imageContainer.m_width = tc.m_width;
_imageContainer.m_height = tc.m_height;
_imageContainer.m_depth = tc.m_depth;
_imageContainer.m_numLayers = tc.m_numLayers;
_imageContainer.m_numMips = tc.m_numMips;
_imageContainer.m_hasAlpha = false;
_imageContainer.m_cubeMap = tc.m_cubeMap;

View File

@ -19,6 +19,7 @@ namespace bgfx
uint32_t m_width;
uint32_t m_height;
uint32_t m_depth;
uint16_t m_numLayers;
uint8_t m_numMips;
bool m_hasAlpha;
bool m_cubeMap;

View File

@ -500,6 +500,7 @@ namespace bgfx { namespace gl
ARB_shader_texture_lod,
ARB_texture_compression_bptc,
ARB_texture_compression_rgtc,
ARB_texture_cube_map_array,
ARB_texture_float,
ARB_texture_multisample,
ARB_texture_rg,
@ -555,6 +556,7 @@ namespace bgfx { namespace gl
EXT_texture_compression_latc,
EXT_texture_compression_rgtc,
EXT_texture_compression_s3tc,
EXT_texture_cube_map_array,
EXT_texture_filter_anisotropic,
EXT_texture_format_BGRA8888,
EXT_texture_rg,
@ -614,6 +616,7 @@ namespace bgfx { namespace gl
OES_texture_half_float,
OES_texture_half_float_linear,
OES_texture_stencil8,
OES_texture_storage_multisample_2d_array,
OES_vertex_array_object,
OES_vertex_half_float,
OES_vertex_type_10_10_10_2,
@ -710,6 +713,7 @@ namespace bgfx { namespace gl
{ "ARB_shader_texture_lod", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "ARB_texture_compression_bptc", BGFX_CONFIG_RENDERER_OPENGL >= 44, true },
{ "ARB_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "ARB_texture_cube_map_array", BGFX_CONFIG_RENDERER_OPENGL >= 40, true },
{ "ARB_texture_float", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "ARB_texture_multisample", BGFX_CONFIG_RENDERER_OPENGL >= 32, true },
{ "ARB_texture_rg", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
@ -765,6 +769,7 @@ namespace bgfx { namespace gl
{ "EXT_texture_compression_latc", false, true },
{ "EXT_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true },
{ "EXT_texture_compression_s3tc", false, true },
{ "EXT_texture_cube_map_array", false, true }, // GLES3.1 extension.
{ "EXT_texture_filter_anisotropic", false, true },
{ "EXT_texture_format_BGRA8888", false, true },
{ "EXT_texture_rg", false, true }, // GLES2 extension.
@ -824,6 +829,7 @@ namespace bgfx { namespace gl
{ "OES_texture_half_float", false, true },
{ "OES_texture_half_float_linear", false, true },
{ "OES_texture_stencil8", false, true },
{ "OES_texture_storage_multisample_2d_array", false, true },
{ "OES_vertex_array_object", false, !BX_PLATFORM_IOS },
{ "OES_vertex_half_float", false, true },
{ "OES_vertex_type_10_10_10_2", false, true },
@ -910,6 +916,15 @@ namespace bgfx { namespace gl
NULL
};
static const char* s_textureArray[] =
{
"sampler2DArray",
"sampler2DMSArray",
"samplerCubeArray",
"sampler2DArrayShadow",
NULL
};
static const char* s_ARB_texture_multisample[] =
{
"sampler2DMS",
@ -1863,6 +1878,21 @@ namespace bgfx { namespace gl
: 0
;
g_caps.supported |= false
|| s_extension[Extension::EXT_texture_array].m_supported
|| s_extension[Extension::EXT_gpu_shader4].m_supported
|| !!(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
? BGFX_CAPS_TEXTURE_2D_ARRAY
: 0
;
g_caps.supported |= false
|| s_extension[Extension::ARB_texture_cube_map_array].m_supported
|| s_extension[Extension::EXT_texture_cube_map_array].m_supported
? BGFX_CAPS_TEXTURE_CUBE_ARRAY
: 0
;
g_caps.maxTextureSize = uint16_t(glGet(GL_MAX_TEXTURE_SIZE) );
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
@ -3621,8 +3651,19 @@ namespace bgfx { namespace gl
GLSL_TYPE(GL_FLOAT_MAT4);
GLSL_TYPE(GL_SAMPLER_2D);
GLSL_TYPE(GL_SAMPLER_2D_ARRAY);
GLSL_TYPE(GL_SAMPLER_2D_MULTISAMPLE);
GLSL_TYPE(GL_INT_SAMPLER_2D);
GLSL_TYPE(GL_INT_SAMPLER_2D_ARRAY);
GLSL_TYPE(GL_INT_SAMPLER_2D_MULTISAMPLE);
GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D);
GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY);
GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE);
GLSL_TYPE(GL_SAMPLER_2D_SHADOW);
GLSL_TYPE(GL_SAMPLER_2D_ARRAY_SHADOW);
GLSL_TYPE(GL_SAMPLER_3D);
GLSL_TYPE(GL_INT_SAMPLER_3D);
@ -3632,12 +3673,6 @@ namespace bgfx { namespace gl
GLSL_TYPE(GL_INT_SAMPLER_CUBE);
GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_CUBE);
GLSL_TYPE(GL_SAMPLER_2D_MULTISAMPLE);
GLSL_TYPE(GL_INT_SAMPLER_2D_MULTISAMPLE);
GLSL_TYPE(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE);
GLSL_TYPE(GL_SAMPLER_2D_SHADOW);
GLSL_TYPE(GL_IMAGE_1D);
GLSL_TYPE(GL_INT_IMAGE_1D);
GLSL_TYPE(GL_UNSIGNED_INT_IMAGE_1D);
@ -3713,8 +3748,19 @@ namespace bgfx { namespace gl
return UniformType::Mat4;
case GL_SAMPLER_2D:
case GL_SAMPLER_2D_ARRAY:
case GL_SAMPLER_2D_MULTISAMPLE:
case GL_INT_SAMPLER_2D:
case GL_INT_SAMPLER_2D_ARRAY:
case GL_INT_SAMPLER_2D_MULTISAMPLE:
case GL_UNSIGNED_INT_SAMPLER_2D:
case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_2D_ARRAY_SHADOW:
case GL_SAMPLER_3D:
case GL_INT_SAMPLER_3D:
@ -3724,12 +3770,6 @@ namespace bgfx { namespace gl
case GL_INT_SAMPLER_CUBE:
case GL_UNSIGNED_INT_SAMPLER_CUBE:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_2D_MULTISAMPLE:
case GL_INT_SAMPLER_2D_MULTISAMPLE:
case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
case GL_IMAGE_1D:
case GL_INT_IMAGE_1D:
case GL_UNSIGNED_INT_IMAGE_1D:
@ -3968,8 +4008,19 @@ namespace bgfx { namespace gl
switch (gltype)
{
case GL_SAMPLER_2D:
case GL_SAMPLER_2D_ARRAY:
case GL_SAMPLER_2D_MULTISAMPLE:
case GL_INT_SAMPLER_2D:
case GL_INT_SAMPLER_2D_ARRAY:
case GL_INT_SAMPLER_2D_MULTISAMPLE:
case GL_UNSIGNED_INT_SAMPLER_2D:
case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_2D_ARRAY_SHADOW:
case GL_SAMPLER_3D:
case GL_INT_SAMPLER_3D:
@ -3979,8 +4030,6 @@ namespace bgfx { namespace gl
case GL_INT_SAMPLER_CUBE:
case GL_UNSIGNED_INT_SAMPLER_CUBE:
case GL_SAMPLER_2D_SHADOW:
case GL_IMAGE_1D:
case GL_INT_IMAGE_1D:
case GL_UNSIGNED_INT_IMAGE_1D:
@ -4211,60 +4260,214 @@ namespace bgfx { namespace gl
m_vcref.invalidate(s_renderGL->m_vaoStateCache);
}
static void texImage(GLenum _target, uint32_t _msaaQuality, GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLsizei _depth, GLint _border, GLenum _format, GLenum _type, const GLvoid* _data)
static void texImage(
GLenum _target
, uint32_t _msaaQuality
, GLint _level
, GLint _internalFormat
, GLsizei _width
, GLsizei _height
, GLsizei _depth
, GLint _border
, GLenum _format
, GLenum _type
, const GLvoid* _data
)
{
if (_target == GL_TEXTURE_3D)
if (_target == GL_TEXTURE_3D
|| _target == GL_TEXTURE_2D_ARRAY
|| _target == GL_TEXTURE_CUBE_MAP_ARRAY)
{
GL_CHECK(glTexImage3D(
_target
, _level
, _internalFormat
, _width
, _height
, _depth
, _border
, _format
, _type
, _data
) );
}
else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
{
GL_CHECK(glTexImage3D(_target, _level, _internalFormat, _width, _height, _depth, _border, _format, _type, _data) );
}
else if (_target == GL_TEXTURE_2D_MULTISAMPLE)
{
GL_CHECK(glTexImage2DMultisample(_target, _msaaQuality, _internalFormat, _width, _height, false) );
GL_CHECK(glTexImage2DMultisample(
_target
, _msaaQuality
, _internalFormat
, _width
, _height
, false
) );
}
else
{
GL_CHECK(glTexImage2D(_target, _level, _internalFormat, _width, _height, _border, _format, _type, _data) );
GL_CHECK(glTexImage2D(
_target
, _level
, _internalFormat
, _width
, _height
, _border
, _format
, _type
, _data
) );
}
BX_UNUSED(_msaaQuality, _depth, _border, _data);
}
static void texSubImage(GLenum _target, GLint _level, GLint _xoffset, GLint _yoffset, GLint _zoffset, GLsizei _width, GLsizei _height, GLsizei _depth, GLenum _format, GLenum _type, const GLvoid* _data)
static void texSubImage(
GLenum _target
, GLint _level
, GLint _xoffset
, GLint _yoffset
, GLint _zoffset
, GLsizei _width
, GLsizei _height
, GLsizei _depth
, GLenum _format
, GLenum _type
, const GLvoid* _data
)
{
if (_target == GL_TEXTURE_3D)
if (_target == GL_TEXTURE_3D
|| _target == GL_TEXTURE_2D_ARRAY
|| _target == GL_TEXTURE_CUBE_MAP_ARRAY)
{
BX_TRACE("zoffset %d, depth %d", _zoffset, _depth);
GL_CHECK(glTexSubImage3D(
_target
, _level
, _xoffset
, _yoffset
, _zoffset
, _width
, _height
, _depth
, _format
, _type
, _data
) );
}
else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
{
GL_CHECK(glTexSubImage3D(_target, _level, _xoffset, _yoffset, _zoffset, _width, _height, _depth, _format, _type, _data) );
}
else
{
BX_UNUSED(_zoffset, _depth);
GL_CHECK(glTexSubImage2D(_target, _level, _xoffset, _yoffset, _width, _height, _format, _type, _data) );
GL_CHECK(glTexSubImage2D(
_target
, _level
, _xoffset
, _yoffset
, _width
, _height
, _format
, _type
, _data
) );
}
}
static void compressedTexImage(GLenum _target, GLint _level, GLenum _internalformat, GLsizei _width, GLsizei _height, GLsizei _depth, GLint _border, GLsizei _imageSize, const GLvoid* _data)
static void compressedTexImage(
GLenum _target
, GLint _level
, GLenum _internalformat
, GLsizei _width
, GLsizei _height
, GLsizei _depth
, GLint _border
, GLsizei _imageSize
, const GLvoid* _data
)
{
if (_target == GL_TEXTURE_3D)
if (_target == GL_TEXTURE_3D
|| _target == GL_TEXTURE_2D_ARRAY
|| _target == GL_TEXTURE_CUBE_MAP_ARRAY)
{
GL_CHECK(glCompressedTexImage3D(
_target
, _level
, _internalformat
, _width
, _height
, _depth
, _border
, _imageSize
, _data
) );
}
else if (_target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
{
GL_CHECK(glCompressedTexImage3D(_target, _level, _internalformat, _width, _height, _depth, _border, _imageSize, _data) );
}
else
{
BX_UNUSED(_depth);
GL_CHECK(glCompressedTexImage2D(_target, _level, _internalformat, _width, _height, _border, _imageSize, _data) );
GL_CHECK(glCompressedTexImage2D(
_target
, _level
, _internalformat
, _width
, _height
, _border
, _imageSize
, _data
) );
}
}
static void compressedTexSubImage(GLenum _target, GLint _level, GLint _xoffset, GLint _yoffset, GLint _zoffset, GLsizei _width, GLsizei _height, GLsizei _depth, GLenum _format, GLsizei _imageSize, const GLvoid* _data)
static void compressedTexSubImage(
GLenum _target
, GLint _level
, GLint _xoffset
, GLint _yoffset
, GLint _zoffset
, GLsizei _width
, GLsizei _height
, GLsizei _depth
, GLenum _format
, GLsizei _imageSize
, const GLvoid* _data
)
{
if (_target == GL_TEXTURE_3D)
{
GL_CHECK(glCompressedTexSubImage3D(_target, _level, _xoffset, _yoffset, _zoffset, _width, _height, _depth, _format, _imageSize, _data) );
GL_CHECK(glCompressedTexSubImage3D(
_target
, _level
, _xoffset
, _yoffset
, _zoffset
, _width
, _height
, _depth
, _format
, _imageSize
, _data
) );
}
else
{
BX_UNUSED(_zoffset, _depth);
GL_CHECK(glCompressedTexSubImage2D(_target, _level, _xoffset, _yoffset, _width, _height, _format, _imageSize, _data) );
GL_CHECK(glCompressedTexSubImage2D(
_target
, _level
, _xoffset
, _yoffset
, _width
, _height
, _format
, _imageSize
, _data
) );
}
}
@ -4408,7 +4611,10 @@ namespace bgfx { namespace gl
const ImageBlockInfo& ibi = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) );
textureWidth = bx::uint32_max(ibi.blockWidth, imageContainer.m_width >>startLod);
textureHeight = bx::uint32_max(ibi.blockHeight, imageContainer.m_height>>startLod);
textureDepth = imageContainer.m_depth;
textureDepth = 1 < imageContainer.m_depth
? imageContainer.m_depth
: imageContainer.m_numLayers
;
}
m_requestedFormat = uint8_t(imageContainer.m_format);
@ -4431,6 +4637,16 @@ namespace bgfx { namespace gl
target = GL_TEXTURE_3D;
}
if (1 < imageContainer.m_numLayers)
{
switch (target)
{
case GL_TEXTURE_CUBE_MAP: target = GL_TEXTURE_CUBE_MAP_ARRAY;
case GL_TEXTURE_2D_MULTISAMPLE: target = GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
default: target = GL_TEXTURE_2D_ARRAY;
}
}
if (!init(target
, textureWidth
, textureHeight
@ -4442,7 +4658,10 @@ namespace bgfx { namespace gl
return;
}
target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target;
target = isCubeMap()
? GL_TEXTURE_CUBE_MAP_POSITIVE_X
: m_target
;
const GLenum internalFmt = srgb
? s_textureFormat[m_textureFormat].m_internalFmtSrgb
@ -4460,11 +4679,12 @@ namespace bgfx { namespace gl
|| swizzle
;
BX_TRACE("Texture%-4s %3d: %s (requested: %s), %dx%dx%d%s."
BX_TRACE("Texture%-4s %3d: %s (requested: %s), layers %d, %dx%dx%d%s."
, imageContainer.m_cubeMap ? "Cube" : (1 < imageContainer.m_depth ? "3D" : "2D")
, this - s_renderGL->m_textures
, getName( (TextureFormat::Enum)m_textureFormat)
, getName( (TextureFormat::Enum)m_requestedFormat)
, imageContainer.m_numLayers
, textureWidth
, textureHeight
, imageContainer.m_cubeMap ? 6 : (1 < imageContainer.m_depth ? imageContainer.m_depth : 0)
@ -4495,7 +4715,10 @@ namespace bgfx { namespace gl
{
width = bx::uint32_max(1, width);
height = bx::uint32_max(1, height);
depth = bx::uint32_max(1, depth);
depth = 1 < imageContainer.m_depth
? bx::uint32_max(1, depth)
: imageContainer.m_numLayers
;
ImageMip mip;
if (imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) )
@ -4622,8 +4845,6 @@ namespace bgfx { namespace gl
void TextureGL::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem)
{
BX_UNUSED(_z, _depth);
const uint32_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) );
const uint32_t rectpitch = _rect.m_width*bpp/8;
uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch;
@ -4631,7 +4852,10 @@ namespace bgfx { namespace gl
GL_CHECK(glBindTexture(m_target, m_id) );
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) );
GLenum target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target;
GLenum target = isCubeMap()
? GL_TEXTURE_CUBE_MAP_POSITIVE_X
: m_target
;
const bool swizzle = true
&& TextureFormat::BGRA8 == m_requestedFormat
@ -5135,6 +5359,7 @@ namespace bgfx { namespace gl
const bool usesGpuShader5 = !!bx::findIdentifierMatch(code, s_ARB_gpu_shader5);
const bool usesIUsamplers = !!bx::findIdentifierMatch(code, s_uisamplers);
const bool usesTexelFetch = !!bx::findIdentifierMatch(code, s_texelFetch);
const bool usesTextureArray = !!bx::findIdentifierMatch(code, s_textureArray);
const bool usesTextureMS = !!bx::findIdentifierMatch(code, s_ARB_texture_multisample);
const bool usesPacking = !!bx::findIdentifierMatch(code, s_ARB_shading_language_packing);
@ -5172,6 +5397,11 @@ namespace bgfx { namespace gl
writeString(&writer, "#extension GL_ARB_texture_multisample : enable\n");
}
if (usesTextureArray)
{
writeString(&writer, "#extension GL_EXT_texture_array : enable\n");
}
if (130 <= version)
{
if (m_type == GL_FRAGMENT_SHADER)
@ -5460,7 +5690,7 @@ namespace bgfx { namespace gl
}
else
{
GLenum target = GL_TEXTURE_CUBE_MAP == texture.m_target
GLenum target = texture.isCubeMap()
? GL_TEXTURE_CUBE_MAP_POSITIVE_X + m_attachment[ii].layer
: texture.m_target
;
@ -5521,7 +5751,7 @@ namespace bgfx { namespace gl
{
++colorIdx;
GLenum target = GL_TEXTURE_CUBE_MAP == texture.m_target
GLenum target = texture.isCubeMap()
? GL_TEXTURE_CUBE_MAP_POSITIVE_X + m_attachment[ii].layer
: texture.m_target
;

View File

@ -624,6 +624,14 @@ typedef uint64_t GLuint64;
# define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2
#endif // GL_UNSIGNED_INT_SAMPLER_2D
#ifndef GL_INT_SAMPLER_2D_ARRAY
# define GL_INT_SAMPLER_2D_ARRAY 0x8DCF
#endif // GL_INT_SAMPLER_2D_ARRAY
#ifndef GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
# define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7
#endif // GL_UNSIGNED_INT_SAMPLER_2D_ARRAY
#ifndef GL_INT_SAMPLER_3D
# define GL_INT_SAMPLER_3D 0x8DCB
#endif // GL_INT_SAMPLER_3D
@ -656,6 +664,14 @@ typedef uint64_t GLuint64;
# define GL_SAMPLER_2D_SHADOW 0x8B62
#endif // GL_SAMPLER_2D_SHADOW
#ifndef GL_SAMPLER_2D_ARRAY
# define GL_SAMPLER_2D_ARRAY 0x8DC1
#endif // GL_SAMPLER_2D_ARRAY
#ifndef GL_SAMPLER_2D_ARRAY_SHADOW
# define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4
#endif // GL_SAMPLER_2D_ARRAY_SHADOW
#ifndef GL_TEXTURE_MAX_LEVEL
# define GL_TEXTURE_MAX_LEVEL 0x813D
#endif // GL_TEXTURE_MAX_LEVEL
@ -863,6 +879,18 @@ typedef uint64_t GLuint64;
# define GL_CLAMP_TO_BORDER 0x812D
#endif // GL_CLAMP_TO_BORDER
#ifndef GL_TEXTURE_2D_ARRAY
# define GL_TEXTURE_2D_ARRAY 0x8C1A
#endif // GL_TEXTURE_2D_ARRAY
#ifndef GL_TEXTURE_2D_MULTISAMPLE_ARRAY
# define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102
#endif // GL_TEXTURE_2D_MULTISAMPLE_ARRAY
#ifndef GL_TEXTURE_CUBE_MAP_ARRAY
# define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009
#endif // GL_TEXTURE_CUBE_MAP_ARRAY
#ifndef GL_TEXTURE_CUBE_MAP_SEAMLESS
# define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
#endif // GL_TEXTURE_CUBE_MAP_SEAMLESS
@ -1240,6 +1268,14 @@ namespace bgfx { namespace gl
void commit(uint32_t _stage, uint32_t _flags, const float _palette[][4]);
void resolve() const;
bool isCubeMap() const
{
return 0
|| GL_TEXTURE_CUBE_MAP == m_target
|| GL_TEXTURE_CUBE_MAP_ARRAY == m_target
;
}
GLuint m_id;
GLuint m_rbo;
GLenum m_target;

View File

@ -89,6 +89,14 @@ namespace bgfx
NULL
};
static const char* s_textureArray[] =
{
"texture2DArray",
"texture2DArrayLod",
"shadow2DArray",
NULL
};
static const char* s_ARB_texture_multisample[] =
{
"sampler2DMS",
@ -1760,11 +1768,12 @@ namespace bgfx
{
std::string code;
const bool usesTextureLod = !!bx::findIdentifierMatch(input, s_ARB_shader_texture_lod /*EXT_shader_texture_lod*/);
const bool usesGpuShader5 = !!bx::findIdentifierMatch(input, s_ARB_gpu_shader5);
const bool usesPacking = !!bx::findIdentifierMatch(input, s_ARB_shading_language_packing);
const bool usesTextureMS = !!bx::findIdentifierMatch(input, s_ARB_texture_multisample);
const bool usesTexelFetch = !!bx::findIdentifierMatch(input, s_texelFetch);
const bool usesTextureLod = !!bx::findIdentifierMatch(input, s_ARB_shader_texture_lod /*EXT_shader_texture_lod*/);
const bool usesTextureMS = !!bx::findIdentifierMatch(input, s_ARB_texture_multisample);
const bool usesTextureArray = !!bx::findIdentifierMatch(input, s_textureArray);
const bool usesPacking = !!bx::findIdentifierMatch(input, s_ARB_shading_language_packing);
if (0 == essl)
{
@ -1824,6 +1833,13 @@ namespace bgfx
, "#extension GL_ARB_texture_multisample : enable\n"
);
}
if (usesTextureArray)
{
bx::stringPrintf(code
, "#extension GL_EXT_texture_array : enable\n"
);
}
}
else
{