Skip to content

Commit

Permalink
Added support for the extension OES_EGL_image_external(_essl3) for GLES2
Browse files Browse the repository at this point in the history
and GLES3 renderer.
  • Loading branch information
Gabriel committed Feb 3, 2020
1 parent dc87c12 commit bf2b6df
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 6 deletions.
4 changes: 3 additions & 1 deletion 3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static inline const char* get_precision_string (glsl_precision p)
static const int tex_sampler_type_count = 7;
// [glsl_sampler_dim]
static const char* tex_sampler_dim_name[tex_sampler_type_count] = {
"1D", "2D", "3D", "Cube", "Rect", "Buf", "External",
"1D", "2D", "3D", "Cube", "Rect", "Buf", "2D",
};
static int tex_sampler_dim_size[tex_sampler_type_count] = {
1, 2, 3, 3, 2, 2, 2,
Expand Down Expand Up @@ -256,6 +256,8 @@ _mesa_print_ir_glsl(exec_list *instructions,
str.asprintf_append("#extension GL_ARB_shader_bit_encoding : enable\n");
if (state->EXT_texture_array_enable)
str.asprintf_append ("#extension GL_EXT_texture_array : enable\n");
if (state->OES_EGL_image_external_enable)
str.asprintf_append ("#extension GL_OES_EGL_image_external : enable\n");
}

// remove unused struct declarations
Expand Down
17 changes: 17 additions & 0 deletions bindings/cs/bgfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3916,6 +3916,23 @@ public struct VertexLayoutHandle{ public ushort idx; }
[DllImport(DllName, EntryPoint="bgfx_override_internal_texture_ptr", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe UIntPtr override_internal_texture_ptr(TextureHandle _handle, UIntPtr _ptr);

/// <summary>
/// Override internal texture with externally created texture. Previously
/// created internal texture will released.
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
/// @returns Native API pointer to texture. If result is 0, texture is not created yet from the
/// main thread.
/// @warning Must be called only on render thread.
/// </summary>
///
/// <param name="_handle">Texture handle.</param>
/// <param name="_ptr">Native API pointer to texture.</param>
/// <param name="_target">Native API sampler target type.</param>
///
[DllImport(DllName, EntryPoint="bgfx_override_internal_texture_ptr_target", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe UIntPtr override_internal_texture_ptr_target(TextureHandle _handle, UIntPtr _ptr, UIntPtr _target);

/// <summary>
/// Override internal texture by creating new texture. Previously created
/// internal texture will released.
Expand Down
31 changes: 31 additions & 0 deletions bindings/d/funcs.d
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,21 @@ version(BindBgfx_Static)
*/
ulong bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, ulong _ptr);

/**
* Override internal texture with externally created texture. Previously
* created internal texture will released.
* Attention: It's expected you understand some bgfx internals before you
* use this call.
* Returns: Native API pointer to texture. If result is 0, texture is not created yet from the
* main thread.
* Warning: Must be called only on render thread.
* Params:
* _handle = Texture handle.
* _ptr = Native API pointer to texture.
* _target = Native API sampler target type.
*/
ulong bgfx_override_internal_texture_ptr_target(bgfx_texture_handle_t _handle, ulong _ptr, ulong _target);

/**
* Override internal texture by creating new texture. Previously created
* internal texture will released.
Expand Down Expand Up @@ -3861,6 +3876,22 @@ else
alias da_bgfx_override_internal_texture_ptr = ulong function(bgfx_texture_handle_t _handle, ulong _ptr);
da_bgfx_override_internal_texture_ptr bgfx_override_internal_texture_ptr;

/**
* Override internal texture with externally created texture. Previously
* created internal texture will released.
* Attention: It's expected you understand some bgfx internals before you
* use this call.
* Returns: Native API pointer to texture. If result is 0, texture is not created yet from the
* main thread.
* Warning: Must be called only on render thread.
* Params:
* _handle = Texture handle.
* _ptr = Native API pointer to texture.
* _target = Native API sampler target type.
*/
alias da_bgfx_override_internal_texture_ptr_target = ulong function(bgfx_texture_handle_t _handle, ulong _ptr, ulong _target);
da_bgfx_override_internal_texture_ptr_target bgfx_override_internal_texture_ptr_target;

/**
* Override internal texture by creating new texture. Previously created
* internal texture will released.
Expand Down
21 changes: 21 additions & 0 deletions include/bgfx/c99/bgfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,25 @@ BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data(void);
*/
BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr);

/**
* Override internal texture with externally created texture. Previously
* created internal texture will released.
* @attention It's expected you understand some bgfx internals before you
* use this call.
* @returns Native API pointer to texture. If result is 0, texture is not created yet from the
* main thread.
* @warning Must be called only on render thread.
*
* @param[in] _handle Texture handle.
* @param[in] _ptr Native API pointer to texture.
* @param[in] _target Native API sampler target type.
*
* @returns Native API pointer to texture. If result is 0, texture is not created
* yet from the main thread.
*
*/
BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr_target(bgfx_texture_handle_t _handle, uintptr_t _ptr, uintptr_t _target);

/**
* Override internal texture by creating new texture. Previously created
* internal texture will released.
Expand Down Expand Up @@ -3373,6 +3392,7 @@ typedef enum bgfx_function_id
BGFX_FUNCTION_ID_SET_PLATFORM_DATA,
BGFX_FUNCTION_ID_GET_INTERNAL_DATA,
BGFX_FUNCTION_ID_OVERRIDE_INTERNAL_TEXTURE_PTR,
BGFX_FUNCTION_ID_OVERRIDE_INTERNAL_TEXTURE_PTR_TARGET,
BGFX_FUNCTION_ID_OVERRIDE_INTERNAL_TEXTURE,
BGFX_FUNCTION_ID_SET_MARKER,
BGFX_FUNCTION_ID_SET_STATE,
Expand Down Expand Up @@ -3565,6 +3585,7 @@ struct bgfx_interface_vtbl
void (*set_platform_data)(const bgfx_platform_data_t * _data);
const bgfx_internal_data_t* (*get_internal_data)(void);
uintptr_t (*override_internal_texture_ptr)(bgfx_texture_handle_t _handle, uintptr_t _ptr);
uintptr_t (*override_internal_texture_ptr_target)(bgfx_texture_handle_t _handle, uintptr_t _ptr, uintptr_t _target);
uintptr_t (*override_internal_texture)(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint64_t _flags);
void (*set_marker)(const char* _marker);
void (*set_state)(uint64_t _state, uint32_t _rgba);
Expand Down
19 changes: 19 additions & 0 deletions include/bgfx/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ namespace bgfx
///
uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr);

/// Override internal texture with externally created texture. Previously
/// created internal texture will released.
///
/// @attention It's expected you understand some bgfx internals before you
/// use this call.
///
/// @param[in] _handle Texture handle.
/// @param[in] _ptr Native API pointer to texture.
/// @param[in] _target Native API sampler target type.
///
/// @returns Native API pointer to texture. If result is 0, texture is not created yet from the
/// main thread.
///
/// @warning Must be called only on render thread.
///
/// @attention C99 equivalent is `bgfx_override_internal_texture_ptr`.
///
uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr, uintptr_t _target);

/// Override internal texture by creating new texture. Previously created
/// internal texture will released.
///
Expand Down
18 changes: 18 additions & 0 deletions scripts/bgfx.idl
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,24 @@ func.overrideInternal { cname = "override_internal_texture_ptr" }
.handle "TextureHandle" --- Texture handle.
.ptr "uintptr_t" --- Native API pointer to texture.

--- Override internal texture with externally created texture. Previously
--- created internal texture will released.
---
--- @attention It's expected you understand some bgfx internals before you
--- use this call.
---
--- @returns Native API pointer to texture. If result is 0, texture is not created yet from the
--- main thread.
---
--- @warning Must be called only on render thread.
---
func.overrideInternal { cname = "override_internal_texture_ptr_target" }
"uintptr_t" --- Native API pointer to texture. If result is 0, texture is not created
--- yet from the main thread.
.handle "TextureHandle" --- Texture handle.
.ptr "uintptr_t" --- Native API pointer to texture.
.target "uintptr_t" --- Native API sampler target type.

--- Override internal texture by creating new texture. Previously created
--- internal texture will released.
---
Expand Down
14 changes: 14 additions & 0 deletions src/bgfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,20 @@ namespace bgfx
return rci->getInternal(_handle);
}

uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr, uintptr_t _target)
{
BGFX_CHECK_RENDER_THREAD();
RendererContextI* rci = s_ctx->m_renderCtx;
if (0 == rci->getInternal(_handle) )
{
return 0;
}

rci->overrideInternal(_handle, _ptr, _target);

return rci->getInternal(_handle);
}

uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint64_t _flags)
{
BGFX_CHECK_RENDER_THREAD();
Expand Down
7 changes: 7 additions & 0 deletions src/bgfx.idl.inl
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,12 @@ BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _h
return bgfx::overrideInternal(handle.cpp, _ptr);
}

BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr_target(bgfx_texture_handle_t _handle, uintptr_t _ptr, uintptr_t _target)
{
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
return bgfx::overrideInternal(handle.cpp, _ptr, _target);
}

BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint64_t _flags)
{
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
Expand Down Expand Up @@ -1353,6 +1359,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
bgfx_set_platform_data,
bgfx_get_internal_data,
bgfx_override_internal_texture_ptr,
bgfx_override_internal_texture_ptr_target,
bgfx_override_internal_texture,
bgfx_set_marker,
bgfx_set_state,
Expand Down
1 change: 1 addition & 0 deletions src/bgfx_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,7 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA
virtual void readTexture(TextureHandle _handle, void* _data, uint8_t _mip) = 0;
virtual void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, uint16_t _numLayers) = 0;
virtual void overrideInternal(TextureHandle _handle, uintptr_t _ptr) = 0;
virtual void overrideInternal(TextureHandle _handle, uintptr_t _ptr, uintptr_t _target) = 0;
virtual uintptr_t getInternal(TextureHandle _handle) = 0;
virtual void destroyTexture(TextureHandle _handle) = 0;
virtual void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const Attachment* _attachment) = 0;
Expand Down
8 changes: 8 additions & 0 deletions src/bgfx_shader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord)
# endif // BGFX_SHADER_LANGUAGE_HLSL > 3
# define SAMPLEREXTERNAL(_name, _reg) SAMPLER2D(_name, _reg)
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); }
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); }
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); }
Expand Down Expand Up @@ -555,6 +557,12 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
# define ISAMPLER3D(_name, _reg) uniform isampler3D _name
# define USAMPLER3D(_name, _reg) uniform usampler3D _name
# if BGFX_SHADER_LANGUAGE_GLSL == 1
# define SAMPLEREXTERNAL(_name, _reg) uniform samplerExternalOES _name
# else
# define SAMPLEREXTERNAL(_name, _reg) SAMPLER2D(_name, _req)
# endif
# define texture2DBias(_sampler, _coord, _bias) texture2D(_sampler, _coord, _bias)
# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias)
Expand Down
6 changes: 6 additions & 0 deletions src/renderer_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,12 @@ namespace bgfx { namespace d3d11
m_textures[_handle.idx].overrideInternal(_ptr);
}

void overrideInternal(TextureHandle _handle, uintptr_t _ptr, uintptr_t _target) override
{
BX_UNUSED(_target);
overrideInternal(_handle, _ptr);
}

uintptr_t getInternal(TextureHandle _handle) override
{
// Resource ref. counts might be messed up outside of bgfx.
Expand Down
6 changes: 6 additions & 0 deletions src/renderer_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,12 @@ namespace bgfx { namespace d3d12
BX_UNUSED(_handle, _ptr);
}

void overrideInternal(TextureHandle _handle, uintptr_t _ptr, uintptr_t _target) override
{
BX_UNUSED(_target);
overrideInternal(_handle, _ptr);
}

uintptr_t getInternal(TextureHandle _handle) override
{
BX_UNUSED(_handle);
Expand Down
6 changes: 6 additions & 0 deletions src/renderer_d3d9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,12 @@ namespace bgfx { namespace d3d9
m_textures[_handle.idx].overrideInternal(_ptr);
}

void overrideInternal(TextureHandle _handle, uintptr_t _ptr, uintptr_t _target) override
{
BX_UNUSED(_target);
overrideInternal(_handle, _ptr);
}

uintptr_t getInternal(TextureHandle _handle) override
{
// Resource ref. counts might be messed up outside of bgfx.
Expand Down
Loading

0 comments on commit bf2b6df

Please sign in to comment.