blob: 695e168478f1e776bf91a26832ab3b1318d511a9 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
3// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// formatutils11.cpp: Queries for GL image formats and their translations to D3D11
9// formats.
10
Geoff Langd47e0fc2013-08-29 11:40:43 -040011#include "libGLESv2/renderer/d3d11/formatutils11.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000012#include "libGLESv2/renderer/generatemip.h"
13#include "libGLESv2/renderer/loadimage.h"
Geoff Langfe28ca02013-06-04 10:10:48 -040014#include "libGLESv2/renderer/copyimage.h"
Geoff Lang00f6bc32013-09-20 14:59:06 -040015#include "libGLESv2/renderer/Renderer.h"
Jamie Madill7ab02fa2014-02-04 16:04:08 -050016#include "libGLESv2/renderer/copyvertex.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017
18namespace rx
19{
20
21struct D3D11ES3FormatInfo
22{
23 DXGI_FORMAT mTexFormat;
24 DXGI_FORMAT mSRVFormat;
25 DXGI_FORMAT mRTVFormat;
26 DXGI_FORMAT mDSVFormat;
27
28 D3D11ES3FormatInfo()
29 : mTexFormat(DXGI_FORMAT_UNKNOWN), mDSVFormat(DXGI_FORMAT_UNKNOWN), mRTVFormat(DXGI_FORMAT_UNKNOWN), mSRVFormat(DXGI_FORMAT_UNKNOWN)
30 { }
31
32 D3D11ES3FormatInfo(DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat, DXGI_FORMAT dsvFormat)
33 : mTexFormat(texFormat), mDSVFormat(dsvFormat), mRTVFormat(rtvFormat), mSRVFormat(srvFormat)
34 { }
35};
36
37// For sized GL internal formats, there is only one corresponding D3D11 format. This map type allows
38// querying for the DXGI texture formats to use for textures, SRVs, RTVs and DSVs given a GL internal
39// format.
Geoff Lang005df412013-10-16 14:12:50 -040040typedef std::pair<GLenum, D3D11ES3FormatInfo> D3D11ES3FormatPair;
41typedef std::map<GLenum, D3D11ES3FormatInfo> D3D11ES3FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000042
Geoff Lang18591b72013-06-07 12:00:15 -040043static D3D11ES3FormatMap BuildD3D11ES3FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000044{
45 D3D11ES3FormatMap map;
46
47 // | GL internal format | | D3D11 texture format | D3D11 SRV format | D3D11 RTV format | D3D11 DSV format |
48 map.insert(D3D11ES3FormatPair(GL_NONE, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +000049 map.insert(D3D11ES3FormatPair(GL_R8, D3D11ES3FormatInfo(DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +000050 map.insert(D3D11ES3FormatPair(GL_R8_SNORM, D3D11ES3FormatInfo(DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +000051 map.insert(D3D11ES3FormatPair(GL_RG8, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +000052 map.insert(D3D11ES3FormatPair(GL_RG8_SNORM, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000053 map.insert(D3D11ES3FormatPair(GL_RGB8, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +000054 map.insert(D3D11ES3FormatPair(GL_RGB8_SNORM, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000055 map.insert(D3D11ES3FormatPair(GL_RGB565, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
56 map.insert(D3D11ES3FormatPair(GL_RGBA4, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
57 map.insert(D3D11ES3FormatPair(GL_RGB5_A1, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
58 map.insert(D3D11ES3FormatPair(GL_RGBA8, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +000059 map.insert(D3D11ES3FormatPair(GL_RGBA8_SNORM, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +000060 map.insert(D3D11ES3FormatPair(GL_RGB10_A2, D3D11ES3FormatInfo(DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +000061 map.insert(D3D11ES3FormatPair(GL_RGB10_A2UI, D3D11ES3FormatInfo(DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +000062 map.insert(D3D11ES3FormatPair(GL_SRGB8, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000063 map.insert(D3D11ES3FormatPair(GL_SRGB8_ALPHA8, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +000064 map.insert(D3D11ES3FormatPair(GL_R16F, D3D11ES3FormatInfo(DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN)));
65 map.insert(D3D11ES3FormatPair(GL_RG16F, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000066 map.insert(D3D11ES3FormatPair(GL_RGB16F, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN)));
67 map.insert(D3D11ES3FormatPair(GL_RGBA16F, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +000068 map.insert(D3D11ES3FormatPair(GL_R32F, D3D11ES3FormatInfo(DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN)));
69 map.insert(D3D11ES3FormatPair(GL_RG32F, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN)));
Geoff Lang1c3192e2013-07-22 13:59:24 -040070 map.insert(D3D11ES3FormatPair(GL_RGB32F, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000071 map.insert(D3D11ES3FormatPair(GL_RGBA32F, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN)));
Geoff Lang1ec57f82013-10-16 11:43:23 -040072 map.insert(D3D11ES3FormatPair(GL_R11F_G11F_B10F, D3D11ES3FormatInfo(DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +000073 map.insert(D3D11ES3FormatPair(GL_RGB9_E5, D3D11ES3FormatInfo(DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +000074 map.insert(D3D11ES3FormatPair(GL_R8I, D3D11ES3FormatInfo(DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_SINT, DXGI_FORMAT_UNKNOWN)));
75 map.insert(D3D11ES3FormatPair(GL_R8UI, D3D11ES3FormatInfo(DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN)));
76 map.insert(D3D11ES3FormatPair(GL_R16I, D3D11ES3FormatInfo(DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SINT, DXGI_FORMAT_UNKNOWN)));
77 map.insert(D3D11ES3FormatPair(GL_R16UI, D3D11ES3FormatInfo(DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_UNKNOWN)));
78 map.insert(D3D11ES3FormatPair(GL_R32I, D3D11ES3FormatInfo(DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_SINT, DXGI_FORMAT_UNKNOWN)));
79 map.insert(D3D11ES3FormatPair(GL_R32UI, D3D11ES3FormatInfo(DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_UNKNOWN)));
80 map.insert(D3D11ES3FormatPair(GL_RG8I, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_UNKNOWN)));
81 map.insert(D3D11ES3FormatPair(GL_RG8UI, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN)));
82 map.insert(D3D11ES3FormatPair(GL_RG16I, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_UNKNOWN)));
83 map.insert(D3D11ES3FormatPair(GL_RG16UI, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_UNKNOWN)));
84 map.insert(D3D11ES3FormatPair(GL_RG32I, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_UNKNOWN)));
85 map.insert(D3D11ES3FormatPair(GL_RG32UI, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN)));
86 map.insert(D3D11ES3FormatPair(GL_RGB8I, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_UNKNOWN)));
87 map.insert(D3D11ES3FormatPair(GL_RGB8UI, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN)));
88 map.insert(D3D11ES3FormatPair(GL_RGB16I, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_UNKNOWN)));
89 map.insert(D3D11ES3FormatPair(GL_RGB16UI, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_UNKNOWN)));
Jamie Madill0fd77862013-09-09 16:24:06 -040090 map.insert(D3D11ES3FormatPair(GL_RGB32I, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_UNKNOWN)));
91 map.insert(D3D11ES3FormatPair(GL_RGB32UI, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +000092 map.insert(D3D11ES3FormatPair(GL_RGBA8I, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_UNKNOWN)));
93 map.insert(D3D11ES3FormatPair(GL_RGBA8UI, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN)));
94 map.insert(D3D11ES3FormatPair(GL_RGBA16I, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_UNKNOWN)));
95 map.insert(D3D11ES3FormatPair(GL_RGBA16UI, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_UNKNOWN)));
96 map.insert(D3D11ES3FormatPair(GL_RGBA32I, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_UNKNOWN)));
97 map.insert(D3D11ES3FormatPair(GL_RGBA32UI, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000098
99 // Unsized formats, TODO: Are types of float and half float allowed for the unsized types? Would it change the DXGI format?
Geoff Lang0d56c432013-06-05 14:54:16 -0400100 map.insert(D3D11ES3FormatPair(GL_ALPHA, D3D11ES3FormatInfo(DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN)));
101 map.insert(D3D11ES3FormatPair(GL_LUMINANCE, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
102 map.insert(D3D11ES3FormatPair(GL_LUMINANCE_ALPHA, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000103 map.insert(D3D11ES3FormatPair(GL_RGB, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
104 map.insert(D3D11ES3FormatPair(GL_RGBA, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
105 map.insert(D3D11ES3FormatPair(GL_BGRA_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
106
107 // From GL_EXT_texture_storage
Geoff Lang0d56c432013-06-05 14:54:16 -0400108 // | GL internal format | | D3D11 texture format | D3D11 SRV format | D3D11 RTV format | D3D11 DSV format |
109 map.insert(D3D11ES3FormatPair(GL_ALPHA8_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN )));
110 map.insert(D3D11ES3FormatPair(GL_LUMINANCE8_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
111 map.insert(D3D11ES3FormatPair(GL_ALPHA32F_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN )));
Geoff Lang95f9f982013-10-21 17:09:19 -0400112 map.insert(D3D11ES3FormatPair(GL_LUMINANCE32F_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN )));
Geoff Lang0d56c432013-06-05 14:54:16 -0400113 map.insert(D3D11ES3FormatPair(GL_ALPHA16F_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN )));
Geoff Langb69d39b2014-05-06 11:49:22 -0400114 map.insert(D3D11ES3FormatPair(GL_LUMINANCE16F_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN )));
Geoff Lang0d56c432013-06-05 14:54:16 -0400115 map.insert(D3D11ES3FormatPair(GL_LUMINANCE8_ALPHA8_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
116 map.insert(D3D11ES3FormatPair(GL_LUMINANCE_ALPHA32F_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN )));
117 map.insert(D3D11ES3FormatPair(GL_LUMINANCE_ALPHA16F_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN )));
118 map.insert(D3D11ES3FormatPair(GL_BGRA8_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
119 map.insert(D3D11ES3FormatPair(GL_BGRA4_ANGLEX, D3D11ES3FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
120 map.insert(D3D11ES3FormatPair(GL_BGR5_A1_ANGLEX, D3D11ES3FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000121
122 // Depth stencil formats
Geoff Lang0d56c432013-06-05 14:54:16 -0400123 map.insert(D3D11ES3FormatPair(GL_DEPTH_COMPONENT16, D3D11ES3FormatInfo(DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D16_UNORM )));
124 map.insert(D3D11ES3FormatPair(GL_DEPTH_COMPONENT24, D3D11ES3FormatInfo(DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D24_UNORM_S8_UINT )));
125 map.insert(D3D11ES3FormatPair(GL_DEPTH_COMPONENT32F, D3D11ES3FormatInfo(DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D32_FLOAT )));
126 map.insert(D3D11ES3FormatPair(GL_DEPTH24_STENCIL8, D3D11ES3FormatInfo(DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D24_UNORM_S8_UINT )));
127 map.insert(D3D11ES3FormatPair(GL_DEPTH32F_STENCIL8, D3D11ES3FormatInfo(DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D32_FLOAT_S8X24_UINT)));
Shannon Woods9e73b212013-07-08 10:32:19 -0400128 map.insert(D3D11ES3FormatPair(GL_STENCIL_INDEX8, D3D11ES3FormatInfo(DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D24_UNORM_S8_UINT )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000129
130 // From GL_ANGLE_depth_texture
Geoff Lang0d56c432013-06-05 14:54:16 -0400131 map.insert(D3D11ES3FormatPair(GL_DEPTH_COMPONENT32_OES, D3D11ES3FormatInfo(DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D24_UNORM_S8_UINT )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000132
133 // Compressed formats, From ES 3.0.1 spec, table 3.16
134 // | GL internal format | | D3D11 texture format | D3D11 SRV format | D3D11 RTV format | D3D11 DSV format |
135 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_R11_EAC, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
136 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SIGNED_R11_EAC, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
137 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RG11_EAC, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
138 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SIGNED_RG11_EAC, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
139 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGB8_ETC2, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
140 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SRGB8_ETC2, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
141 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
142 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
143 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA8_ETC2_EAC, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
144 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, D3D11ES3FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
145
146 // From GL_EXT_texture_compression_dxt1
147 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
148 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, D3D11ES3FormatInfo(DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
149
150 // From GL_ANGLE_texture_compression_dxt3
151 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, D3D11ES3FormatInfo(DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
152
153 // From GL_ANGLE_texture_compression_dxt5
154 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, D3D11ES3FormatInfo(DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
155
156 return map;
157}
158
Geoff Lang005df412013-10-16 14:12:50 -0400159static bool GetD3D11ES3FormatInfo(GLenum internalFormat, GLuint clientVersion, D3D11ES3FormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000160{
Geoff Lang18591b72013-06-07 12:00:15 -0400161 static const D3D11ES3FormatMap formatMap = BuildD3D11ES3FormatMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000162 D3D11ES3FormatMap::const_iterator iter = formatMap.find(internalFormat);
163 if (iter != formatMap.end())
164 {
165 if (outFormatInfo)
166 {
167 *outFormatInfo = iter->second;
168 }
169 return true;
170 }
171 else
172 {
173 return false;
174 }
175}
176
177// ES3 image loading functions vary based on the internal format and data type given,
178// this map type determines the loading function from the internal format and type supplied
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000179// to glTex*Image*D and the destination DXGI_FORMAT. Source formats and types are taken from
180// Tables 3.2 and 3.3 of the ES 3 spec.
Geoff Lang005df412013-10-16 14:12:50 -0400181typedef std::pair<GLenum, GLenum> InternalFormatTypePair;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000182typedef std::pair<InternalFormatTypePair, LoadImageFunction> D3D11LoadFunctionPair;
183typedef std::map<InternalFormatTypePair, LoadImageFunction> D3D11LoadFunctionMap;
184
185static void UnimplementedLoadFunction(int width, int height, int depth,
186 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
187 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
188{
189 UNIMPLEMENTED();
190}
191
Geoff Langd3ff2162013-06-07 15:10:59 -0400192static void UnreachableLoadFunction(int width, int height, int depth,
193 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
194 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
195{
196 UNREACHABLE();
197}
198
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000199// A helper function to insert data into the D3D11LoadFunctionMap with fewer characters.
Geoff Lang005df412013-10-16 14:12:50 -0400200static inline void insertLoadFunction(D3D11LoadFunctionMap *map, GLenum internalFormat, GLenum type,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000201 LoadImageFunction loadFunc)
202{
203 map->insert(D3D11LoadFunctionPair(InternalFormatTypePair(internalFormat, type), loadFunc));
204}
205
206D3D11LoadFunctionMap buildD3D11LoadFunctionMap()
207{
208 D3D11LoadFunctionMap map;
209
210 // | Internal format | Type | Load function |
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000211 insertLoadFunction(&map, GL_RGBA8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400212 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
213 insertLoadFunction(&map, GL_RGBA4, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000214 insertLoadFunction(&map, GL_SRGB8_ALPHA8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000215 insertLoadFunction(&map, GL_RGBA8_SNORM, GL_BYTE, loadToNative<GLbyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000216 insertLoadFunction(&map, GL_RGBA4, GL_UNSIGNED_SHORT_4_4_4_4, loadRGBA4444DataToRGBA );
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000217 insertLoadFunction(&map, GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000218 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_SHORT_5_5_5_1, loadRGBA5551DataToRGBA );
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000219 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_INT_2_10_10_10_REV, loadRGBA2101010ToRGBA );
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000220 insertLoadFunction(&map, GL_RGBA16F, GL_HALF_FLOAT, loadToNative<GLhalf, 4> );
221 insertLoadFunction(&map, GL_RGBA32F, GL_FLOAT, loadToNative<GLfloat, 4> );
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000222 insertLoadFunction(&map, GL_RGBA16F, GL_FLOAT, loadFloatDataToHalfFloat<4> );
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000223 insertLoadFunction(&map, GL_RGBA8UI, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
224 insertLoadFunction(&map, GL_RGBA8I, GL_BYTE, loadToNative<GLbyte, 4> );
225 insertLoadFunction(&map, GL_RGBA16UI, GL_UNSIGNED_SHORT, loadToNative<GLushort, 4> );
226 insertLoadFunction(&map, GL_RGBA16I, GL_SHORT, loadToNative<GLshort, 4> );
227 insertLoadFunction(&map, GL_RGBA32UI, GL_UNSIGNED_INT, loadToNative<GLuint, 4> );
228 insertLoadFunction(&map, GL_RGBA32I, GL_INT, loadToNative<GLint, 4> );
229 insertLoadFunction(&map, GL_RGB10_A2UI, GL_UNSIGNED_INT_2_10_10_10_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000230 insertLoadFunction(&map, GL_RGB8, GL_UNSIGNED_BYTE, loadRGBUByteDataToRGBA );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400231 insertLoadFunction(&map, GL_RGB565, GL_UNSIGNED_BYTE, loadToNative3To4<GLubyte, 0xFF> );
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +0000232 insertLoadFunction(&map, GL_SRGB8, GL_UNSIGNED_BYTE, loadToNative3To4<GLubyte, 0xFF> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000233 insertLoadFunction(&map, GL_RGB8_SNORM, GL_BYTE, loadRGBSByteDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000234 insertLoadFunction(&map, GL_RGB565, GL_UNSIGNED_SHORT_5_6_5, loadRGB565DataToRGBA );
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000235 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_UNSIGNED_INT_10F_11F_11F_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000236 insertLoadFunction(&map, GL_RGB9_E5, GL_UNSIGNED_INT_5_9_9_9_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000237 insertLoadFunction(&map, GL_RGB16F, GL_HALF_FLOAT, loadToNative3To4<GLhalf, gl::Float16One>);
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000238 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_HALF_FLOAT, loadRGBHalfFloatDataTo111110Float );
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000239 insertLoadFunction(&map, GL_RGB9_E5, GL_HALF_FLOAT, loadRGBHalfFloatDataTo999E5 );
Geoff Lang1c3192e2013-07-22 13:59:24 -0400240 insertLoadFunction(&map, GL_RGB32F, GL_FLOAT, loadToNative3To4<GLfloat, gl::Float32One>);
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000241 insertLoadFunction(&map, GL_RGB16F, GL_FLOAT, loadFloatRGBDataToHalfFloatRGBA );
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000242 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_FLOAT, loadRGBFloatDataTo111110Float );
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000243 insertLoadFunction(&map, GL_RGB9_E5, GL_FLOAT, loadRGBFloatDataTo999E5 );
Geoff Lang5b61c692013-08-02 15:02:59 -0400244 insertLoadFunction(&map, GL_RGB8UI, GL_UNSIGNED_BYTE, loadToNative3To4<GLubyte, 0x01> );
245 insertLoadFunction(&map, GL_RGB8I, GL_BYTE, loadToNative3To4<GLbyte, 0x01> );
246 insertLoadFunction(&map, GL_RGB16UI, GL_UNSIGNED_SHORT, loadToNative3To4<GLushort, 0x0001> );
247 insertLoadFunction(&map, GL_RGB16I, GL_SHORT, loadToNative3To4<GLshort, 0x0001> );
Jamie Madill0fd77862013-09-09 16:24:06 -0400248 insertLoadFunction(&map, GL_RGB32UI, GL_UNSIGNED_INT, loadToNative3To4<GLuint, 0x00000001> );
249 insertLoadFunction(&map, GL_RGB32I, GL_INT, loadToNative3To4<GLint, 0x00000001> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000250 insertLoadFunction(&map, GL_RG8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 2> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000251 insertLoadFunction(&map, GL_RG8_SNORM, GL_BYTE, loadToNative<GLbyte, 2> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000252 insertLoadFunction(&map, GL_RG16F, GL_HALF_FLOAT, loadToNative<GLhalf, 2> );
253 insertLoadFunction(&map, GL_RG32F, GL_FLOAT, loadToNative<GLfloat, 2> );
254 insertLoadFunction(&map, GL_RG16F, GL_FLOAT, loadFloatDataToHalfFloat<2> );
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000255 insertLoadFunction(&map, GL_RG8UI, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 2> );
256 insertLoadFunction(&map, GL_RG8I, GL_BYTE, loadToNative<GLbyte, 2> );
257 insertLoadFunction(&map, GL_RG16UI, GL_UNSIGNED_SHORT, loadToNative<GLushort, 2> );
258 insertLoadFunction(&map, GL_RG16I, GL_SHORT, loadToNative<GLshort, 2> );
259 insertLoadFunction(&map, GL_RG32UI, GL_UNSIGNED_INT, loadToNative<GLuint, 2> );
260 insertLoadFunction(&map, GL_RG32I, GL_INT, loadToNative<GLint, 2> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000261 insertLoadFunction(&map, GL_R8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 1> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000262 insertLoadFunction(&map, GL_R8_SNORM, GL_BYTE, loadToNative<GLbyte, 1> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000263 insertLoadFunction(&map, GL_R16F, GL_HALF_FLOAT, loadToNative<GLhalf, 1> );
264 insertLoadFunction(&map, GL_R32F, GL_FLOAT, loadToNative<GLfloat, 1> );
265 insertLoadFunction(&map, GL_R16F, GL_FLOAT, loadFloatDataToHalfFloat<1> );
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000266 insertLoadFunction(&map, GL_R8UI, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 1> );
267 insertLoadFunction(&map, GL_R8I, GL_BYTE, loadToNative<GLbyte, 1> );
268 insertLoadFunction(&map, GL_R16UI, GL_UNSIGNED_SHORT, loadToNative<GLushort, 1> );
269 insertLoadFunction(&map, GL_R16I, GL_SHORT, loadToNative<GLshort, 1> );
270 insertLoadFunction(&map, GL_R32UI, GL_UNSIGNED_INT, loadToNative<GLuint, 1> );
271 insertLoadFunction(&map, GL_R32I, GL_INT, loadToNative<GLint, 1> );
Geoff Lang87465462013-06-17 16:28:54 -0400272 insertLoadFunction(&map, GL_DEPTH_COMPONENT16, GL_UNSIGNED_SHORT, loadToNative<GLushort, 1> );
Geoff Lang4133f5c2013-10-10 13:51:18 -0400273 insertLoadFunction(&map, GL_DEPTH_COMPONENT24, GL_UNSIGNED_INT, loadG8R24DataToR24G8 );
Geoff Lang87465462013-06-17 16:28:54 -0400274 insertLoadFunction(&map, GL_DEPTH_COMPONENT16, GL_UNSIGNED_INT, loadUintDataToUshort );
275 insertLoadFunction(&map, GL_DEPTH_COMPONENT32F, GL_FLOAT, loadToNative<GLfloat, 1> );
Geoff Lang4133f5c2013-10-10 13:51:18 -0400276 insertLoadFunction(&map, GL_DEPTH24_STENCIL8, GL_UNSIGNED_INT_24_8, loadG8R24DataToR24G8 );
Geoff Lang87465462013-06-17 16:28:54 -0400277 insertLoadFunction(&map, GL_DEPTH32F_STENCIL8, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, loadToNative<GLuint, 2> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000278
279 // Unsized formats
Geoff Langd3ff2162013-06-07 15:10:59 -0400280 // Load functions are unreachable because they are converted to sized internal formats based on
281 // the format and type before loading takes place.
282 insertLoadFunction(&map, GL_RGBA, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
283 insertLoadFunction(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, UnreachableLoadFunction );
284 insertLoadFunction(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, UnreachableLoadFunction );
285 insertLoadFunction(&map, GL_RGB, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
286 insertLoadFunction(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, UnreachableLoadFunction );
287 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
288 insertLoadFunction(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
289 insertLoadFunction(&map, GL_ALPHA, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000290
291 // From GL_OES_texture_float
292 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, loadLuminanceAlphaFloatDataToRGBA );
293 insertLoadFunction(&map, GL_LUMINANCE, GL_FLOAT, loadLuminanceFloatDataToRGB );
294 insertLoadFunction(&map, GL_ALPHA, GL_FLOAT, loadAlphaFloatDataToRGBA );
295
296 // From GL_OES_texture_half_float
297 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, loadLuminanceAlphaHalfFloatDataToRGBA);
298 insertLoadFunction(&map, GL_LUMINANCE, GL_HALF_FLOAT, loadLuminanceHalfFloatDataToRGBA );
299 insertLoadFunction(&map, GL_ALPHA, GL_HALF_FLOAT, loadAlphaHalfFloatDataToRGBA );
300
301 // From GL_EXT_texture_storage
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000302 insertLoadFunction(&map, GL_ALPHA8_EXT, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 1> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000303 insertLoadFunction(&map, GL_LUMINANCE8_EXT, GL_UNSIGNED_BYTE, loadLuminanceDataToBGRA );
304 insertLoadFunction(&map, GL_LUMINANCE8_ALPHA8_EXT, GL_UNSIGNED_BYTE, loadLuminanceAlphaDataToBGRA );
305 insertLoadFunction(&map, GL_ALPHA32F_EXT, GL_FLOAT, loadAlphaFloatDataToRGBA );
306 insertLoadFunction(&map, GL_LUMINANCE32F_EXT, GL_FLOAT, loadLuminanceFloatDataToRGB );
307 insertLoadFunction(&map, GL_LUMINANCE_ALPHA32F_EXT, GL_FLOAT, loadLuminanceAlphaFloatDataToRGBA );
308 insertLoadFunction(&map, GL_ALPHA16F_EXT, GL_HALF_FLOAT, loadAlphaHalfFloatDataToRGBA );
309 insertLoadFunction(&map, GL_LUMINANCE16F_EXT, GL_HALF_FLOAT, loadLuminanceHalfFloatDataToRGBA );
310 insertLoadFunction(&map, GL_LUMINANCE_ALPHA16F_EXT, GL_HALF_FLOAT, loadLuminanceAlphaHalfFloatDataToRGBA);
311
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000312 insertLoadFunction(&map, GL_BGRA8_EXT, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000313 insertLoadFunction(&map, GL_BGRA4_ANGLEX, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, loadRGBA4444DataToRGBA );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400314 insertLoadFunction(&map, GL_BGRA4_ANGLEX, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000315 insertLoadFunction(&map, GL_BGR5_A1_ANGLEX, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, loadRGBA5551DataToRGBA );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400316 insertLoadFunction(&map, GL_BGR5_A1_ANGLEX, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000317
318 // Compressed formats
319 // From ES 3.0.1 spec, table 3.16
320 // | Internal format | Type | Load function |
321 insertLoadFunction(&map, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
322 insertLoadFunction(&map, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
323 insertLoadFunction(&map, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
324 insertLoadFunction(&map, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
325 insertLoadFunction(&map, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
326 insertLoadFunction(&map, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
327 insertLoadFunction(&map, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
328 insertLoadFunction(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
329 insertLoadFunction(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
330 insertLoadFunction(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
331 insertLoadFunction(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
332
333 // From GL_EXT_texture_compression_dxt1
334 insertLoadFunction(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 8>);
335 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 8>);
336
337 // From GL_ANGLE_texture_compression_dxt3
338 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 16>);
339
340 // From GL_ANGLE_texture_compression_dxt5
341 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 16>);
342
343 return map;
344}
345
346struct D3D11ES2FormatInfo
347{
348 DXGI_FORMAT mTexFormat;
349 DXGI_FORMAT mSRVFormat;
350 DXGI_FORMAT mRTVFormat;
351 DXGI_FORMAT mDSVFormat;
352
353 LoadImageFunction mLoadImageFunction;
354
355 D3D11ES2FormatInfo()
356 : mTexFormat(DXGI_FORMAT_UNKNOWN), mDSVFormat(DXGI_FORMAT_UNKNOWN), mRTVFormat(DXGI_FORMAT_UNKNOWN),
357 mSRVFormat(DXGI_FORMAT_UNKNOWN), mLoadImageFunction(NULL)
358 { }
359
360 D3D11ES2FormatInfo(DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat, DXGI_FORMAT dsvFormat,
361 LoadImageFunction loadFunc)
362 : mTexFormat(texFormat), mDSVFormat(dsvFormat), mRTVFormat(rtvFormat), mSRVFormat(srvFormat),
363 mLoadImageFunction(loadFunc)
364 { }
365};
366
367// ES2 internal formats can map to DXGI formats and loading functions
Geoff Lang005df412013-10-16 14:12:50 -0400368typedef std::pair<GLenum, D3D11ES2FormatInfo> D3D11ES2FormatPair;
369typedef std::map<GLenum, D3D11ES2FormatInfo> D3D11ES2FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000370
Geoff Lang18591b72013-06-07 12:00:15 -0400371static D3D11ES2FormatMap BuildD3D11ES2FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000372{
373 D3D11ES2FormatMap map;
374
375 // | Internal format | | Texture format | SRV format | RTV format | DSV format | Load function |
Geoff Lang87465462013-06-17 16:28:54 -0400376 map.insert(D3D11ES2FormatPair(GL_NONE, D3D11ES2FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, UnreachableLoadFunction )));
377 map.insert(D3D11ES2FormatPair(GL_DEPTH_COMPONENT16, D3D11ES2FormatInfo(DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D16_UNORM, UnreachableLoadFunction )));
378 map.insert(D3D11ES2FormatPair(GL_DEPTH_COMPONENT32_OES, D3D11ES2FormatInfo(DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D32_FLOAT, UnreachableLoadFunction )));
379 map.insert(D3D11ES2FormatPair(GL_DEPTH24_STENCIL8_OES, D3D11ES2FormatInfo(DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D24_UNORM_S8_UINT, UnreachableLoadFunction )));
380 map.insert(D3D11ES2FormatPair(GL_STENCIL_INDEX8, D3D11ES2FormatInfo(DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D24_UNORM_S8_UINT, UnreachableLoadFunction )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000381
382 map.insert(D3D11ES2FormatPair(GL_RGBA32F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, loadRGBAFloatDataToRGBA )));
Geoff Lang1c3192e2013-07-22 13:59:24 -0400383 map.insert(D3D11ES2FormatPair(GL_RGB32F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, loadRGBFloatDataToRGBA )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000384 map.insert(D3D11ES2FormatPair(GL_ALPHA32F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, loadAlphaFloatDataToRGBA )));
Geoff Lang95f9f982013-10-21 17:09:19 -0400385 map.insert(D3D11ES2FormatPair(GL_LUMINANCE32F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, loadLuminanceFloatDataToRGBA )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000386 map.insert(D3D11ES2FormatPair(GL_LUMINANCE_ALPHA32F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, loadLuminanceAlphaFloatDataToRGBA )));
387
388 map.insert(D3D11ES2FormatPair(GL_RGBA16F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, loadRGBAHalfFloatDataToRGBA )));
389 map.insert(D3D11ES2FormatPair(GL_RGB16F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, loadRGBHalfFloatDataToRGBA )));
390 map.insert(D3D11ES2FormatPair(GL_ALPHA16F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, loadAlphaHalfFloatDataToRGBA )));
391 map.insert(D3D11ES2FormatPair(GL_LUMINANCE16F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, loadLuminanceHalfFloatDataToRGBA )));
392 map.insert(D3D11ES2FormatPair(GL_LUMINANCE_ALPHA16F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, loadLuminanceAlphaHalfFloatDataToRGBA )));
393
394 map.insert(D3D11ES2FormatPair(GL_ALPHA8_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN, loadAlphaDataToNative )));
395 map.insert(D3D11ES2FormatPair(GL_LUMINANCE8_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadLuminanceDataToBGRA )));
396 map.insert(D3D11ES2FormatPair(GL_LUMINANCE8_ALPHA8_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadLuminanceAlphaDataToBGRA )));
397
398 map.insert(D3D11ES2FormatPair(GL_RGB8_OES, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadRGBUByteDataToRGBA )));
399 map.insert(D3D11ES2FormatPair(GL_RGB565, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadRGB565DataToRGBA )));
400 map.insert(D3D11ES2FormatPair(GL_RGBA8_OES, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadRGBAUByteDataToNative )));
401 map.insert(D3D11ES2FormatPair(GL_RGBA4, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadRGBA4444DataToRGBA )));
402 map.insert(D3D11ES2FormatPair(GL_RGB5_A1, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadRGBA5551DataToRGBA )));
403 map.insert(D3D11ES2FormatPair(GL_BGRA8_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadBGRADataToBGRA )));
404 map.insert(D3D11ES2FormatPair(GL_BGRA4_ANGLEX, D3D11ES2FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadRGBA4444DataToRGBA )));
405 map.insert(D3D11ES2FormatPair(GL_BGR5_A1_ANGLEX, D3D11ES2FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, loadRGBA5551DataToRGBA )));
406
Geoff Lang632192d2013-10-04 13:40:46 -0400407 // From GL_EXT_texture_rg
408 map.insert(D3D11ES2FormatPair(GL_R8_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN, loadToNative<GLubyte, 1> )));
409 map.insert(D3D11ES2FormatPair(GL_R32F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, loadToNative<GLfloat, 1> )));
410 map.insert(D3D11ES2FormatPair(GL_R16F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN, loadToNative<GLhalf, 1> )));
411 map.insert(D3D11ES2FormatPair(GL_RG8_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_UNKNOWN, loadToNative<GLubyte, 2> )));
412 map.insert(D3D11ES2FormatPair(GL_RG32F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN, loadToNative<GLfloat, 2> )));
413 map.insert(D3D11ES2FormatPair(GL_RG16F_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_UNKNOWN, loadToNative<GLhalf, 2> )));
414
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000415 map.insert(D3D11ES2FormatPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, loadCompressedBlockDataToNative<4, 4, 8>)));
416 map.insert(D3D11ES2FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, D3D11ES2FormatInfo(DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, loadCompressedBlockDataToNative<4, 4, 8>)));
417 map.insert(D3D11ES2FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, D3D11ES2FormatInfo(DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, loadCompressedBlockDataToNative<4, 4, 16>)));
418 map.insert(D3D11ES2FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, D3D11ES2FormatInfo(DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, loadCompressedBlockDataToNative<4, 4, 16>)));
419
420 return map;
421}
422
Geoff Lang005df412013-10-16 14:12:50 -0400423static bool GetD3D11ES2FormatInfo(GLenum internalFormat, GLuint clientVersion, D3D11ES2FormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000424{
Geoff Lang18591b72013-06-07 12:00:15 -0400425 static const D3D11ES2FormatMap formatMap = BuildD3D11ES2FormatMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000426 D3D11ES2FormatMap::const_iterator iter = formatMap.find(internalFormat);
427 if (iter != formatMap.end())
428 {
429 if (outFormatInfo)
430 {
431 *outFormatInfo = iter->second;
432 }
433 return true;
434 }
435 else
436 {
437 return false;
438 }
439}
440
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000441// A map to determine the pixel size and mipmap generation function of a given DXGI format
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000442struct DXGIFormatInfo
443{
444 GLuint mPixelBits;
445 GLuint mBlockWidth;
446 GLuint mBlockHeight;
Jamie Madill826f3d32014-01-29 09:26:49 -0500447 GLenum mComponentType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000448
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000449 MipGenerationFunction mMipGenerationFunction;
Geoff Langfe28ca02013-06-04 10:10:48 -0400450 ColorReadFunction mColorReadFunction;
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000451
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000452 DXGIFormatInfo()
Jamie Madill826f3d32014-01-29 09:26:49 -0500453 : mPixelBits(0), mBlockWidth(0), mBlockHeight(0), mComponentType(GL_NONE), mMipGenerationFunction(NULL),
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500454 mColorReadFunction(NULL)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000455 { }
456
Jamie Madill826f3d32014-01-29 09:26:49 -0500457 DXGIFormatInfo(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight, GLenum componentType,
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500458 MipGenerationFunction mipFunc, ColorReadFunction readFunc)
Jamie Madill826f3d32014-01-29 09:26:49 -0500459 : mPixelBits(pixelBits), mBlockWidth(blockWidth), mBlockHeight(blockHeight), mComponentType(componentType),
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500460 mMipGenerationFunction(mipFunc), mColorReadFunction(readFunc)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000461 { }
462};
463
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000464typedef std::map<DXGI_FORMAT, DXGIFormatInfo> DXGIFormatInfoMap;
465
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500466void AddDXGIFormat(DXGIFormatInfoMap *map, DXGI_FORMAT dxgiFormat, GLuint pixelBits, GLuint blockWidth, GLuint blockHeight,
Jamie Madill826f3d32014-01-29 09:26:49 -0500467 GLenum componentType, MipGenerationFunction mipFunc, ColorReadFunction readFunc)
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500468{
Jamie Madill826f3d32014-01-29 09:26:49 -0500469 map->insert(std::make_pair(dxgiFormat, DXGIFormatInfo(pixelBits, blockWidth, blockHeight, componentType, mipFunc, readFunc)));
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500470}
471
472static DXGIFormatInfoMap BuildDXGIFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000473{
474 DXGIFormatInfoMap map;
475
Jamie Madill826f3d32014-01-29 09:26:49 -0500476 // | DXGI format |S |W |H |Component Type | Mip generation function | Color read function
477 AddDXGIFormat(&map, DXGI_FORMAT_UNKNOWN, 0, 0, 0, GL_NONE, NULL, NULL);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000478
Jamie Madill826f3d32014-01-29 09:26:49 -0500479 AddDXGIFormat(&map, DXGI_FORMAT_A8_UNORM, 8, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<A8>, ReadColor<A8, GLfloat>);
480 AddDXGIFormat(&map, DXGI_FORMAT_R8_UNORM, 8, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8>, ReadColor<R8, GLfloat>);
481 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8G8>, ReadColor<R8G8, GLfloat>);
482 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_UNORM, 32, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8G8B8A8>, ReadColor<R8G8B8A8, GLfloat>);
483 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 32, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8G8B8A8>, ReadColor<R8G8B8A8, GLfloat>);
484 AddDXGIFormat(&map, DXGI_FORMAT_B8G8R8A8_UNORM, 32, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<B8G8R8A8>, ReadColor<B8G8R8A8, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000485
Jamie Madill826f3d32014-01-29 09:26:49 -0500486 AddDXGIFormat(&map, DXGI_FORMAT_R8_SNORM, 8, 1, 1, GL_SIGNED_NORMALIZED, GenerateMip<R8S>, ReadColor<R8S, GLfloat>);
487 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_SNORM, 16, 1, 1, GL_SIGNED_NORMALIZED, GenerateMip<R8G8S>, ReadColor<R8G8S, GLfloat>);
488 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_SNORM, 32, 1, 1, GL_SIGNED_NORMALIZED, GenerateMip<R8G8B8A8S>, ReadColor<R8G8B8A8S, GLfloat>);
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000489
Jamie Madill826f3d32014-01-29 09:26:49 -0500490 AddDXGIFormat(&map, DXGI_FORMAT_R8_UINT, 8, 1, 1, GL_UNSIGNED_INT, GenerateMip<R8>, ReadColor<R8, GLuint>);
491 AddDXGIFormat(&map, DXGI_FORMAT_R16_UINT, 16, 1, 1, GL_UNSIGNED_INT, GenerateMip<R16>, ReadColor<R16, GLuint>);
492 AddDXGIFormat(&map, DXGI_FORMAT_R32_UINT, 32, 1, 1, GL_UNSIGNED_INT, GenerateMip<R32>, ReadColor<R32, GLuint>);
493 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_UINT, 16, 1, 1, GL_UNSIGNED_INT, GenerateMip<R8G8>, ReadColor<R8G8, GLuint>);
494 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_UINT, 32, 1, 1, GL_UNSIGNED_INT, GenerateMip<R16G16>, ReadColor<R16G16, GLuint>);
495 AddDXGIFormat(&map, DXGI_FORMAT_R32G32_UINT, 64, 1, 1, GL_UNSIGNED_INT, GenerateMip<R32G32>, ReadColor<R32G32, GLuint>);
496 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32_UINT, 96, 1, 1, GL_UNSIGNED_INT, GenerateMip<R32G32B32>, ReadColor<R32G32B32, GLuint>);
497 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_UINT, 32, 1, 1, GL_UNSIGNED_INT, GenerateMip<R8G8B8A8>, ReadColor<R8G8B8A8, GLuint>);
498 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_UINT, 64, 1, 1, GL_UNSIGNED_INT, GenerateMip<R16G16B16A16>, ReadColor<R16G16B16A16, GLuint>);
499 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32A32_UINT, 128, 1, 1, GL_UNSIGNED_INT, GenerateMip<R32G32B32A32>, ReadColor<R32G32B32A32, GLuint>);
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000500
Jamie Madill826f3d32014-01-29 09:26:49 -0500501 AddDXGIFormat(&map, DXGI_FORMAT_R8_SINT, 8, 1, 1, GL_INT, GenerateMip<R8S>, ReadColor<R8S, GLint>);
502 AddDXGIFormat(&map, DXGI_FORMAT_R16_SINT, 16, 1, 1, GL_INT, GenerateMip<R16S>, ReadColor<R16S, GLint>);
503 AddDXGIFormat(&map, DXGI_FORMAT_R32_SINT, 32, 1, 1, GL_INT, GenerateMip<R32S>, ReadColor<R32S, GLint>);
504 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_SINT, 16, 1, 1, GL_INT, GenerateMip<R8G8S>, ReadColor<R8G8S, GLint>);
505 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_SINT, 32, 1, 1, GL_INT, GenerateMip<R16G16S>, ReadColor<R16G16S, GLint>);
506 AddDXGIFormat(&map, DXGI_FORMAT_R32G32_SINT, 64, 1, 1, GL_INT, GenerateMip<R32G32S>, ReadColor<R32G32S, GLint>);
507 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32_SINT, 96, 1, 1, GL_INT, GenerateMip<R32G32B32S>, ReadColor<R32G32B32S, GLint>);
508 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_SINT, 32, 1, 1, GL_INT, GenerateMip<R8G8B8A8S>, ReadColor<R8G8B8A8S, GLint>);
509 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_SINT, 64, 1, 1, GL_INT, GenerateMip<R16G16B16A16S>, ReadColor<R16G16B16A16S, GLint>);
510 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32A32_SINT, 128, 1, 1, GL_INT, GenerateMip<R32G32B32A32S>, ReadColor<R32G32B32A32S, GLint>);
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000511
Jamie Madill826f3d32014-01-29 09:26:49 -0500512 AddDXGIFormat(&map, DXGI_FORMAT_R10G10B10A2_UNORM, 32, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R10G10B10A2>, ReadColor<R10G10B10A2, GLfloat>);
513 AddDXGIFormat(&map, DXGI_FORMAT_R10G10B10A2_UINT, 32, 1, 1, GL_UNSIGNED_INT, GenerateMip<R10G10B10A2>, ReadColor<R10G10B10A2, GLuint>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000514
Jamie Madill826f3d32014-01-29 09:26:49 -0500515 AddDXGIFormat(&map, DXGI_FORMAT_R16_FLOAT, 16, 1, 1, GL_FLOAT, GenerateMip<R16F>, ReadColor<R16F, GLfloat>);
516 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_FLOAT, 32, 1, 1, GL_FLOAT, GenerateMip<R16G16F>, ReadColor<R16G16F, GLfloat>);
517 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_FLOAT, 64, 1, 1, GL_FLOAT, GenerateMip<R16G16B16A16F>, ReadColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000518
Jamie Madill826f3d32014-01-29 09:26:49 -0500519 AddDXGIFormat(&map, DXGI_FORMAT_R32_FLOAT, 32, 1, 1, GL_FLOAT, GenerateMip<R32F>, ReadColor<R32F, GLfloat>);
520 AddDXGIFormat(&map, DXGI_FORMAT_R32G32_FLOAT, 64, 1, 1, GL_FLOAT, GenerateMip<R32G32F>, ReadColor<R32G32F, GLfloat>);
521 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32_FLOAT, 96, 1, 1, GL_FLOAT, NULL, NULL);
522 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32A32_FLOAT, 128, 1, 1, GL_FLOAT, GenerateMip<R32G32B32A32F>, ReadColor<R32G32B32A32F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000523
Jamie Madill826f3d32014-01-29 09:26:49 -0500524 AddDXGIFormat(&map, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 32, 1, 1, GL_FLOAT, GenerateMip<R9G9B9E5>, ReadColor<R9G9B9E5, GLfloat>);
525 AddDXGIFormat(&map, DXGI_FORMAT_R11G11B10_FLOAT, 32, 1, 1, GL_FLOAT, GenerateMip<R11G11B10F>, ReadColor<R11G11B10F, GLfloat>);
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000526
Jamie Madill826f3d32014-01-29 09:26:49 -0500527 AddDXGIFormat(&map, DXGI_FORMAT_R16_TYPELESS, 16, 1, 1, GL_NONE, NULL, NULL);
528 AddDXGIFormat(&map, DXGI_FORMAT_R16_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
529 AddDXGIFormat(&map, DXGI_FORMAT_D16_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
530 AddDXGIFormat(&map, DXGI_FORMAT_R24G8_TYPELESS, 32, 1, 1, GL_NONE, NULL, NULL);
531 AddDXGIFormat(&map, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, 32, 1, 1, GL_NONE, NULL, NULL);
532 AddDXGIFormat(&map, DXGI_FORMAT_D24_UNORM_S8_UINT, 32, 1, 1, GL_UNSIGNED_INT, NULL, NULL);
533 AddDXGIFormat(&map, DXGI_FORMAT_R32G8X24_TYPELESS, 64, 1, 1, GL_NONE, NULL, NULL);
534 AddDXGIFormat(&map, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, 64, 1, 1, GL_NONE, NULL, NULL);
535 AddDXGIFormat(&map, DXGI_FORMAT_D32_FLOAT_S8X24_UINT, 64, 1, 1, GL_UNSIGNED_INT, NULL, NULL);
536 AddDXGIFormat(&map, DXGI_FORMAT_R32_TYPELESS, 32, 1, 1, GL_NONE, NULL, NULL);
537 AddDXGIFormat(&map, DXGI_FORMAT_D32_FLOAT, 32, 1, 1, GL_FLOAT, NULL, NULL);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000538
Jamie Madill826f3d32014-01-29 09:26:49 -0500539 AddDXGIFormat(&map, DXGI_FORMAT_BC1_UNORM, 64, 4, 4, GL_UNSIGNED_NORMALIZED, NULL, NULL);
540 AddDXGIFormat(&map, DXGI_FORMAT_BC2_UNORM, 128, 4, 4, GL_UNSIGNED_NORMALIZED, NULL, NULL);
541 AddDXGIFormat(&map, DXGI_FORMAT_BC3_UNORM, 128, 4, 4, GL_UNSIGNED_NORMALIZED, NULL, NULL);
542
543 // Useful formats for vertex buffers
544 AddDXGIFormat(&map, DXGI_FORMAT_R16_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
545 AddDXGIFormat(&map, DXGI_FORMAT_R16_SNORM, 16, 1, 1, GL_SIGNED_NORMALIZED, NULL, NULL);
546 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_UNORM, 32, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
547 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_SNORM, 32, 1, 1, GL_SIGNED_NORMALIZED, NULL, NULL);
548 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_UNORM, 64, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
549 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_SNORM, 64, 1, 1, GL_SIGNED_NORMALIZED, NULL, NULL);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000550
551 return map;
552}
553
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500554typedef std::map<DXGI_FORMAT, GLenum> DXGIToESFormatMap;
Jamie Madill707dbd72013-07-10 15:13:39 -0400555
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500556inline void AddDXGIToESEntry(DXGIToESFormatMap *map, DXGI_FORMAT key, GLenum value)
557{
558 map->insert(std::make_pair(key, value));
559}
560
561static DXGIToESFormatMap BuildCommonDXGIToESFormatMap()
562{
563 DXGIToESFormatMap map;
564
565 AddDXGIToESEntry(&map, DXGI_FORMAT_UNKNOWN, GL_NONE);
566
567 AddDXGIToESEntry(&map, DXGI_FORMAT_A8_UNORM, GL_ALPHA8_EXT);
568 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_UNORM, GL_R8);
569 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_UNORM, GL_RG8);
570 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_UNORM, GL_RGBA8);
571 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, GL_SRGB8_ALPHA8);
572 AddDXGIToESEntry(&map, DXGI_FORMAT_B8G8R8A8_UNORM, GL_BGRA8_EXT);
573
574 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_SNORM, GL_R8_SNORM);
575 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_SNORM, GL_RG8_SNORM);
576 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_SNORM, GL_RGBA8_SNORM);
577
578 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_UINT, GL_R8UI);
579 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_UINT, GL_R16UI);
580 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_UINT, GL_R32UI);
581 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_UINT, GL_RG8UI);
582 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16_UINT, GL_RG16UI);
583 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32_UINT, GL_RG32UI);
584 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32_UINT, GL_RGB32UI);
585 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_UINT, GL_RGBA8UI);
586 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16B16A16_UINT, GL_RGBA16UI);
587 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32A32_UINT, GL_RGBA32UI);
588
589 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_SINT, GL_R8I);
590 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_SINT, GL_R16I);
591 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_SINT, GL_R32I);
592 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_SINT, GL_RG8I);
593 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16_SINT, GL_RG16I);
594 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32_SINT, GL_RG32I);
595 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32_SINT, GL_RGB32I);
596 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_SINT, GL_RGBA8I);
597 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16B16A16_SINT, GL_RGBA16I);
598 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32A32_SINT, GL_RGBA32I);
599
600 AddDXGIToESEntry(&map, DXGI_FORMAT_R10G10B10A2_UNORM, GL_RGB10_A2);
601 AddDXGIToESEntry(&map, DXGI_FORMAT_R10G10B10A2_UINT, GL_RGB10_A2UI);
602
603 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_FLOAT, GL_R16F);
604 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16_FLOAT, GL_RG16F);
605 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16B16A16_FLOAT, GL_RGBA16F);
606
607 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_FLOAT, GL_R32F);
608 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32_FLOAT, GL_RG32F);
609 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32_FLOAT, GL_RGB32F);
610 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32A32_FLOAT, GL_RGBA32F);
611
612 AddDXGIToESEntry(&map, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, GL_RGB9_E5);
613 AddDXGIToESEntry(&map, DXGI_FORMAT_R11G11B10_FLOAT, GL_R11F_G11F_B10F);
614
615 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_TYPELESS, GL_DEPTH_COMPONENT16);
616 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_UNORM, GL_DEPTH_COMPONENT16);
617 AddDXGIToESEntry(&map, DXGI_FORMAT_D16_UNORM, GL_DEPTH_COMPONENT16);
618 AddDXGIToESEntry(&map, DXGI_FORMAT_R24G8_TYPELESS, GL_DEPTH24_STENCIL8_OES);
619 AddDXGIToESEntry(&map, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, GL_DEPTH24_STENCIL8_OES);
620 AddDXGIToESEntry(&map, DXGI_FORMAT_D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8_OES);
621 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G8X24_TYPELESS, GL_DEPTH32F_STENCIL8);
622 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, GL_DEPTH32F_STENCIL8);
623 AddDXGIToESEntry(&map, DXGI_FORMAT_D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8);
624
625 AddDXGIToESEntry(&map, DXGI_FORMAT_BC1_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
626 AddDXGIToESEntry(&map, DXGI_FORMAT_BC2_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
627 AddDXGIToESEntry(&map, DXGI_FORMAT_BC3_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Jamie Madill707dbd72013-07-10 15:13:39 -0400628
629 return map;
630}
631
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500632static DXGIToESFormatMap BuildDXGIToES2FormatMap()
Jamie Madill707dbd72013-07-10 15:13:39 -0400633{
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500634 DXGIToESFormatMap map = BuildCommonDXGIToESFormatMap();
Jamie Madill707dbd72013-07-10 15:13:39 -0400635
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500636 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_TYPELESS, GL_DEPTH_COMPONENT32_OES);
637 AddDXGIToESEntry(&map, DXGI_FORMAT_D32_FLOAT, GL_DEPTH_COMPONENT32_OES);
Jamie Madill707dbd72013-07-10 15:13:39 -0400638
639 return map;
640}
641
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500642static DXGIToESFormatMap BuildDXGIToES3FormatMap()
Jamie Madill707dbd72013-07-10 15:13:39 -0400643{
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500644 DXGIToESFormatMap map = BuildCommonDXGIToESFormatMap();
Jamie Madill707dbd72013-07-10 15:13:39 -0400645
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500646 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_TYPELESS, GL_DEPTH_COMPONENT32F);
647 AddDXGIToESEntry(&map, DXGI_FORMAT_D32_FLOAT, GL_DEPTH_COMPONENT32F);
648
649 return map;
Geoff Lang61e49a52013-05-29 10:22:58 -0400650}
651
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500652static const DXGIFormatInfoMap &GetDXGIFormatInfoMap()
Geoff Lang61e49a52013-05-29 10:22:58 -0400653{
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500654 static const DXGIFormatInfoMap infoMap = BuildDXGIFormatInfoMap();
655 return infoMap;
656}
657
658static bool GetDXGIFormatInfo(DXGI_FORMAT format, DXGIFormatInfo *outFormatInfo)
659{
660 const DXGIFormatInfoMap &infoMap = GetDXGIFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000661 DXGIFormatInfoMap::const_iterator iter = infoMap.find(format);
662 if (iter != infoMap.end())
663 {
664 if (outFormatInfo)
665 {
666 *outFormatInfo = iter->second;
667 }
668 return true;
669 }
670 else
671 {
672 return false;
673 }
674}
675
Geoff Lang61e49a52013-05-29 10:22:58 -0400676static d3d11::DXGIFormatSet BuildAllDXGIFormatSet()
677{
678 d3d11::DXGIFormatSet set;
679
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500680 const DXGIFormatInfoMap &infoMap = GetDXGIFormatInfoMap();
681 for (DXGIFormatInfoMap::const_iterator i = infoMap.begin(); i != infoMap.end(); ++i)
Geoff Lang61e49a52013-05-29 10:22:58 -0400682 {
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500683 set.insert(i->first);
Geoff Lang61e49a52013-05-29 10:22:58 -0400684 }
685
686 return set;
687}
688
Geoff Langfe28ca02013-06-04 10:10:48 -0400689struct D3D11FastCopyFormat
690{
691 DXGI_FORMAT mSourceFormat;
692 GLenum mDestFormat;
693 GLenum mDestType;
694
695 D3D11FastCopyFormat(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType)
696 : mSourceFormat(sourceFormat), mDestFormat(destFormat), mDestType(destType)
697 { }
698
699 bool operator<(const D3D11FastCopyFormat& other) const
700 {
701 return memcmp(this, &other, sizeof(D3D11FastCopyFormat)) < 0;
702 }
703};
704
705typedef std::map<D3D11FastCopyFormat, ColorCopyFunction> D3D11FastCopyMap;
706typedef std::pair<D3D11FastCopyFormat, ColorCopyFunction> D3D11FastCopyPair;
707
708static D3D11FastCopyMap BuildFastCopyMap()
709{
710 D3D11FastCopyMap map;
711
712 map.insert(D3D11FastCopyPair(D3D11FastCopyFormat(DXGI_FORMAT_B8G8R8A8_UNORM, GL_RGBA, GL_UNSIGNED_BYTE), CopyBGRAUByteToRGBAUByte));
713
714 return map;
715}
716
Geoff Langd8c86132013-06-12 11:17:24 -0400717struct DXGIDepthStencilInfo
718{
719 unsigned int mDepthBits;
720 unsigned int mDepthOffset;
721 unsigned int mStencilBits;
722 unsigned int mStencilOffset;
723
724 DXGIDepthStencilInfo()
725 : mDepthBits(0), mDepthOffset(0), mStencilBits(0), mStencilOffset(0)
726 { }
727
728 DXGIDepthStencilInfo(unsigned int depthBits, unsigned int depthOffset, unsigned int stencilBits, unsigned int stencilOffset)
729 : mDepthBits(depthBits), mDepthOffset(depthOffset), mStencilBits(stencilBits), mStencilOffset(stencilOffset)
730 { }
731};
732
733typedef std::map<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoMap;
734typedef std::pair<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoPair;
735
736static DepthStencilInfoMap BuildDepthStencilInfoMap()
737{
738 DepthStencilInfoMap map;
739
740 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R16_TYPELESS, DXGIDepthStencilInfo(16, 0, 0, 0)));
741 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R16_UNORM, DXGIDepthStencilInfo(16, 0, 0, 0)));
742 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D16_UNORM, DXGIDepthStencilInfo(16, 0, 0, 0)));
743
744 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R24G8_TYPELESS, DXGIDepthStencilInfo(24, 0, 8, 24)));
745 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGIDepthStencilInfo(24, 0, 8, 24)));
746 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D24_UNORM_S8_UINT, DXGIDepthStencilInfo(24, 0, 8, 24)));
747
748 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32_TYPELESS, DXGIDepthStencilInfo(32, 0, 0, 0)));
749 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32_FLOAT, DXGIDepthStencilInfo(32, 0, 0, 0)));
750 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D32_FLOAT, DXGIDepthStencilInfo(32, 0, 0, 0)));
751
752 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32G8X24_TYPELESS, DXGIDepthStencilInfo(32, 0, 8, 32)));
753 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGIDepthStencilInfo(32, 0, 8, 32)));
754 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, DXGIDepthStencilInfo(32, 0, 8, 32)));
755
756 return map;
757}
758
759static const DepthStencilInfoMap &GetDepthStencilInfoMap()
760{
761 static const DepthStencilInfoMap infoMap = BuildDepthStencilInfoMap();
762 return infoMap;
763}
764
765bool GetDepthStencilInfo(DXGI_FORMAT format, DXGIDepthStencilInfo *outDepthStencilInfo)
766{
767 const DepthStencilInfoMap& infoMap = GetDepthStencilInfoMap();
768 DepthStencilInfoMap::const_iterator iter = infoMap.find(format);
769 if (iter != infoMap.end())
770 {
771 if (outDepthStencilInfo)
772 {
773 *outDepthStencilInfo = iter->second;
774 }
775 return true;
776 }
777 else
778 {
779 return false;
780 }
781}
782
Geoff Lang00f6bc32013-09-20 14:59:06 -0400783struct SwizzleSizeType
784{
785 unsigned int mMaxComponentSize;
786 GLenum mComponentType;
787
788 SwizzleSizeType()
789 : mMaxComponentSize(0), mComponentType(GL_NONE)
790 { }
791
792 SwizzleSizeType(unsigned int maxComponentSize, GLenum componentType)
793 : mMaxComponentSize(maxComponentSize), mComponentType(componentType)
794 { }
795
796 bool operator<(const SwizzleSizeType& other) const
797 {
798 return (mMaxComponentSize != other.mMaxComponentSize) ? (mMaxComponentSize < other.mMaxComponentSize)
799 : (mComponentType < other.mComponentType);
800 }
801};
802
803struct SwizzleFormatInfo
804{
805 DXGI_FORMAT mTexFormat;
806 DXGI_FORMAT mSRVFormat;
807 DXGI_FORMAT mRTVFormat;
808
809 SwizzleFormatInfo()
810 : mTexFormat(DXGI_FORMAT_UNKNOWN), mSRVFormat(DXGI_FORMAT_UNKNOWN), mRTVFormat(DXGI_FORMAT_UNKNOWN)
811 { }
812
813 SwizzleFormatInfo(DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat)
814 : mTexFormat(texFormat), mSRVFormat(srvFormat), mRTVFormat(rtvFormat)
815 { }
816};
817
818typedef std::map<SwizzleSizeType, SwizzleFormatInfo> SwizzleInfoMap;
819typedef std::pair<SwizzleSizeType, SwizzleFormatInfo> SwizzleInfoPair;
820
821static SwizzleInfoMap BuildSwizzleInfoMap()
822{
823 SwizzleInfoMap map;
824
825 map.insert(SwizzleInfoPair(SwizzleSizeType( 8, GL_UNSIGNED_NORMALIZED), SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM )));
Geoff Lang67938ef2014-01-07 16:17:21 -0500826 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_UNSIGNED_NORMALIZED), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM)));
827 map.insert(SwizzleInfoPair(SwizzleSizeType(24, GL_UNSIGNED_NORMALIZED), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT)));
828 map.insert(SwizzleInfoPair(SwizzleSizeType(32, GL_UNSIGNED_NORMALIZED), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT)));
Geoff Lang00f6bc32013-09-20 14:59:06 -0400829
830 map.insert(SwizzleInfoPair(SwizzleSizeType( 8, GL_SIGNED_NORMALIZED ), SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM )));
831
832 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_FLOAT ), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT)));
833 map.insert(SwizzleInfoPair(SwizzleSizeType(32, GL_FLOAT ), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT)));
834
835 map.insert(SwizzleInfoPair(SwizzleSizeType( 8, GL_UNSIGNED_INT ), SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT )));
836 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_UNSIGNED_INT ), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT )));
837 map.insert(SwizzleInfoPair(SwizzleSizeType(32, GL_UNSIGNED_INT ), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT )));
838
839 map.insert(SwizzleInfoPair(SwizzleSizeType( 8, GL_INT ), SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT )));
840 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_INT ), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT )));
841 map.insert(SwizzleInfoPair(SwizzleSizeType(32, GL_INT ), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT )));
842
843 return map;
844}
Geoff Lang0c99b1b2013-09-30 15:07:43 -0400845typedef std::pair<GLint, InitializeTextureDataFunction> InternalFormatInitializerPair;
846typedef std::map<GLint, InitializeTextureDataFunction> InternalFormatInitializerMap;
847
848static InternalFormatInitializerMap BuildInternalFormatInitializerMap()
849{
850 InternalFormatInitializerMap map;
851
852 map.insert(InternalFormatInitializerPair(GL_RGB8, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF> ));
853 map.insert(InternalFormatInitializerPair(GL_RGB565, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF> ));
854 map.insert(InternalFormatInitializerPair(GL_SRGB8, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF> ));
855 map.insert(InternalFormatInitializerPair(GL_RGB16F, initialize4ComponentData<GLhalf, 0x0000, 0x0000, 0x0000, gl::Float16One>));
856 map.insert(InternalFormatInitializerPair(GL_RGB32F, initialize4ComponentData<GLfloat, 0x00000000, 0x00000000, 0x00000000, gl::Float32One>));
857 map.insert(InternalFormatInitializerPair(GL_RGB8UI, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0x01> ));
858 map.insert(InternalFormatInitializerPair(GL_RGB8I, initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x01> ));
859 map.insert(InternalFormatInitializerPair(GL_RGB16UI, initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x0001> ));
860 map.insert(InternalFormatInitializerPair(GL_RGB16I, initialize4ComponentData<GLshort, 0x0000, 0x0000, 0x0000, 0x0001> ));
861 map.insert(InternalFormatInitializerPair(GL_RGB32UI, initialize4ComponentData<GLuint, 0x00000000, 0x00000000, 0x00000000, 0x00000001> ));
862 map.insert(InternalFormatInitializerPair(GL_RGB32I, initialize4ComponentData<GLint, 0x00000000, 0x00000000, 0x00000000, 0x00000001> ));
863
864 return map;
865}
Geoff Lang00f6bc32013-09-20 14:59:06 -0400866
867static const SwizzleInfoMap &GetSwizzleInfoMap()
868{
869 static const SwizzleInfoMap map = BuildSwizzleInfoMap();
870 return map;
871}
872
873static const SwizzleFormatInfo GetSwizzleFormatInfo(GLint internalFormat, GLuint clientVersion)
874{
875 // Get the maximum sized component
Jamie Madill80b5a552014-01-03 10:57:11 -0500876 unsigned int maxBits = 1;
877
878 if (gl::IsFormatCompressed(internalFormat, clientVersion))
879 {
Geoff Lang67938ef2014-01-07 16:17:21 -0500880 unsigned int compressedBitsPerBlock = gl::GetPixelBytes(internalFormat, clientVersion) * 8;
881 unsigned int blockSize = gl::GetCompressedBlockWidth(internalFormat, clientVersion) *
882 gl::GetCompressedBlockHeight(internalFormat, clientVersion);
883 maxBits = std::max(compressedBitsPerBlock / blockSize, maxBits);
Jamie Madill80b5a552014-01-03 10:57:11 -0500884 }
885 else
886 {
887 maxBits = std::max(maxBits, gl::GetAlphaBits( internalFormat, clientVersion));
888 maxBits = std::max(maxBits, gl::GetRedBits( internalFormat, clientVersion));
889 maxBits = std::max(maxBits, gl::GetGreenBits( internalFormat, clientVersion));
890 maxBits = std::max(maxBits, gl::GetBlueBits( internalFormat, clientVersion));
891 maxBits = std::max(maxBits, gl::GetLuminanceBits(internalFormat, clientVersion));
892 maxBits = std::max(maxBits, gl::GetDepthBits( internalFormat, clientVersion));
893 }
894
Geoff Lang00f6bc32013-09-20 14:59:06 -0400895 maxBits = roundUp(maxBits, 8U);
896
897 GLenum componentType = gl::GetComponentType(internalFormat, clientVersion);
898
899 const SwizzleInfoMap &map = GetSwizzleInfoMap();
900 SwizzleInfoMap::const_iterator iter = map.find(SwizzleSizeType(maxBits, componentType));
901
902 if (iter != map.end())
903 {
904 return iter->second;
905 }
906 else
907 {
908 UNREACHABLE();
909 static const SwizzleFormatInfo defaultFormatInfo;
910 return defaultFormatInfo;
911 }
912}
913
Geoff Lang0c99b1b2013-09-30 15:07:43 -0400914static const InternalFormatInitializerMap &GetInternalFormatInitializerMap()
915{
916 static const InternalFormatInitializerMap map = BuildInternalFormatInitializerMap();
917 return map;
918}
919
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000920namespace d3d11
921{
922
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500923MipGenerationFunction GetMipGenerationFunction(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000924{
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000925 DXGIFormatInfo formatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500926 if (GetDXGIFormatInfo(format, &formatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000927 {
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000928 return formatInfo.mMipGenerationFunction;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000929 }
930 else
931 {
932 UNREACHABLE();
933 return NULL;
934 }
935}
936
Geoff Lang005df412013-10-16 14:12:50 -0400937LoadImageFunction GetImageLoadFunction(GLenum internalFormat, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000938{
939 if (clientVersion == 2)
940 {
941 D3D11ES2FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -0400942 if (GetD3D11ES2FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000943 {
944 return d3d11FormatInfo.mLoadImageFunction;
945 }
946 else
947 {
948 UNREACHABLE();
949 return NULL;
950 }
951 }
952 else if (clientVersion == 3)
953 {
954 static const D3D11LoadFunctionMap loadImageMap = buildD3D11LoadFunctionMap();
955 D3D11LoadFunctionMap::const_iterator iter = loadImageMap.find(InternalFormatTypePair(internalFormat, type));
956 if (iter != loadImageMap.end())
957 {
958 return iter->second;
959 }
960 else
961 {
962 UNREACHABLE();
963 return NULL;
964 }
965 }
966 else
967 {
968 UNREACHABLE();
969 return NULL;
970 }
971}
972
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500973GLuint GetFormatPixelBytes(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000974{
975 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500976 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000977 {
978 return dxgiFormatInfo.mPixelBits / 8;
979 }
980 else
981 {
982 UNREACHABLE();
983 return 0;
984 }
985}
986
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500987GLuint GetBlockWidth(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000988{
989 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500990 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000991 {
992 return dxgiFormatInfo.mBlockWidth;
993 }
994 else
995 {
996 UNREACHABLE();
997 return 0;
998 }
999}
1000
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001001GLuint GetBlockHeight(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001002{
1003 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001004 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001005 {
1006 return dxgiFormatInfo.mBlockHeight;
1007 }
1008 else
1009 {
1010 UNREACHABLE();
1011 return 0;
1012 }
1013}
1014
Jamie Madill826f3d32014-01-29 09:26:49 -05001015GLenum GetComponentType(DXGI_FORMAT format)
1016{
1017 DXGIFormatInfo dxgiFormatInfo;
1018 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
1019 {
1020 return dxgiFormatInfo.mComponentType;
1021 }
1022 else
1023 {
1024 UNREACHABLE();
1025 return GL_NONE;
1026 }
1027}
1028
Geoff Langd8c86132013-06-12 11:17:24 -04001029GLuint GetDepthBits(DXGI_FORMAT format)
1030{
1031 DXGIDepthStencilInfo dxgiDSInfo;
1032 if (GetDepthStencilInfo(format, &dxgiDSInfo))
1033 {
1034 return dxgiDSInfo.mDepthBits;
1035 }
1036 else
1037 {
1038 // Since the depth stencil info map does not contain all used DXGI formats,
1039 // we should not assert that the format exists
1040 return 0;
1041 }
1042}
1043
1044GLuint GetDepthOffset(DXGI_FORMAT format)
1045{
1046 DXGIDepthStencilInfo dxgiDSInfo;
1047 if (GetDepthStencilInfo(format, &dxgiDSInfo))
1048 {
1049 return dxgiDSInfo.mDepthOffset;
1050 }
1051 else
1052 {
1053 // Since the depth stencil info map does not contain all used DXGI formats,
1054 // we should not assert that the format exists
1055 return 0;
1056 }
1057}
1058
1059GLuint GetStencilBits(DXGI_FORMAT format)
1060{
1061 DXGIDepthStencilInfo dxgiDSInfo;
1062 if (GetDepthStencilInfo(format, &dxgiDSInfo))
1063 {
1064 return dxgiDSInfo.mStencilBits;
1065 }
1066 else
1067 {
1068 // Since the depth stencil info map does not contain all used DXGI formats,
1069 // we should not assert that the format exists
1070 return 0;
1071 }
1072}
1073
1074GLuint GetStencilOffset(DXGI_FORMAT format)
1075{
1076 DXGIDepthStencilInfo dxgiDSInfo;
1077 if (GetDepthStencilInfo(format, &dxgiDSInfo))
1078 {
1079 return dxgiDSInfo.mStencilOffset;
1080 }
1081 else
1082 {
1083 // Since the depth stencil info map does not contain all used DXGI formats,
1084 // we should not assert that the format exists
1085 return 0;
1086 }
1087}
1088
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001089void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001090{
1091 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001092 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001093 {
1094 int upsampleCount = 0;
1095
1096 GLsizei blockWidth = dxgiFormatInfo.mBlockWidth;
1097 GLsizei blockHeight = dxgiFormatInfo.mBlockHeight;
1098
1099 // Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
1100 if (isImage || *requestWidth < blockWidth || *requestHeight < blockHeight)
1101 {
1102 while (*requestWidth % blockWidth != 0 || *requestHeight % blockHeight != 0)
1103 {
1104 *requestWidth <<= 1;
1105 *requestHeight <<= 1;
1106 upsampleCount++;
1107 }
1108 }
1109 *levelOffset = upsampleCount;
1110 }
1111 else
1112 {
1113 UNREACHABLE();
1114 }
1115}
1116
Geoff Lang61e49a52013-05-29 10:22:58 -04001117const DXGIFormatSet &GetAllUsedDXGIFormats()
1118{
1119 static DXGIFormatSet formatSet = BuildAllDXGIFormatSet();
1120 return formatSet;
1121}
1122
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001123ColorReadFunction GetColorReadFunction(DXGI_FORMAT format)
Geoff Langfe28ca02013-06-04 10:10:48 -04001124{
1125 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001126 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
Geoff Langfe28ca02013-06-04 10:10:48 -04001127 {
1128 return dxgiFormatInfo.mColorReadFunction;
1129 }
1130 else
1131 {
1132 UNREACHABLE();
1133 return NULL;
1134 }
1135}
1136
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001137ColorCopyFunction GetFastCopyFunction(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType)
Geoff Langfe28ca02013-06-04 10:10:48 -04001138{
1139 static const D3D11FastCopyMap fastCopyMap = BuildFastCopyMap();
1140 D3D11FastCopyMap::const_iterator iter = fastCopyMap.find(D3D11FastCopyFormat(sourceFormat, destFormat, destType));
1141 return (iter != fastCopyMap.end()) ? iter->second : NULL;
1142}
1143
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001144}
1145
1146namespace gl_d3d11
1147{
1148
Geoff Lang005df412013-10-16 14:12:50 -04001149DXGI_FORMAT GetTexFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001150{
1151 if (clientVersion == 2)
1152 {
1153 D3D11ES2FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001154 if (GetD3D11ES2FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001155 {
1156 return d3d11FormatInfo.mTexFormat;
1157 }
1158 else
1159 {
1160 UNREACHABLE();
1161 return DXGI_FORMAT_UNKNOWN;
1162 }
1163 }
1164 else if (clientVersion == 3)
1165 {
1166 D3D11ES3FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001167 if (GetD3D11ES3FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001168 {
1169 return d3d11FormatInfo.mTexFormat;
1170 }
1171 else
1172 {
1173 UNREACHABLE();
1174 return DXGI_FORMAT_UNKNOWN;
1175 }
1176 }
1177 else
1178 {
1179 UNREACHABLE();
1180 return DXGI_FORMAT_UNKNOWN;
1181 }
1182}
1183
Geoff Lang005df412013-10-16 14:12:50 -04001184DXGI_FORMAT GetSRVFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001185{
1186 if (clientVersion == 2)
1187 {
1188 D3D11ES2FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001189 if (GetD3D11ES2FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001190 {
1191 return d3d11FormatInfo.mSRVFormat;
1192 }
1193 else
1194 {
1195 UNREACHABLE();
1196 return DXGI_FORMAT_UNKNOWN;
1197 }
1198 }
1199 else if (clientVersion == 3)
1200 {
1201 D3D11ES3FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001202 if (GetD3D11ES3FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001203 {
1204 return d3d11FormatInfo.mSRVFormat;
1205 }
1206 else
1207 {
1208 UNREACHABLE();
1209 return DXGI_FORMAT_UNKNOWN;
1210 }
1211 }
1212 else
1213 {
1214 UNREACHABLE();
1215 return DXGI_FORMAT_UNKNOWN;
1216 }
1217}
1218
Geoff Lang005df412013-10-16 14:12:50 -04001219DXGI_FORMAT GetRTVFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001220{
1221 if (clientVersion == 2)
1222 {
1223 D3D11ES2FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001224 if (GetD3D11ES2FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001225 {
1226 return d3d11FormatInfo.mRTVFormat;
1227 }
1228 else
1229 {
1230 UNREACHABLE();
1231 return DXGI_FORMAT_UNKNOWN;
1232 }
1233 }
1234 else if (clientVersion == 3)
1235 {
1236 D3D11ES3FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001237 if (GetD3D11ES3FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001238 {
1239 return d3d11FormatInfo.mRTVFormat;
1240 }
1241 else
1242 {
1243 UNREACHABLE();
1244 return DXGI_FORMAT_UNKNOWN;
1245 }
1246 }
1247 else
1248 {
1249 UNREACHABLE();
1250 return DXGI_FORMAT_UNKNOWN;
1251 }
1252}
1253
Geoff Lang005df412013-10-16 14:12:50 -04001254DXGI_FORMAT GetDSVFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001255{
1256 if (clientVersion == 2)
1257 {
1258 D3D11ES2FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001259 if (GetD3D11ES2FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001260 {
1261 return d3d11FormatInfo.mDSVFormat;
1262 }
1263 else
1264 {
1265 return DXGI_FORMAT_UNKNOWN;
1266 }
1267 }
1268 else if (clientVersion == 3)
1269 {
1270 D3D11ES3FormatInfo d3d11FormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001271 if (GetD3D11ES3FormatInfo(internalFormat, clientVersion, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001272 {
1273 return d3d11FormatInfo.mDSVFormat;
1274 }
1275 else
1276 {
1277 return DXGI_FORMAT_UNKNOWN;
1278 }
1279 }
1280 else
1281 {
1282 UNREACHABLE();
1283 return DXGI_FORMAT_UNKNOWN;
1284 }
1285}
1286
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001287// Given a GL internal format, this function returns the DSV format if it is depth- or stencil-renderable,
1288// the RTV format if it is color-renderable, and the (nonrenderable) texture format otherwise.
Geoff Lang005df412013-10-16 14:12:50 -04001289DXGI_FORMAT GetRenderableFormat(GLenum internalFormat, GLuint clientVersion)
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001290{
1291 DXGI_FORMAT targetFormat = GetDSVFormat(internalFormat, clientVersion);
1292 if (targetFormat == DXGI_FORMAT_UNKNOWN)
1293 targetFormat = GetRTVFormat(internalFormat, clientVersion);
1294 if (targetFormat == DXGI_FORMAT_UNKNOWN)
1295 targetFormat = GetTexFormat(internalFormat, clientVersion);
1296
1297 return targetFormat;
1298}
1299
Geoff Lang00f6bc32013-09-20 14:59:06 -04001300DXGI_FORMAT GetSwizzleTexFormat(GLint internalFormat, const Renderer *renderer)
1301{
1302 GLuint clientVersion = renderer->getCurrentClientVersion();
1303 if (gl::GetComponentCount(internalFormat, clientVersion) != 4 || !gl::IsColorRenderingSupported(internalFormat, renderer))
1304 {
1305 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat, clientVersion);
1306 return swizzleInfo.mTexFormat;
1307 }
1308 else
1309 {
1310 return GetTexFormat(internalFormat, clientVersion);
1311 }
1312}
1313
1314DXGI_FORMAT GetSwizzleSRVFormat(GLint internalFormat, const Renderer *renderer)
1315{
1316 GLuint clientVersion = renderer->getCurrentClientVersion();
1317 if (gl::GetComponentCount(internalFormat, clientVersion) != 4 || !gl::IsColorRenderingSupported(internalFormat, renderer))
1318 {
1319 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat, clientVersion);
1320 return swizzleInfo.mSRVFormat;
1321 }
1322 else
1323 {
1324 return GetTexFormat(internalFormat, clientVersion);
1325 }
1326}
1327
1328DXGI_FORMAT GetSwizzleRTVFormat(GLint internalFormat, const Renderer *renderer)
1329{
1330 GLuint clientVersion = renderer->getCurrentClientVersion();
1331 if (gl::GetComponentCount(internalFormat, clientVersion) != 4 || !gl::IsColorRenderingSupported(internalFormat, renderer))
1332 {
1333 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat, clientVersion);
1334 return swizzleInfo.mRTVFormat;
1335 }
1336 else
1337 {
1338 return GetTexFormat(internalFormat, clientVersion);
1339 }
1340}
1341
Geoff Lang0c99b1b2013-09-30 15:07:43 -04001342bool RequiresTextureDataInitialization(GLint internalFormat)
1343{
1344 const InternalFormatInitializerMap &map = GetInternalFormatInitializerMap();
1345 return map.find(internalFormat) != map.end();
1346}
1347
1348InitializeTextureDataFunction GetTextureDataInitializationFunction(GLint internalFormat)
1349{
1350 const InternalFormatInitializerMap &map = GetInternalFormatInitializerMap();
1351 InternalFormatInitializerMap::const_iterator iter = map.find(internalFormat);
1352 if (iter != map.end())
1353 {
1354 return iter->second;
1355 }
1356 else
1357 {
1358 UNREACHABLE();
1359 return NULL;
1360 }
1361}
1362
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001363struct D3D11VertexFormatInfo
1364{
1365 rx::VertexConversionType mConversionType;
1366 DXGI_FORMAT mNativeFormat;
1367 VertexCopyFunction mCopyFunction;
1368
1369 D3D11VertexFormatInfo()
1370 : mConversionType(VERTEX_CONVERT_NONE),
1371 mNativeFormat(DXGI_FORMAT_UNKNOWN),
1372 mCopyFunction(NULL)
1373 {}
1374
1375 D3D11VertexFormatInfo(VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1376 : mConversionType(conversionType),
1377 mNativeFormat(nativeFormat),
1378 mCopyFunction(copyFunction)
1379 {}
1380};
1381
1382typedef std::map<gl::VertexFormat, D3D11VertexFormatInfo> D3D11VertexFormatInfoMap;
1383
1384typedef std::pair<gl::VertexFormat, D3D11VertexFormatInfo> D3D11VertexFormatPair;
1385
1386static void addVertexFormatInfo(D3D11VertexFormatInfoMap *map, GLenum inputType, GLboolean normalized, GLuint componentCount,
1387 VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1388{
1389 gl::VertexFormat inputFormat(inputType, normalized, componentCount, false);
1390 map->insert(D3D11VertexFormatPair(inputFormat, D3D11VertexFormatInfo(conversionType, nativeFormat, copyFunction)));
1391}
1392
1393static void addIntegerVertexFormatInfo(D3D11VertexFormatInfoMap *map, GLenum inputType, GLuint componentCount,
1394 VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1395{
1396 gl::VertexFormat inputFormat(inputType, GL_FALSE, componentCount, true);
1397 map->insert(D3D11VertexFormatPair(inputFormat, D3D11VertexFormatInfo(conversionType, nativeFormat, copyFunction)));
1398}
1399
1400static D3D11VertexFormatInfoMap BuildD3D11VertexFormatInfoMap()
1401{
1402 D3D11VertexFormatInfoMap map;
1403
1404 // TODO: column legend
1405
1406 //
1407 // Float formats
1408 //
1409
1410 // GL_BYTE -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001411 addVertexFormatInfo(&map, GL_BYTE, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_SINT, &copyVertexData<GLbyte, 1, 0>);
1412 addVertexFormatInfo(&map, GL_BYTE, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8_SINT, &copyVertexData<GLbyte, 2, 0>);
Jamie Madillca442ba2014-03-05 09:53:30 -05001413 addVertexFormatInfo(&map, GL_BYTE, GL_FALSE, 3, VERTEX_CONVERT_BOTH, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 3, 1>);
Jamie Madill2f612292014-03-05 09:53:29 -05001414 addVertexFormatInfo(&map, GL_BYTE, GL_FALSE, 4, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001415
1416 // GL_BYTE -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001417 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SNORM, &copyVertexData<GLbyte, 1, 0>);
1418 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SNORM, &copyVertexData<GLbyte, 2, 0>);
1419 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SNORM, &copyVertexData<GLbyte, 3, INT8_MAX>);
1420 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_SNORM, &copyVertexData<GLbyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001421
1422 // GL_UNSIGNED_BYTE -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001423 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_UINT, &copyVertexData<GLubyte, 1, 0>);
1424 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8_UINT, &copyVertexData<GLubyte, 2, 0>);
Jamie Madillca442ba2014-03-05 09:53:30 -05001425 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_FALSE, 3, VERTEX_CONVERT_BOTH, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 3, 1>);
Jamie Madill2f612292014-03-05 09:53:29 -05001426 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_FALSE, 4, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001427
1428 // GL_UNSIGNED_BYTE -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001429 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UNORM, &copyVertexData<GLubyte, 1, 0>);
1430 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UNORM, &copyVertexData<GLubyte, 2, 0>);
1431 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UNORM, &copyVertexData<GLubyte, 3, UINT8_MAX>);
1432 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_UNORM, &copyVertexData<GLubyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001433
1434 // GL_SHORT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001435 addVertexFormatInfo(&map, GL_SHORT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_SINT, &copyVertexData<GLshort, 1, 0>);
1436 addVertexFormatInfo(&map, GL_SHORT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16_SINT, &copyVertexData<GLshort, 2, 0>);
Jamie Madillca442ba2014-03-05 09:53:30 -05001437 addVertexFormatInfo(&map, GL_SHORT, GL_FALSE, 3, VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 4, 1>);
Jamie Madill2f612292014-03-05 09:53:29 -05001438 addVertexFormatInfo(&map, GL_SHORT, GL_FALSE, 4, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001439
1440 // GL_SHORT -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001441 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SNORM, &copyVertexData<GLshort, 1, 0>);
1442 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SNORM, &copyVertexData<GLshort, 2, 0>);
1443 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SNORM, &copyVertexData<GLshort, 3, INT16_MAX>);
1444 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_SNORM, &copyVertexData<GLshort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001445
1446 // GL_UNSIGNED_SHORT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001447 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_UINT, &copyVertexData<GLushort, 1, 0>);
1448 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16_UINT, &copyVertexData<GLushort, 2, 0>);
Jamie Madillca442ba2014-03-05 09:53:30 -05001449 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_FALSE, 3, VERTEX_CONVERT_BOTH, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 3, 1>);
Jamie Madill2f612292014-03-05 09:53:29 -05001450 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_FALSE, 4, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001451
1452 // GL_UNSIGNED_SHORT -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001453 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UNORM, &copyVertexData<GLushort, 1, 0>);
1454 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UNORM, &copyVertexData<GLushort, 2, 0>);
1455 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UNORM, &copyVertexData<GLushort, 3, UINT16_MAX>);
1456 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_UNORM, &copyVertexData<GLushort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001457
1458 // GL_INT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001459 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_SINT, &copyVertexData<GLint, 1, 0>);
1460 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLint, 2, 0>);
1461 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 3, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLint, 3, 0>);
1462 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 4, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32A32_SINT, &copyVertexData<GLint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001463
1464 // GL_INT -- normalized
1465 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 1, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, &copyToFloatVertexData<GLint, 1, true>);
1466 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 2, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, &copyToFloatVertexData<GLint, 2, true>);
1467 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyToFloatVertexData<GLint, 3, true>);
1468 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyToFloatVertexData<GLint, 4, true>);
1469
1470 // GL_UNSIGNED_INT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001471 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_UINT, &copyVertexData<GLuint, 1, 0>);
1472 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_UINT, &copyVertexData<GLuint, 2, 0>);
1473 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 3, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_UINT, &copyVertexData<GLuint, 3, 0>);
1474 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 4, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32A32_UINT, &copyVertexData<GLuint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001475
1476 // GL_UNSIGNED_INT -- normalized
1477 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_FLOAT, &copyToFloatVertexData<GLuint, 1, true>);
1478 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_FLOAT, &copyToFloatVertexData<GLuint, 2, true>);
1479 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyToFloatVertexData<GLuint, 3, true>);
1480 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyToFloatVertexData<GLuint, 4, true>);
1481
1482 // GL_FIXED
1483 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 1, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, &copyFixedVertexData<1>);
1484 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 2, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, &copyFixedVertexData<2>);
1485 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyFixedVertexData<3>);
1486 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyFixedVertexData<4>);
1487
1488 // GL_HALF_FLOAT
Jamie Madill2f612292014-03-05 09:53:29 -05001489 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_FLOAT, &copyVertexData<GLhalf, 1, 0>);
1490 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_FLOAT, &copyVertexData<GLhalf, 2, 0>);
1491 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_FLOAT, &copyVertexData<GLhalf, 3, gl::Float16One>);
1492 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_FLOAT, &copyVertexData<GLhalf, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001493
1494 // GL_FLOAT
Jamie Madill2f612292014-03-05 09:53:29 -05001495 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_FLOAT, &copyVertexData<GLfloat, 1, 0>);
1496 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_FLOAT, &copyVertexData<GLfloat, 2, 0>);
1497 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_FLOAT, &copyVertexData<GLfloat, 3, 0>);
1498 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyVertexData<GLfloat, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001499
1500 // GL_INT_2_10_10_10_REV
1501 addVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, GL_FALSE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyPackedVertexData<true, false, true>);
1502 addVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, GL_TRUE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyPackedVertexData<true, true, true>);
1503
1504 // GL_UNSIGNED_INT_2_10_10_10_REV
Jamie Madill0c667202014-03-17 10:06:09 -04001505 addVertexFormatInfo(&map, GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyPackedVertexData<false, false, true>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001506 addVertexFormatInfo(&map, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UNORM, &copyPackedUnsignedVertexData);
1507
1508 //
1509 // Integer Formats
1510 //
1511
1512 // GL_BYTE
Jamie Madill2f612292014-03-05 09:53:29 -05001513 addIntegerVertexFormatInfo(&map, GL_BYTE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SINT, &copyVertexData<GLbyte, 1, 0>);
1514 addIntegerVertexFormatInfo(&map, GL_BYTE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SINT, &copyVertexData<GLbyte, 2, 0>);
1515 addIntegerVertexFormatInfo(&map, GL_BYTE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 3, 1>);
1516 addIntegerVertexFormatInfo(&map, GL_BYTE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001517
1518 // GL_UNSIGNED_BYTE
Jamie Madill2f612292014-03-05 09:53:29 -05001519 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UINT, &copyVertexData<GLubyte, 1, 0>);
1520 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UINT, &copyVertexData<GLubyte, 2, 0>);
1521 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 3, 1>);
1522 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001523
1524 // GL_SHORT
Jamie Madill2f612292014-03-05 09:53:29 -05001525 addIntegerVertexFormatInfo(&map, GL_SHORT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SINT, &copyVertexData<GLshort, 1, 0>);
1526 addIntegerVertexFormatInfo(&map, GL_SHORT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SINT, &copyVertexData<GLshort, 2, 0>);
1527 addIntegerVertexFormatInfo(&map, GL_SHORT, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 3, 1>);
1528 addIntegerVertexFormatInfo(&map, GL_SHORT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001529
1530 // GL_UNSIGNED_SHORT
Jamie Madill2f612292014-03-05 09:53:29 -05001531 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UINT, &copyVertexData<GLushort, 1, 0>);
1532 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UINT, &copyVertexData<GLushort, 2, 0>);
1533 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 3, 1>);
1534 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001535
1536 // GL_INT
Jamie Madill2f612292014-03-05 09:53:29 -05001537 addIntegerVertexFormatInfo(&map, GL_INT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, &copyVertexData<GLint, 1, 0>);
1538 addIntegerVertexFormatInfo(&map, GL_INT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLint, 2, 0>);
1539 addIntegerVertexFormatInfo(&map, GL_INT, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLint, 3, 0>);
1540 addIntegerVertexFormatInfo(&map, GL_INT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, &copyVertexData<GLint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001541
1542 // GL_UNSIGNED_INT
Jamie Madill2f612292014-03-05 09:53:29 -05001543 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, &copyVertexData<GLuint, 1, 0>);
1544 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLuint, 2, 0>);
1545 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLuint, 3, 0>);
1546 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, &copyVertexData<GLuint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001547
1548 // GL_INT_2_10_10_10_REV
1549 addIntegerVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, &copyPackedVertexData<true, true, false>);
1550
1551 // GL_UNSIGNED_INT_2_10_10_10_REV
1552 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT_2_10_10_10_REV, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UINT, &copyPackedUnsignedVertexData);
1553
1554 return map;
1555}
1556
1557static bool GetD3D11VertexFormatInfo(const gl::VertexFormat &vertexFormat, D3D11VertexFormatInfo *outVertexFormatInfo)
1558{
1559 static const D3D11VertexFormatInfoMap vertexFormatMap = BuildD3D11VertexFormatInfoMap();
1560
1561 D3D11VertexFormatInfoMap::const_iterator iter = vertexFormatMap.find(vertexFormat);
1562 if (iter != vertexFormatMap.end())
1563 {
1564 if (outVertexFormatInfo)
1565 {
1566 *outVertexFormatInfo = iter->second;
1567 }
1568 return true;
1569 }
1570 else
1571 {
1572 return false;
1573 }
1574}
1575
1576VertexCopyFunction GetVertexCopyFunction(const gl::VertexFormat &vertexFormat)
1577{
1578 D3D11VertexFormatInfo vertexFormatInfo;
1579 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1580 {
1581 return vertexFormatInfo.mCopyFunction;
1582 }
1583 else
1584 {
1585 UNREACHABLE();
1586 return NULL;
1587 }
1588}
1589
1590size_t GetVertexElementSize(const gl::VertexFormat &vertexFormat)
1591{
1592 D3D11VertexFormatInfo vertexFormatInfo;
1593 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1594 {
1595 // FIXME: should not need a client version, and is not a pixel!
1596 return d3d11::GetFormatPixelBytes(vertexFormatInfo.mNativeFormat);
1597 }
1598 else
1599 {
1600 UNREACHABLE();
1601 return 0;
1602 }
1603}
1604
1605rx::VertexConversionType GetVertexConversionType(const gl::VertexFormat &vertexFormat)
1606{
1607 D3D11VertexFormatInfo vertexFormatInfo;
1608 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1609 {
1610 return vertexFormatInfo.mConversionType;
1611 }
1612 else
1613 {
1614 UNREACHABLE();
1615 return VERTEX_CONVERT_NONE;
1616 }
1617}
1618
1619DXGI_FORMAT GetNativeVertexFormat(const gl::VertexFormat &vertexFormat)
1620{
1621 D3D11VertexFormatInfo vertexFormatInfo;
1622 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1623 {
1624 return vertexFormatInfo.mNativeFormat;
1625 }
1626 else
1627 {
1628 UNREACHABLE();
1629 return DXGI_FORMAT_UNKNOWN;
1630 }
1631}
1632
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001633}
1634
1635namespace d3d11_gl
1636{
1637
Geoff Lang005df412013-10-16 14:12:50 -04001638GLenum GetInternalFormat(DXGI_FORMAT format, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001639{
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001640 if (clientVersion == 2)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001641 {
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001642 static DXGIToESFormatMap es2FormatMap = BuildDXGIToES2FormatMap();
1643 auto formatIt = es2FormatMap.find(format);
1644 if (formatIt != es2FormatMap.end())
1645 {
1646 return formatIt->second;
1647 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001648 }
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001649 else if (clientVersion == 3)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001650 {
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001651 static DXGIToESFormatMap es3FormatMap = BuildDXGIToES3FormatMap();
1652 auto formatIt = es3FormatMap.find(format);
1653 if (formatIt != es3FormatMap.end())
1654 {
1655 return formatIt->second;
1656 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001657 }
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001658
1659 UNREACHABLE();
1660 return GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001661}
1662
1663}
1664
1665}