GL vs D3D init.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ---- GL version | |
| static GLuint mk_tex_bind( GLenum target ) | |
| { | |
| GLuint tex; | |
| glGenTextures( 1, &tex ); | |
| glBindTexture( target, tex ); | |
| return tex; | |
| } | |
| static GLuint make_gl_tex( GLenum internalformat, GLsizei w, GLsizei h ) | |
| { | |
| GLuint tex = mk_tex_bind( GL_TEXTURE_2D ); | |
| glTexStorage2D( GL_TEXTURE_2D, 1, internalformat, w, h ); | |
| return tex; | |
| } | |
| static GLuint make_gl_view( GLuint orig_tex, GLenum internalformat ) | |
| { | |
| GLuint tex; | |
| glGenTextures( 1, &tex ); | |
| glTextureView( tex, GL_TEXTURE_2D, orig_tex, internalformat, 0, 1, 0, 1 ); | |
| return tex; | |
| } | |
| static BINKGPU_GL_PLANESET make_plane_set( GLsizei w, GLsizei h, U32 has_alpha ) | |
| { | |
| BINKGPU_GL_PLANESET p; | |
| p.t.Y = make_gl_tex( GL_R8UI, w, h ); | |
| p.t.CrCb = make_gl_tex( GL_RG8UI, w / 2, h / 2 ); | |
| p.t.A = 0; | |
| if ( has_alpha ) | |
| p.t.A = make_gl_tex( GL_R8UI, w, h ); | |
| return p; | |
| } | |
| static BINKGPU_GL_PLANESET float_views_plane_set( BINKGPU_GL_PLANESET const * in ) | |
| { | |
| BINKGPU_GL_PLANESET p; | |
| p.t.Y = make_gl_view( in->t.Y, GL_R8 ); | |
| p.t.CrCb = make_gl_view( in->t.CrCb, GL_RG8 ); | |
| p.t.A = 0; | |
| if ( in->t.A ) | |
| p.t.A = make_gl_view( in->t.A, GL_R8 ); | |
| return p; | |
| } | |
| // ---- D3D11 version | |
| static void create_plane_tex( BINKGPU_D3D11_PLANE_TEX * plane, ID3D11Device * dev, HRESULT * hr, DXGI_FORMAT fmt_res, DXGI_FORMAT fmt_uint, DXGI_FORMAT fmt_unorm, U32 w, U32 h ) | |
| { | |
| D3D11_TEXTURE2D_DESC tex_desc; | |
| D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc; | |
| D3D11_SHADER_RESOURCE_VIEW_DESC srv_uint_desc, srv_unorm_desc; | |
| if ( FAILED( *hr ) ) | |
| return; | |
| tex_desc.Width = w; | |
| tex_desc.Height = h; | |
| tex_desc.MipLevels = 1; | |
| tex_desc.ArraySize = 1; | |
| tex_desc.Format = fmt_res; | |
| tex_desc.SampleDesc.Count = 1; | |
| tex_desc.SampleDesc.Quality = 0; | |
| tex_desc.Usage = D3D11_USAGE_DEFAULT; | |
| tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS; | |
| tex_desc.CPUAccessFlags = 0; | |
| tex_desc.MiscFlags = 0; | |
| srv_uint_desc.Format = fmt_uint; | |
| srv_uint_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; | |
| srv_uint_desc.Texture2D.MostDetailedMip = 0; | |
| srv_uint_desc.Texture2D.MipLevels = 1; | |
| srv_unorm_desc.Format = fmt_unorm; | |
| srv_unorm_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; | |
| srv_unorm_desc.Texture2D.MostDetailedMip = 0; | |
| srv_unorm_desc.Texture2D.MipLevels = 1; | |
| uav_desc.Format = fmt_uint; | |
| uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; | |
| uav_desc.Texture2D.MipSlice = 0; | |
| *hr = dev->CreateTexture2D( &tex_desc, NULL, &plane->tex ); | |
| if ( FAILED( *hr ) ) { d3d_error( *hr ); return; } | |
| *hr = dev->CreateUnorderedAccessView( plane->tex, &uav_desc, &plane->uav ); | |
| if ( FAILED( *hr ) ) { d3d_error( *hr ); return; } | |
| *hr = dev->CreateShaderResourceView( plane->tex, &srv_uint_desc, &plane->srv_uint ); | |
| if ( FAILED( *hr ) ) { d3d_error( *hr ); return; } | |
| *hr = dev->CreateShaderResourceView( plane->tex, &srv_unorm_desc, &plane->srv_unorm ); | |
| if ( FAILED( *hr ) ) { d3d_error( *hr ); return; } | |
| } | |
| static void create_plane_set( BINKGPU_D3D11_PLANESET * set, ID3D11Device * dev, HRESULT * hr, U32 w, U32 h, U32 has_alpha ) | |
| { | |
| memset( set, 0, sizeof( *set ) ); | |
| create_plane_tex( &set->Y, dev, hr, DXGI_FORMAT_R8_TYPELESS, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UNORM, w, h ); | |
| create_plane_tex( &set->CrCb, dev, hr, DXGI_FORMAT_R8G8_TYPELESS, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UNORM, w / 2, h / 2 ); | |
| if ( has_alpha ) | |
| create_plane_tex( &set->A, dev, hr, DXGI_FORMAT_R8_TYPELESS, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UNORM, w, h ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment