blob: e40ab0912750c028cc6b27f5943222a42a300226 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
Geoff Langcec35902014-04-16 10:52:36 -04003// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00004// 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
Brandon Jonesc7a41042014-06-23 12:03:25 -070011#include "libGLESv2/renderer/d3d/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
Geoff Lange4a492b2014-06-19 14:14:41 -040021struct D3D11FormatInfo
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000022{
23 DXGI_FORMAT mTexFormat;
24 DXGI_FORMAT mSRVFormat;
25 DXGI_FORMAT mRTVFormat;
26 DXGI_FORMAT mDSVFormat;
27
Geoff Lange4a492b2014-06-19 14:14:41 -040028 D3D11FormatInfo()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000029 : mTexFormat(DXGI_FORMAT_UNKNOWN), mDSVFormat(DXGI_FORMAT_UNKNOWN), mRTVFormat(DXGI_FORMAT_UNKNOWN), mSRVFormat(DXGI_FORMAT_UNKNOWN)
30 { }
31
Geoff Lange4a492b2014-06-19 14:14:41 -040032 D3D11FormatInfo(DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat, DXGI_FORMAT dsvFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000033 : 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 Lange4a492b2014-06-19 14:14:41 -040040typedef std::pair<GLenum, D3D11FormatInfo> D3D11ES3FormatPair;
41typedef std::map<GLenum, D3D11FormatInfo> D3D11ES3FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000042
Geoff Lange4a492b2014-06-19 14:14:41 -040043static D3D11ES3FormatMap BuildD3D11FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000044{
45 D3D11ES3FormatMap map;
46
Geoff Lange4a492b2014-06-19 14:14:41 -040047 // | GL internal format | | D3D11 texture format | D3D11 SRV format | D3D11 RTV format | D3D11 DSV format |
48 map.insert(D3D11ES3FormatPair(GL_NONE, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
49 map.insert(D3D11ES3FormatPair(GL_R8, D3D11FormatInfo(DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN)));
50 map.insert(D3D11ES3FormatPair(GL_R8_SNORM, D3D11FormatInfo(DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
51 map.insert(D3D11ES3FormatPair(GL_RG8, D3D11FormatInfo(DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_UNKNOWN)));
52 map.insert(D3D11ES3FormatPair(GL_RG8_SNORM, D3D11FormatInfo(DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
53 map.insert(D3D11ES3FormatPair(GL_RGB8, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
54 map.insert(D3D11ES3FormatPair(GL_RGB8_SNORM, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
55 map.insert(D3D11ES3FormatPair(GL_RGB565, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
56 map.insert(D3D11ES3FormatPair(GL_RGBA4, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
57 map.insert(D3D11ES3FormatPair(GL_RGB5_A1, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
58 map.insert(D3D11ES3FormatPair(GL_RGBA8, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
59 map.insert(D3D11ES3FormatPair(GL_RGBA8_SNORM, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
60 map.insert(D3D11ES3FormatPair(GL_RGB10_A2, D3D11FormatInfo(DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_UNKNOWN)));
61 map.insert(D3D11ES3FormatPair(GL_RGB10_A2UI, D3D11FormatInfo(DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_UNKNOWN)));
62 map.insert(D3D11ES3FormatPair(GL_SRGB8, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
63 map.insert(D3D11ES3FormatPair(GL_SRGB8_ALPHA8, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_UNKNOWN)));
64 map.insert(D3D11ES3FormatPair(GL_R16F, D3D11FormatInfo(DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN)));
65 map.insert(D3D11ES3FormatPair(GL_RG16F, D3D11FormatInfo(DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_UNKNOWN)));
66 map.insert(D3D11ES3FormatPair(GL_RGB16F, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN)));
67 map.insert(D3D11ES3FormatPair(GL_RGBA16F, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN)));
68 map.insert(D3D11ES3FormatPair(GL_R32F, D3D11FormatInfo(DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN)));
69 map.insert(D3D11ES3FormatPair(GL_RG32F, D3D11FormatInfo(DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN)));
70 map.insert(D3D11ES3FormatPair(GL_RGB32F, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN)));
71 map.insert(D3D11ES3FormatPair(GL_RGBA32F, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN)));
72 map.insert(D3D11ES3FormatPair(GL_R11F_G11F_B10F, D3D11FormatInfo(DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_UNKNOWN)));
73 map.insert(D3D11ES3FormatPair(GL_RGB9_E5, D3D11FormatInfo(DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
74 map.insert(D3D11ES3FormatPair(GL_R8I, D3D11FormatInfo(DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_SINT, DXGI_FORMAT_UNKNOWN)));
75 map.insert(D3D11ES3FormatPair(GL_R8UI, D3D11FormatInfo(DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN)));
76 map.insert(D3D11ES3FormatPair(GL_R16I, D3D11FormatInfo(DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SINT, DXGI_FORMAT_UNKNOWN)));
77 map.insert(D3D11ES3FormatPair(GL_R16UI, D3D11FormatInfo(DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_UNKNOWN)));
78 map.insert(D3D11ES3FormatPair(GL_R32I, D3D11FormatInfo(DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_SINT, DXGI_FORMAT_UNKNOWN)));
79 map.insert(D3D11ES3FormatPair(GL_R32UI, D3D11FormatInfo(DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_UNKNOWN)));
80 map.insert(D3D11ES3FormatPair(GL_RG8I, D3D11FormatInfo(DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_UNKNOWN)));
81 map.insert(D3D11ES3FormatPair(GL_RG8UI, D3D11FormatInfo(DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN)));
82 map.insert(D3D11ES3FormatPair(GL_RG16I, D3D11FormatInfo(DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_UNKNOWN)));
83 map.insert(D3D11ES3FormatPair(GL_RG16UI, D3D11FormatInfo(DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_UNKNOWN)));
84 map.insert(D3D11ES3FormatPair(GL_RG32I, D3D11FormatInfo(DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_UNKNOWN)));
85 map.insert(D3D11ES3FormatPair(GL_RG32UI, D3D11FormatInfo(DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN)));
86 map.insert(D3D11ES3FormatPair(GL_RGB8I, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_UNKNOWN)));
87 map.insert(D3D11ES3FormatPair(GL_RGB8UI, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN)));
88 map.insert(D3D11ES3FormatPair(GL_RGB16I, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_UNKNOWN)));
89 map.insert(D3D11ES3FormatPair(GL_RGB16UI, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_UNKNOWN)));
90 map.insert(D3D11ES3FormatPair(GL_RGB32I, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_UNKNOWN)));
91 map.insert(D3D11ES3FormatPair(GL_RGB32UI, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN)));
92 map.insert(D3D11ES3FormatPair(GL_RGBA8I, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_UNKNOWN)));
93 map.insert(D3D11ES3FormatPair(GL_RGBA8UI, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN)));
94 map.insert(D3D11ES3FormatPair(GL_RGBA16I, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_UNKNOWN)));
95 map.insert(D3D11ES3FormatPair(GL_RGBA16UI, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_UNKNOWN)));
96 map.insert(D3D11ES3FormatPair(GL_RGBA32I, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_UNKNOWN)));
97 map.insert(D3D11ES3FormatPair(GL_RGBA32UI, D3D11FormatInfo(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 Lange4a492b2014-06-19 14:14:41 -0400100 map.insert(D3D11ES3FormatPair(GL_ALPHA, D3D11FormatInfo(DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN)));
101 map.insert(D3D11ES3FormatPair(GL_LUMINANCE, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
102 map.insert(D3D11ES3FormatPair(GL_LUMINANCE_ALPHA, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
103 map.insert(D3D11ES3FormatPair(GL_RGB, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
104 map.insert(D3D11ES3FormatPair(GL_RGBA, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
105 map.insert(D3D11ES3FormatPair(GL_BGRA_EXT, D3D11FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000106
107 // From GL_EXT_texture_storage
Geoff Lange4a492b2014-06-19 14:14:41 -0400108 // | GL internal format | | D3D11 texture format | D3D11 SRV format | D3D11 RTV format | D3D11 DSV format |
109 map.insert(D3D11ES3FormatPair(GL_ALPHA8_EXT, D3D11FormatInfo(DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN )));
110 map.insert(D3D11ES3FormatPair(GL_LUMINANCE8_EXT, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
111 map.insert(D3D11ES3FormatPair(GL_ALPHA32F_EXT, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN )));
112 map.insert(D3D11ES3FormatPair(GL_LUMINANCE32F_EXT, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN )));
113 map.insert(D3D11ES3FormatPair(GL_ALPHA16F_EXT, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN )));
114 map.insert(D3D11ES3FormatPair(GL_LUMINANCE16F_EXT, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN )));
115 map.insert(D3D11ES3FormatPair(GL_LUMINANCE8_ALPHA8_EXT, D3D11FormatInfo(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
116 map.insert(D3D11ES3FormatPair(GL_LUMINANCE_ALPHA32F_EXT, D3D11FormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN )));
117 map.insert(D3D11ES3FormatPair(GL_LUMINANCE_ALPHA16F_EXT, D3D11FormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN )));
118 map.insert(D3D11ES3FormatPair(GL_BGRA8_EXT, D3D11FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
119 map.insert(D3D11ES3FormatPair(GL_BGRA4_ANGLEX, D3D11FormatInfo(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN )));
120 map.insert(D3D11ES3FormatPair(GL_BGR5_A1_ANGLEX, D3D11FormatInfo(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 Lange4a492b2014-06-19 14:14:41 -0400123 map.insert(D3D11ES3FormatPair(GL_DEPTH_COMPONENT16, D3D11FormatInfo(DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D16_UNORM )));
124 map.insert(D3D11ES3FormatPair(GL_DEPTH_COMPONENT24, D3D11FormatInfo(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, D3D11FormatInfo(DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D32_FLOAT )));
126 map.insert(D3D11ES3FormatPair(GL_DEPTH24_STENCIL8, D3D11FormatInfo(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, D3D11FormatInfo(DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D32_FLOAT_S8X24_UINT)));
128 map.insert(D3D11ES3FormatPair(GL_STENCIL_INDEX8, D3D11FormatInfo(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 Lange4a492b2014-06-19 14:14:41 -0400131 // Since D3D11 doesn't have a D32_UNORM format, use D24S8 which has comparable precision and matches the ES3 format.
132 map.insert(D3D11ES3FormatPair(GL_DEPTH_COMPONENT32_OES, D3D11FormatInfo(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 +0000133
134 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lange4a492b2014-06-19 14:14:41 -0400135 // | GL internal format | | D3D11 texture format | D3D11 SRV format | D3D11 RTV format | D3D11 DSV format |
136 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_R11_EAC, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
137 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SIGNED_R11_EAC, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
138 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RG11_EAC, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
139 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SIGNED_RG11_EAC, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
140 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGB8_ETC2, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
141 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SRGB8_ETC2, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
142 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
143 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
144 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA8_ETC2_EAC, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
145 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, D3D11FormatInfo(DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000146
147 // From GL_EXT_texture_compression_dxt1
Geoff Lange4a492b2014-06-19 14:14:41 -0400148 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, D3D11FormatInfo(DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
149 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, D3D11FormatInfo(DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000150
151 // From GL_ANGLE_texture_compression_dxt3
Geoff Lange4a492b2014-06-19 14:14:41 -0400152 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, D3D11FormatInfo(DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000153
154 // From GL_ANGLE_texture_compression_dxt5
Geoff Lange4a492b2014-06-19 14:14:41 -0400155 map.insert(D3D11ES3FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, D3D11FormatInfo(DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000156
157 return map;
158}
159
Geoff Lange4a492b2014-06-19 14:14:41 -0400160static bool GetD3D11FormatInfo(GLenum internalFormat, D3D11FormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000161{
Geoff Lange4a492b2014-06-19 14:14:41 -0400162 static const D3D11ES3FormatMap formatMap = BuildD3D11FormatMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000163 D3D11ES3FormatMap::const_iterator iter = formatMap.find(internalFormat);
164 if (iter != formatMap.end())
165 {
166 if (outFormatInfo)
167 {
168 *outFormatInfo = iter->second;
169 }
170 return true;
171 }
172 else
173 {
174 return false;
175 }
176}
177
178// ES3 image loading functions vary based on the internal format and data type given,
179// this map type determines the loading function from the internal format and type supplied
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000180// to glTex*Image*D and the destination DXGI_FORMAT. Source formats and types are taken from
181// Tables 3.2 and 3.3 of the ES 3 spec.
Geoff Lang005df412013-10-16 14:12:50 -0400182typedef std::pair<GLenum, GLenum> InternalFormatTypePair;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000183typedef std::pair<InternalFormatTypePair, LoadImageFunction> D3D11LoadFunctionPair;
184typedef std::map<InternalFormatTypePair, LoadImageFunction> D3D11LoadFunctionMap;
185
186static void UnimplementedLoadFunction(int width, int height, int depth,
187 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
188 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
189{
190 UNIMPLEMENTED();
191}
192
Geoff Langd3ff2162013-06-07 15:10:59 -0400193static void UnreachableLoadFunction(int width, int height, int depth,
194 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
195 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
196{
197 UNREACHABLE();
198}
199
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000200// A helper function to insert data into the D3D11LoadFunctionMap with fewer characters.
Geoff Lang005df412013-10-16 14:12:50 -0400201static inline void insertLoadFunction(D3D11LoadFunctionMap *map, GLenum internalFormat, GLenum type,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000202 LoadImageFunction loadFunc)
203{
204 map->insert(D3D11LoadFunctionPair(InternalFormatTypePair(internalFormat, type), loadFunc));
205}
206
207D3D11LoadFunctionMap buildD3D11LoadFunctionMap()
208{
209 D3D11LoadFunctionMap map;
210
211 // | Internal format | Type | Load function |
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000212 insertLoadFunction(&map, GL_RGBA8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400213 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
214 insertLoadFunction(&map, GL_RGBA4, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000215 insertLoadFunction(&map, GL_SRGB8_ALPHA8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000216 insertLoadFunction(&map, GL_RGBA8_SNORM, GL_BYTE, loadToNative<GLbyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000217 insertLoadFunction(&map, GL_RGBA4, GL_UNSIGNED_SHORT_4_4_4_4, loadRGBA4444DataToRGBA );
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000218 insertLoadFunction(&map, GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000219 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_SHORT_5_5_5_1, loadRGBA5551DataToRGBA );
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000220 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_INT_2_10_10_10_REV, loadRGBA2101010ToRGBA );
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000221 insertLoadFunction(&map, GL_RGBA16F, GL_HALF_FLOAT, loadToNative<GLhalf, 4> );
Geoff Lange4a492b2014-06-19 14:14:41 -0400222 insertLoadFunction(&map, GL_RGBA16F, GL_HALF_FLOAT_OES, loadToNative<GLhalf, 4> );
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000223 insertLoadFunction(&map, GL_RGBA32F, GL_FLOAT, loadToNative<GLfloat, 4> );
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000224 insertLoadFunction(&map, GL_RGBA16F, GL_FLOAT, loadFloatDataToHalfFloat<4> );
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000225 insertLoadFunction(&map, GL_RGBA8UI, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
226 insertLoadFunction(&map, GL_RGBA8I, GL_BYTE, loadToNative<GLbyte, 4> );
227 insertLoadFunction(&map, GL_RGBA16UI, GL_UNSIGNED_SHORT, loadToNative<GLushort, 4> );
228 insertLoadFunction(&map, GL_RGBA16I, GL_SHORT, loadToNative<GLshort, 4> );
229 insertLoadFunction(&map, GL_RGBA32UI, GL_UNSIGNED_INT, loadToNative<GLuint, 4> );
230 insertLoadFunction(&map, GL_RGBA32I, GL_INT, loadToNative<GLint, 4> );
231 insertLoadFunction(&map, GL_RGB10_A2UI, GL_UNSIGNED_INT_2_10_10_10_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000232 insertLoadFunction(&map, GL_RGB8, GL_UNSIGNED_BYTE, loadRGBUByteDataToRGBA );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400233 insertLoadFunction(&map, GL_RGB565, GL_UNSIGNED_BYTE, loadToNative3To4<GLubyte, 0xFF> );
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +0000234 insertLoadFunction(&map, GL_SRGB8, GL_UNSIGNED_BYTE, loadToNative3To4<GLubyte, 0xFF> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000235 insertLoadFunction(&map, GL_RGB8_SNORM, GL_BYTE, loadRGBSByteDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000236 insertLoadFunction(&map, GL_RGB565, GL_UNSIGNED_SHORT_5_6_5, loadRGB565DataToRGBA );
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000237 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_UNSIGNED_INT_10F_11F_11F_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000238 insertLoadFunction(&map, GL_RGB9_E5, GL_UNSIGNED_INT_5_9_9_9_REV, loadToNative<GLuint, 1> );
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000239 insertLoadFunction(&map, GL_RGB16F, GL_HALF_FLOAT, loadToNative3To4<GLhalf, gl::Float16One>);
Geoff Lange4a492b2014-06-19 14:14:41 -0400240 insertLoadFunction(&map, GL_RGB16F, GL_HALF_FLOAT_OES, loadToNative3To4<GLhalf, gl::Float16One>);
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000241 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_HALF_FLOAT, loadRGBHalfFloatDataTo111110Float );
Geoff Lange4a492b2014-06-19 14:14:41 -0400242 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_HALF_FLOAT_OES, loadRGBHalfFloatDataTo111110Float );
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000243 insertLoadFunction(&map, GL_RGB9_E5, GL_HALF_FLOAT, loadRGBHalfFloatDataTo999E5 );
Geoff Lange4a492b2014-06-19 14:14:41 -0400244 insertLoadFunction(&map, GL_RGB9_E5, GL_HALF_FLOAT_OES, loadRGBHalfFloatDataTo999E5 );
Geoff Lang1c3192e2013-07-22 13:59:24 -0400245 insertLoadFunction(&map, GL_RGB32F, GL_FLOAT, loadToNative3To4<GLfloat, gl::Float32One>);
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000246 insertLoadFunction(&map, GL_RGB16F, GL_FLOAT, loadFloatRGBDataToHalfFloatRGBA );
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000247 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_FLOAT, loadRGBFloatDataTo111110Float );
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000248 insertLoadFunction(&map, GL_RGB9_E5, GL_FLOAT, loadRGBFloatDataTo999E5 );
Geoff Lang5b61c692013-08-02 15:02:59 -0400249 insertLoadFunction(&map, GL_RGB8UI, GL_UNSIGNED_BYTE, loadToNative3To4<GLubyte, 0x01> );
250 insertLoadFunction(&map, GL_RGB8I, GL_BYTE, loadToNative3To4<GLbyte, 0x01> );
251 insertLoadFunction(&map, GL_RGB16UI, GL_UNSIGNED_SHORT, loadToNative3To4<GLushort, 0x0001> );
252 insertLoadFunction(&map, GL_RGB16I, GL_SHORT, loadToNative3To4<GLshort, 0x0001> );
Jamie Madill0fd77862013-09-09 16:24:06 -0400253 insertLoadFunction(&map, GL_RGB32UI, GL_UNSIGNED_INT, loadToNative3To4<GLuint, 0x00000001> );
254 insertLoadFunction(&map, GL_RGB32I, GL_INT, loadToNative3To4<GLint, 0x00000001> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000255 insertLoadFunction(&map, GL_RG8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 2> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000256 insertLoadFunction(&map, GL_RG8_SNORM, GL_BYTE, loadToNative<GLbyte, 2> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000257 insertLoadFunction(&map, GL_RG16F, GL_HALF_FLOAT, loadToNative<GLhalf, 2> );
Geoff Lange4a492b2014-06-19 14:14:41 -0400258 insertLoadFunction(&map, GL_RG16F, GL_HALF_FLOAT_OES, loadToNative<GLhalf, 2> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000259 insertLoadFunction(&map, GL_RG32F, GL_FLOAT, loadToNative<GLfloat, 2> );
260 insertLoadFunction(&map, GL_RG16F, GL_FLOAT, loadFloatDataToHalfFloat<2> );
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000261 insertLoadFunction(&map, GL_RG8UI, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 2> );
262 insertLoadFunction(&map, GL_RG8I, GL_BYTE, loadToNative<GLbyte, 2> );
263 insertLoadFunction(&map, GL_RG16UI, GL_UNSIGNED_SHORT, loadToNative<GLushort, 2> );
264 insertLoadFunction(&map, GL_RG16I, GL_SHORT, loadToNative<GLshort, 2> );
265 insertLoadFunction(&map, GL_RG32UI, GL_UNSIGNED_INT, loadToNative<GLuint, 2> );
266 insertLoadFunction(&map, GL_RG32I, GL_INT, loadToNative<GLint, 2> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000267 insertLoadFunction(&map, GL_R8, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 1> );
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000268 insertLoadFunction(&map, GL_R8_SNORM, GL_BYTE, loadToNative<GLbyte, 1> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000269 insertLoadFunction(&map, GL_R16F, GL_HALF_FLOAT, loadToNative<GLhalf, 1> );
Geoff Lange4a492b2014-06-19 14:14:41 -0400270 insertLoadFunction(&map, GL_R16F, GL_HALF_FLOAT_OES, loadToNative<GLhalf, 1> );
shannonwoods@chromium.orga32a2ba2013-05-30 00:14:40 +0000271 insertLoadFunction(&map, GL_R32F, GL_FLOAT, loadToNative<GLfloat, 1> );
272 insertLoadFunction(&map, GL_R16F, GL_FLOAT, loadFloatDataToHalfFloat<1> );
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000273 insertLoadFunction(&map, GL_R8UI, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 1> );
274 insertLoadFunction(&map, GL_R8I, GL_BYTE, loadToNative<GLbyte, 1> );
275 insertLoadFunction(&map, GL_R16UI, GL_UNSIGNED_SHORT, loadToNative<GLushort, 1> );
276 insertLoadFunction(&map, GL_R16I, GL_SHORT, loadToNative<GLshort, 1> );
277 insertLoadFunction(&map, GL_R32UI, GL_UNSIGNED_INT, loadToNative<GLuint, 1> );
278 insertLoadFunction(&map, GL_R32I, GL_INT, loadToNative<GLint, 1> );
Geoff Lang87465462013-06-17 16:28:54 -0400279 insertLoadFunction(&map, GL_DEPTH_COMPONENT16, GL_UNSIGNED_SHORT, loadToNative<GLushort, 1> );
Geoff Lang4133f5c2013-10-10 13:51:18 -0400280 insertLoadFunction(&map, GL_DEPTH_COMPONENT24, GL_UNSIGNED_INT, loadG8R24DataToR24G8 );
Geoff Lang87465462013-06-17 16:28:54 -0400281 insertLoadFunction(&map, GL_DEPTH_COMPONENT16, GL_UNSIGNED_INT, loadUintDataToUshort );
282 insertLoadFunction(&map, GL_DEPTH_COMPONENT32F, GL_FLOAT, loadToNative<GLfloat, 1> );
Geoff Lang4133f5c2013-10-10 13:51:18 -0400283 insertLoadFunction(&map, GL_DEPTH24_STENCIL8, GL_UNSIGNED_INT_24_8, loadG8R24DataToR24G8 );
Geoff Lang87465462013-06-17 16:28:54 -0400284 insertLoadFunction(&map, GL_DEPTH32F_STENCIL8, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, loadToNative<GLuint, 2> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000285
286 // Unsized formats
Geoff Langd3ff2162013-06-07 15:10:59 -0400287 // Load functions are unreachable because they are converted to sized internal formats based on
288 // the format and type before loading takes place.
289 insertLoadFunction(&map, GL_RGBA, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
290 insertLoadFunction(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, UnreachableLoadFunction );
291 insertLoadFunction(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, UnreachableLoadFunction );
292 insertLoadFunction(&map, GL_RGB, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
293 insertLoadFunction(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, UnreachableLoadFunction );
294 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
295 insertLoadFunction(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
296 insertLoadFunction(&map, GL_ALPHA, GL_UNSIGNED_BYTE, UnreachableLoadFunction );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000297
298 // From GL_OES_texture_float
299 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, loadLuminanceAlphaFloatDataToRGBA );
Geoff Lange4a492b2014-06-19 14:14:41 -0400300 insertLoadFunction(&map, GL_LUMINANCE, GL_FLOAT, loadLuminanceFloatDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000301 insertLoadFunction(&map, GL_ALPHA, GL_FLOAT, loadAlphaFloatDataToRGBA );
302
303 // From GL_OES_texture_half_float
304 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, loadLuminanceAlphaHalfFloatDataToRGBA);
Geoff Lange4a492b2014-06-19 14:14:41 -0400305 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, loadLuminanceAlphaHalfFloatDataToRGBA);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000306 insertLoadFunction(&map, GL_LUMINANCE, GL_HALF_FLOAT, loadLuminanceHalfFloatDataToRGBA );
Geoff Lange4a492b2014-06-19 14:14:41 -0400307 insertLoadFunction(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, loadLuminanceHalfFloatDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000308 insertLoadFunction(&map, GL_ALPHA, GL_HALF_FLOAT, loadAlphaHalfFloatDataToRGBA );
Geoff Lange4a492b2014-06-19 14:14:41 -0400309 insertLoadFunction(&map, GL_ALPHA, GL_HALF_FLOAT_OES, loadAlphaHalfFloatDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000310
311 // From GL_EXT_texture_storage
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000312 insertLoadFunction(&map, GL_ALPHA8_EXT, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 1> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000313 insertLoadFunction(&map, GL_LUMINANCE8_EXT, GL_UNSIGNED_BYTE, loadLuminanceDataToBGRA );
314 insertLoadFunction(&map, GL_LUMINANCE8_ALPHA8_EXT, GL_UNSIGNED_BYTE, loadLuminanceAlphaDataToBGRA );
315 insertLoadFunction(&map, GL_ALPHA32F_EXT, GL_FLOAT, loadAlphaFloatDataToRGBA );
Geoff Lange4a492b2014-06-19 14:14:41 -0400316 insertLoadFunction(&map, GL_LUMINANCE32F_EXT, GL_FLOAT, loadLuminanceFloatDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000317 insertLoadFunction(&map, GL_LUMINANCE_ALPHA32F_EXT, GL_FLOAT, loadLuminanceAlphaFloatDataToRGBA );
318 insertLoadFunction(&map, GL_ALPHA16F_EXT, GL_HALF_FLOAT, loadAlphaHalfFloatDataToRGBA );
Geoff Lange4a492b2014-06-19 14:14:41 -0400319 insertLoadFunction(&map, GL_ALPHA16F_EXT, GL_HALF_FLOAT_OES, loadAlphaHalfFloatDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000320 insertLoadFunction(&map, GL_LUMINANCE16F_EXT, GL_HALF_FLOAT, loadLuminanceHalfFloatDataToRGBA );
Geoff Lange4a492b2014-06-19 14:14:41 -0400321 insertLoadFunction(&map, GL_LUMINANCE16F_EXT, GL_HALF_FLOAT_OES, loadLuminanceHalfFloatDataToRGBA );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000322 insertLoadFunction(&map, GL_LUMINANCE_ALPHA16F_EXT, GL_HALF_FLOAT, loadLuminanceAlphaHalfFloatDataToRGBA);
Geoff Lange4a492b2014-06-19 14:14:41 -0400323 insertLoadFunction(&map, GL_LUMINANCE_ALPHA16F_EXT, GL_HALF_FLOAT_OES, loadLuminanceAlphaHalfFloatDataToRGBA);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000324
Geoff Lange4a492b2014-06-19 14:14:41 -0400325 // From GL_ANGLE_depth_texture
326 insertLoadFunction(&map, GL_DEPTH_COMPONENT32_OES, GL_UNSIGNED_INT, loadUintDataToUint24X8 );
327
328 // From GL_EXT_texture_format_BGRA8888
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000329 insertLoadFunction(&map, GL_BGRA8_EXT, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000330 insertLoadFunction(&map, GL_BGRA4_ANGLEX, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, loadRGBA4444DataToRGBA );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400331 insertLoadFunction(&map, GL_BGRA4_ANGLEX, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000332 insertLoadFunction(&map, GL_BGR5_A1_ANGLEX, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, loadRGBA5551DataToRGBA );
Geoff Lang9c5808c2013-06-07 15:16:58 -0400333 insertLoadFunction(&map, GL_BGR5_A1_ANGLEX, GL_UNSIGNED_BYTE, loadToNative<GLubyte, 4> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000334
335 // Compressed formats
336 // From ES 3.0.1 spec, table 3.16
337 // | Internal format | Type | Load function |
338 insertLoadFunction(&map, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
339 insertLoadFunction(&map, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
340 insertLoadFunction(&map, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
341 insertLoadFunction(&map, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
342 insertLoadFunction(&map, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
343 insertLoadFunction(&map, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
344 insertLoadFunction(&map, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
345 insertLoadFunction(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
346 insertLoadFunction(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
347 insertLoadFunction(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
348 insertLoadFunction(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedLoadFunction );
349
350 // From GL_EXT_texture_compression_dxt1
351 insertLoadFunction(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 8>);
352 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 8>);
353
354 // From GL_ANGLE_texture_compression_dxt3
355 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 16>);
356
357 // From GL_ANGLE_texture_compression_dxt5
358 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, loadCompressedBlockDataToNative<4, 4, 16>);
359
360 return map;
361}
362
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000363// A map to determine the pixel size and mipmap generation function of a given DXGI format
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000364struct DXGIFormatInfo
365{
366 GLuint mPixelBits;
367 GLuint mBlockWidth;
368 GLuint mBlockHeight;
Jamie Madill826f3d32014-01-29 09:26:49 -0500369 GLenum mComponentType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000370
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000371 MipGenerationFunction mMipGenerationFunction;
Geoff Langfe28ca02013-06-04 10:10:48 -0400372 ColorReadFunction mColorReadFunction;
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000373
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000374 DXGIFormatInfo()
Jamie Madill826f3d32014-01-29 09:26:49 -0500375 : mPixelBits(0), mBlockWidth(0), mBlockHeight(0), mComponentType(GL_NONE), mMipGenerationFunction(NULL),
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500376 mColorReadFunction(NULL)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000377 { }
378
Jamie Madill826f3d32014-01-29 09:26:49 -0500379 DXGIFormatInfo(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight, GLenum componentType,
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500380 MipGenerationFunction mipFunc, ColorReadFunction readFunc)
Jamie Madill826f3d32014-01-29 09:26:49 -0500381 : mPixelBits(pixelBits), mBlockWidth(blockWidth), mBlockHeight(blockHeight), mComponentType(componentType),
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500382 mMipGenerationFunction(mipFunc), mColorReadFunction(readFunc)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000383 { }
384};
385
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000386typedef std::map<DXGI_FORMAT, DXGIFormatInfo> DXGIFormatInfoMap;
387
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500388void AddDXGIFormat(DXGIFormatInfoMap *map, DXGI_FORMAT dxgiFormat, GLuint pixelBits, GLuint blockWidth, GLuint blockHeight,
Jamie Madill826f3d32014-01-29 09:26:49 -0500389 GLenum componentType, MipGenerationFunction mipFunc, ColorReadFunction readFunc)
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500390{
Jamie Madill826f3d32014-01-29 09:26:49 -0500391 map->insert(std::make_pair(dxgiFormat, DXGIFormatInfo(pixelBits, blockWidth, blockHeight, componentType, mipFunc, readFunc)));
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500392}
393
394static DXGIFormatInfoMap BuildDXGIFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000395{
396 DXGIFormatInfoMap map;
397
Jamie Madill826f3d32014-01-29 09:26:49 -0500398 // | DXGI format |S |W |H |Component Type | Mip generation function | Color read function
399 AddDXGIFormat(&map, DXGI_FORMAT_UNKNOWN, 0, 0, 0, GL_NONE, NULL, NULL);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000400
Jamie Madill826f3d32014-01-29 09:26:49 -0500401 AddDXGIFormat(&map, DXGI_FORMAT_A8_UNORM, 8, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<A8>, ReadColor<A8, GLfloat>);
402 AddDXGIFormat(&map, DXGI_FORMAT_R8_UNORM, 8, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8>, ReadColor<R8, GLfloat>);
403 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8G8>, ReadColor<R8G8, GLfloat>);
404 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_UNORM, 32, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8G8B8A8>, ReadColor<R8G8B8A8, GLfloat>);
405 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 32, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R8G8B8A8>, ReadColor<R8G8B8A8, GLfloat>);
406 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 +0000407
Jamie Madill826f3d32014-01-29 09:26:49 -0500408 AddDXGIFormat(&map, DXGI_FORMAT_R8_SNORM, 8, 1, 1, GL_SIGNED_NORMALIZED, GenerateMip<R8S>, ReadColor<R8S, GLfloat>);
409 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_SNORM, 16, 1, 1, GL_SIGNED_NORMALIZED, GenerateMip<R8G8S>, ReadColor<R8G8S, GLfloat>);
410 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 +0000411
Jamie Madill826f3d32014-01-29 09:26:49 -0500412 AddDXGIFormat(&map, DXGI_FORMAT_R8_UINT, 8, 1, 1, GL_UNSIGNED_INT, GenerateMip<R8>, ReadColor<R8, GLuint>);
413 AddDXGIFormat(&map, DXGI_FORMAT_R16_UINT, 16, 1, 1, GL_UNSIGNED_INT, GenerateMip<R16>, ReadColor<R16, GLuint>);
414 AddDXGIFormat(&map, DXGI_FORMAT_R32_UINT, 32, 1, 1, GL_UNSIGNED_INT, GenerateMip<R32>, ReadColor<R32, GLuint>);
415 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_UINT, 16, 1, 1, GL_UNSIGNED_INT, GenerateMip<R8G8>, ReadColor<R8G8, GLuint>);
416 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_UINT, 32, 1, 1, GL_UNSIGNED_INT, GenerateMip<R16G16>, ReadColor<R16G16, GLuint>);
417 AddDXGIFormat(&map, DXGI_FORMAT_R32G32_UINT, 64, 1, 1, GL_UNSIGNED_INT, GenerateMip<R32G32>, ReadColor<R32G32, GLuint>);
418 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32_UINT, 96, 1, 1, GL_UNSIGNED_INT, GenerateMip<R32G32B32>, ReadColor<R32G32B32, GLuint>);
419 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_UINT, 32, 1, 1, GL_UNSIGNED_INT, GenerateMip<R8G8B8A8>, ReadColor<R8G8B8A8, GLuint>);
420 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_UINT, 64, 1, 1, GL_UNSIGNED_INT, GenerateMip<R16G16B16A16>, ReadColor<R16G16B16A16, GLuint>);
421 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 +0000422
Jamie Madill826f3d32014-01-29 09:26:49 -0500423 AddDXGIFormat(&map, DXGI_FORMAT_R8_SINT, 8, 1, 1, GL_INT, GenerateMip<R8S>, ReadColor<R8S, GLint>);
424 AddDXGIFormat(&map, DXGI_FORMAT_R16_SINT, 16, 1, 1, GL_INT, GenerateMip<R16S>, ReadColor<R16S, GLint>);
425 AddDXGIFormat(&map, DXGI_FORMAT_R32_SINT, 32, 1, 1, GL_INT, GenerateMip<R32S>, ReadColor<R32S, GLint>);
426 AddDXGIFormat(&map, DXGI_FORMAT_R8G8_SINT, 16, 1, 1, GL_INT, GenerateMip<R8G8S>, ReadColor<R8G8S, GLint>);
427 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_SINT, 32, 1, 1, GL_INT, GenerateMip<R16G16S>, ReadColor<R16G16S, GLint>);
428 AddDXGIFormat(&map, DXGI_FORMAT_R32G32_SINT, 64, 1, 1, GL_INT, GenerateMip<R32G32S>, ReadColor<R32G32S, GLint>);
429 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32_SINT, 96, 1, 1, GL_INT, GenerateMip<R32G32B32S>, ReadColor<R32G32B32S, GLint>);
430 AddDXGIFormat(&map, DXGI_FORMAT_R8G8B8A8_SINT, 32, 1, 1, GL_INT, GenerateMip<R8G8B8A8S>, ReadColor<R8G8B8A8S, GLint>);
431 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_SINT, 64, 1, 1, GL_INT, GenerateMip<R16G16B16A16S>, ReadColor<R16G16B16A16S, GLint>);
432 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32A32_SINT, 128, 1, 1, GL_INT, GenerateMip<R32G32B32A32S>, ReadColor<R32G32B32A32S, GLint>);
shannonwoods@chromium.orga05127a2013-05-30 00:16:07 +0000433
Jamie Madill826f3d32014-01-29 09:26:49 -0500434 AddDXGIFormat(&map, DXGI_FORMAT_R10G10B10A2_UNORM, 32, 1, 1, GL_UNSIGNED_NORMALIZED, GenerateMip<R10G10B10A2>, ReadColor<R10G10B10A2, GLfloat>);
435 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 +0000436
Jamie Madill826f3d32014-01-29 09:26:49 -0500437 AddDXGIFormat(&map, DXGI_FORMAT_R16_FLOAT, 16, 1, 1, GL_FLOAT, GenerateMip<R16F>, ReadColor<R16F, GLfloat>);
438 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_FLOAT, 32, 1, 1, GL_FLOAT, GenerateMip<R16G16F>, ReadColor<R16G16F, GLfloat>);
439 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_FLOAT, 64, 1, 1, GL_FLOAT, GenerateMip<R16G16B16A16F>, ReadColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000440
Jamie Madill826f3d32014-01-29 09:26:49 -0500441 AddDXGIFormat(&map, DXGI_FORMAT_R32_FLOAT, 32, 1, 1, GL_FLOAT, GenerateMip<R32F>, ReadColor<R32F, GLfloat>);
442 AddDXGIFormat(&map, DXGI_FORMAT_R32G32_FLOAT, 64, 1, 1, GL_FLOAT, GenerateMip<R32G32F>, ReadColor<R32G32F, GLfloat>);
443 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32_FLOAT, 96, 1, 1, GL_FLOAT, NULL, NULL);
444 AddDXGIFormat(&map, DXGI_FORMAT_R32G32B32A32_FLOAT, 128, 1, 1, GL_FLOAT, GenerateMip<R32G32B32A32F>, ReadColor<R32G32B32A32F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000445
Jamie Madill826f3d32014-01-29 09:26:49 -0500446 AddDXGIFormat(&map, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 32, 1, 1, GL_FLOAT, GenerateMip<R9G9B9E5>, ReadColor<R9G9B9E5, GLfloat>);
447 AddDXGIFormat(&map, DXGI_FORMAT_R11G11B10_FLOAT, 32, 1, 1, GL_FLOAT, GenerateMip<R11G11B10F>, ReadColor<R11G11B10F, GLfloat>);
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000448
Jamie Madill826f3d32014-01-29 09:26:49 -0500449 AddDXGIFormat(&map, DXGI_FORMAT_R16_TYPELESS, 16, 1, 1, GL_NONE, NULL, NULL);
450 AddDXGIFormat(&map, DXGI_FORMAT_R16_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
451 AddDXGIFormat(&map, DXGI_FORMAT_D16_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
452 AddDXGIFormat(&map, DXGI_FORMAT_R24G8_TYPELESS, 32, 1, 1, GL_NONE, NULL, NULL);
453 AddDXGIFormat(&map, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, 32, 1, 1, GL_NONE, NULL, NULL);
454 AddDXGIFormat(&map, DXGI_FORMAT_D24_UNORM_S8_UINT, 32, 1, 1, GL_UNSIGNED_INT, NULL, NULL);
455 AddDXGIFormat(&map, DXGI_FORMAT_R32G8X24_TYPELESS, 64, 1, 1, GL_NONE, NULL, NULL);
456 AddDXGIFormat(&map, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, 64, 1, 1, GL_NONE, NULL, NULL);
457 AddDXGIFormat(&map, DXGI_FORMAT_D32_FLOAT_S8X24_UINT, 64, 1, 1, GL_UNSIGNED_INT, NULL, NULL);
458 AddDXGIFormat(&map, DXGI_FORMAT_R32_TYPELESS, 32, 1, 1, GL_NONE, NULL, NULL);
459 AddDXGIFormat(&map, DXGI_FORMAT_D32_FLOAT, 32, 1, 1, GL_FLOAT, NULL, NULL);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000460
Jamie Madill826f3d32014-01-29 09:26:49 -0500461 AddDXGIFormat(&map, DXGI_FORMAT_BC1_UNORM, 64, 4, 4, GL_UNSIGNED_NORMALIZED, NULL, NULL);
462 AddDXGIFormat(&map, DXGI_FORMAT_BC2_UNORM, 128, 4, 4, GL_UNSIGNED_NORMALIZED, NULL, NULL);
463 AddDXGIFormat(&map, DXGI_FORMAT_BC3_UNORM, 128, 4, 4, GL_UNSIGNED_NORMALIZED, NULL, NULL);
464
465 // Useful formats for vertex buffers
466 AddDXGIFormat(&map, DXGI_FORMAT_R16_UNORM, 16, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
467 AddDXGIFormat(&map, DXGI_FORMAT_R16_SNORM, 16, 1, 1, GL_SIGNED_NORMALIZED, NULL, NULL);
468 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_UNORM, 32, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
469 AddDXGIFormat(&map, DXGI_FORMAT_R16G16_SNORM, 32, 1, 1, GL_SIGNED_NORMALIZED, NULL, NULL);
470 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_UNORM, 64, 1, 1, GL_UNSIGNED_NORMALIZED, NULL, NULL);
471 AddDXGIFormat(&map, DXGI_FORMAT_R16G16B16A16_SNORM, 64, 1, 1, GL_SIGNED_NORMALIZED, NULL, NULL);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000472
473 return map;
474}
475
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500476typedef std::map<DXGI_FORMAT, GLenum> DXGIToESFormatMap;
Jamie Madill707dbd72013-07-10 15:13:39 -0400477
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500478inline void AddDXGIToESEntry(DXGIToESFormatMap *map, DXGI_FORMAT key, GLenum value)
479{
480 map->insert(std::make_pair(key, value));
481}
482
Geoff Lang66aaf722014-06-05 12:42:07 -0400483static DXGIToESFormatMap BuildDXGIToESFormatMap()
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500484{
485 DXGIToESFormatMap map;
486
487 AddDXGIToESEntry(&map, DXGI_FORMAT_UNKNOWN, GL_NONE);
488
489 AddDXGIToESEntry(&map, DXGI_FORMAT_A8_UNORM, GL_ALPHA8_EXT);
490 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_UNORM, GL_R8);
491 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_UNORM, GL_RG8);
492 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_UNORM, GL_RGBA8);
493 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, GL_SRGB8_ALPHA8);
494 AddDXGIToESEntry(&map, DXGI_FORMAT_B8G8R8A8_UNORM, GL_BGRA8_EXT);
495
496 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_SNORM, GL_R8_SNORM);
497 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_SNORM, GL_RG8_SNORM);
498 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_SNORM, GL_RGBA8_SNORM);
499
500 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_UINT, GL_R8UI);
501 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_UINT, GL_R16UI);
502 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_UINT, GL_R32UI);
503 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_UINT, GL_RG8UI);
504 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16_UINT, GL_RG16UI);
505 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32_UINT, GL_RG32UI);
506 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32_UINT, GL_RGB32UI);
507 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_UINT, GL_RGBA8UI);
508 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16B16A16_UINT, GL_RGBA16UI);
509 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32A32_UINT, GL_RGBA32UI);
510
511 AddDXGIToESEntry(&map, DXGI_FORMAT_R8_SINT, GL_R8I);
512 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_SINT, GL_R16I);
513 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_SINT, GL_R32I);
514 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8_SINT, GL_RG8I);
515 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16_SINT, GL_RG16I);
516 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32_SINT, GL_RG32I);
517 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32_SINT, GL_RGB32I);
518 AddDXGIToESEntry(&map, DXGI_FORMAT_R8G8B8A8_SINT, GL_RGBA8I);
519 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16B16A16_SINT, GL_RGBA16I);
520 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32A32_SINT, GL_RGBA32I);
521
522 AddDXGIToESEntry(&map, DXGI_FORMAT_R10G10B10A2_UNORM, GL_RGB10_A2);
523 AddDXGIToESEntry(&map, DXGI_FORMAT_R10G10B10A2_UINT, GL_RGB10_A2UI);
524
525 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_FLOAT, GL_R16F);
526 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16_FLOAT, GL_RG16F);
527 AddDXGIToESEntry(&map, DXGI_FORMAT_R16G16B16A16_FLOAT, GL_RGBA16F);
528
529 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_FLOAT, GL_R32F);
530 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32_FLOAT, GL_RG32F);
531 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32_FLOAT, GL_RGB32F);
532 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G32B32A32_FLOAT, GL_RGBA32F);
533
534 AddDXGIToESEntry(&map, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, GL_RGB9_E5);
535 AddDXGIToESEntry(&map, DXGI_FORMAT_R11G11B10_FLOAT, GL_R11F_G11F_B10F);
536
537 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_TYPELESS, GL_DEPTH_COMPONENT16);
538 AddDXGIToESEntry(&map, DXGI_FORMAT_R16_UNORM, GL_DEPTH_COMPONENT16);
539 AddDXGIToESEntry(&map, DXGI_FORMAT_D16_UNORM, GL_DEPTH_COMPONENT16);
540 AddDXGIToESEntry(&map, DXGI_FORMAT_R24G8_TYPELESS, GL_DEPTH24_STENCIL8_OES);
541 AddDXGIToESEntry(&map, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, GL_DEPTH24_STENCIL8_OES);
542 AddDXGIToESEntry(&map, DXGI_FORMAT_D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8_OES);
543 AddDXGIToESEntry(&map, DXGI_FORMAT_R32G8X24_TYPELESS, GL_DEPTH32F_STENCIL8);
544 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, GL_DEPTH32F_STENCIL8);
545 AddDXGIToESEntry(&map, DXGI_FORMAT_D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8);
Geoff Lang66aaf722014-06-05 12:42:07 -0400546 AddDXGIToESEntry(&map, DXGI_FORMAT_R32_TYPELESS, GL_DEPTH_COMPONENT32F);
547 AddDXGIToESEntry(&map, DXGI_FORMAT_D32_FLOAT, GL_DEPTH_COMPONENT32F);
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500548
549 AddDXGIToESEntry(&map, DXGI_FORMAT_BC1_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
550 AddDXGIToESEntry(&map, DXGI_FORMAT_BC2_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
551 AddDXGIToESEntry(&map, DXGI_FORMAT_BC3_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Jamie Madill707dbd72013-07-10 15:13:39 -0400552
553 return map;
554}
555
Geoff Lange4a492b2014-06-19 14:14:41 -0400556static const DXGIToESFormatMap &GetDXGIToESFormatMap()
557{
558 static const DXGIToESFormatMap map = BuildDXGIToESFormatMap();
559 return map;
560}
561
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500562static const DXGIFormatInfoMap &GetDXGIFormatInfoMap()
Geoff Lang61e49a52013-05-29 10:22:58 -0400563{
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500564 static const DXGIFormatInfoMap infoMap = BuildDXGIFormatInfoMap();
565 return infoMap;
566}
567
568static bool GetDXGIFormatInfo(DXGI_FORMAT format, DXGIFormatInfo *outFormatInfo)
569{
570 const DXGIFormatInfoMap &infoMap = GetDXGIFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000571 DXGIFormatInfoMap::const_iterator iter = infoMap.find(format);
572 if (iter != infoMap.end())
573 {
574 if (outFormatInfo)
575 {
576 *outFormatInfo = iter->second;
577 }
578 return true;
579 }
580 else
581 {
582 return false;
583 }
584}
585
Geoff Lang61e49a52013-05-29 10:22:58 -0400586static d3d11::DXGIFormatSet BuildAllDXGIFormatSet()
587{
588 d3d11::DXGIFormatSet set;
589
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500590 const DXGIFormatInfoMap &infoMap = GetDXGIFormatInfoMap();
591 for (DXGIFormatInfoMap::const_iterator i = infoMap.begin(); i != infoMap.end(); ++i)
Geoff Lang61e49a52013-05-29 10:22:58 -0400592 {
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500593 set.insert(i->first);
Geoff Lang61e49a52013-05-29 10:22:58 -0400594 }
595
596 return set;
597}
598
Geoff Langfe28ca02013-06-04 10:10:48 -0400599struct D3D11FastCopyFormat
600{
601 DXGI_FORMAT mSourceFormat;
602 GLenum mDestFormat;
603 GLenum mDestType;
604
605 D3D11FastCopyFormat(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType)
606 : mSourceFormat(sourceFormat), mDestFormat(destFormat), mDestType(destType)
607 { }
608
609 bool operator<(const D3D11FastCopyFormat& other) const
610 {
611 return memcmp(this, &other, sizeof(D3D11FastCopyFormat)) < 0;
612 }
613};
614
615typedef std::map<D3D11FastCopyFormat, ColorCopyFunction> D3D11FastCopyMap;
616typedef std::pair<D3D11FastCopyFormat, ColorCopyFunction> D3D11FastCopyPair;
617
618static D3D11FastCopyMap BuildFastCopyMap()
619{
620 D3D11FastCopyMap map;
621
622 map.insert(D3D11FastCopyPair(D3D11FastCopyFormat(DXGI_FORMAT_B8G8R8A8_UNORM, GL_RGBA, GL_UNSIGNED_BYTE), CopyBGRAUByteToRGBAUByte));
623
624 return map;
625}
626
Geoff Langd8c86132013-06-12 11:17:24 -0400627struct DXGIDepthStencilInfo
628{
629 unsigned int mDepthBits;
630 unsigned int mDepthOffset;
631 unsigned int mStencilBits;
632 unsigned int mStencilOffset;
633
634 DXGIDepthStencilInfo()
635 : mDepthBits(0), mDepthOffset(0), mStencilBits(0), mStencilOffset(0)
636 { }
637
638 DXGIDepthStencilInfo(unsigned int depthBits, unsigned int depthOffset, unsigned int stencilBits, unsigned int stencilOffset)
639 : mDepthBits(depthBits), mDepthOffset(depthOffset), mStencilBits(stencilBits), mStencilOffset(stencilOffset)
640 { }
641};
642
643typedef std::map<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoMap;
644typedef std::pair<DXGI_FORMAT, DXGIDepthStencilInfo> DepthStencilInfoPair;
645
646static DepthStencilInfoMap BuildDepthStencilInfoMap()
647{
648 DepthStencilInfoMap map;
649
650 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R16_TYPELESS, DXGIDepthStencilInfo(16, 0, 0, 0)));
651 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R16_UNORM, DXGIDepthStencilInfo(16, 0, 0, 0)));
652 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D16_UNORM, DXGIDepthStencilInfo(16, 0, 0, 0)));
653
654 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R24G8_TYPELESS, DXGIDepthStencilInfo(24, 0, 8, 24)));
655 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGIDepthStencilInfo(24, 0, 8, 24)));
656 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D24_UNORM_S8_UINT, DXGIDepthStencilInfo(24, 0, 8, 24)));
657
658 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32_TYPELESS, DXGIDepthStencilInfo(32, 0, 0, 0)));
659 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32_FLOAT, DXGIDepthStencilInfo(32, 0, 0, 0)));
660 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D32_FLOAT, DXGIDepthStencilInfo(32, 0, 0, 0)));
661
662 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32G8X24_TYPELESS, DXGIDepthStencilInfo(32, 0, 8, 32)));
663 map.insert(DepthStencilInfoPair(DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGIDepthStencilInfo(32, 0, 8, 32)));
664 map.insert(DepthStencilInfoPair(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, DXGIDepthStencilInfo(32, 0, 8, 32)));
665
666 return map;
667}
668
669static const DepthStencilInfoMap &GetDepthStencilInfoMap()
670{
671 static const DepthStencilInfoMap infoMap = BuildDepthStencilInfoMap();
672 return infoMap;
673}
674
675bool GetDepthStencilInfo(DXGI_FORMAT format, DXGIDepthStencilInfo *outDepthStencilInfo)
676{
677 const DepthStencilInfoMap& infoMap = GetDepthStencilInfoMap();
678 DepthStencilInfoMap::const_iterator iter = infoMap.find(format);
679 if (iter != infoMap.end())
680 {
681 if (outDepthStencilInfo)
682 {
683 *outDepthStencilInfo = iter->second;
684 }
685 return true;
686 }
687 else
688 {
689 return false;
690 }
691}
692
Geoff Lang00f6bc32013-09-20 14:59:06 -0400693struct SwizzleSizeType
694{
695 unsigned int mMaxComponentSize;
696 GLenum mComponentType;
697
698 SwizzleSizeType()
699 : mMaxComponentSize(0), mComponentType(GL_NONE)
700 { }
701
702 SwizzleSizeType(unsigned int maxComponentSize, GLenum componentType)
703 : mMaxComponentSize(maxComponentSize), mComponentType(componentType)
704 { }
705
706 bool operator<(const SwizzleSizeType& other) const
707 {
708 return (mMaxComponentSize != other.mMaxComponentSize) ? (mMaxComponentSize < other.mMaxComponentSize)
709 : (mComponentType < other.mComponentType);
710 }
711};
712
713struct SwizzleFormatInfo
714{
715 DXGI_FORMAT mTexFormat;
716 DXGI_FORMAT mSRVFormat;
717 DXGI_FORMAT mRTVFormat;
718
719 SwizzleFormatInfo()
720 : mTexFormat(DXGI_FORMAT_UNKNOWN), mSRVFormat(DXGI_FORMAT_UNKNOWN), mRTVFormat(DXGI_FORMAT_UNKNOWN)
721 { }
722
723 SwizzleFormatInfo(DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat)
724 : mTexFormat(texFormat), mSRVFormat(srvFormat), mRTVFormat(rtvFormat)
725 { }
726};
727
728typedef std::map<SwizzleSizeType, SwizzleFormatInfo> SwizzleInfoMap;
729typedef std::pair<SwizzleSizeType, SwizzleFormatInfo> SwizzleInfoPair;
730
731static SwizzleInfoMap BuildSwizzleInfoMap()
732{
733 SwizzleInfoMap map;
734
735 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 -0500736 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_UNSIGNED_NORMALIZED), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM)));
737 map.insert(SwizzleInfoPair(SwizzleSizeType(24, GL_UNSIGNED_NORMALIZED), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT)));
738 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 -0400739
740 map.insert(SwizzleInfoPair(SwizzleSizeType( 8, GL_SIGNED_NORMALIZED ), SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM )));
741
742 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_FLOAT ), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT)));
743 map.insert(SwizzleInfoPair(SwizzleSizeType(32, GL_FLOAT ), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT)));
744
745 map.insert(SwizzleInfoPair(SwizzleSizeType( 8, GL_UNSIGNED_INT ), SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT )));
746 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_UNSIGNED_INT ), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT )));
747 map.insert(SwizzleInfoPair(SwizzleSizeType(32, GL_UNSIGNED_INT ), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT )));
748
749 map.insert(SwizzleInfoPair(SwizzleSizeType( 8, GL_INT ), SwizzleFormatInfo(DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT )));
750 map.insert(SwizzleInfoPair(SwizzleSizeType(16, GL_INT ), SwizzleFormatInfo(DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT )));
751 map.insert(SwizzleInfoPair(SwizzleSizeType(32, GL_INT ), SwizzleFormatInfo(DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT )));
752
753 return map;
754}
Geoff Lang0c99b1b2013-09-30 15:07:43 -0400755typedef std::pair<GLint, InitializeTextureDataFunction> InternalFormatInitializerPair;
756typedef std::map<GLint, InitializeTextureDataFunction> InternalFormatInitializerMap;
757
758static InternalFormatInitializerMap BuildInternalFormatInitializerMap()
759{
760 InternalFormatInitializerMap map;
761
762 map.insert(InternalFormatInitializerPair(GL_RGB8, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF> ));
763 map.insert(InternalFormatInitializerPair(GL_RGB565, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF> ));
764 map.insert(InternalFormatInitializerPair(GL_SRGB8, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0xFF> ));
765 map.insert(InternalFormatInitializerPair(GL_RGB16F, initialize4ComponentData<GLhalf, 0x0000, 0x0000, 0x0000, gl::Float16One>));
766 map.insert(InternalFormatInitializerPair(GL_RGB32F, initialize4ComponentData<GLfloat, 0x00000000, 0x00000000, 0x00000000, gl::Float32One>));
767 map.insert(InternalFormatInitializerPair(GL_RGB8UI, initialize4ComponentData<GLubyte, 0x00, 0x00, 0x00, 0x01> ));
768 map.insert(InternalFormatInitializerPair(GL_RGB8I, initialize4ComponentData<GLbyte, 0x00, 0x00, 0x00, 0x01> ));
769 map.insert(InternalFormatInitializerPair(GL_RGB16UI, initialize4ComponentData<GLushort, 0x0000, 0x0000, 0x0000, 0x0001> ));
770 map.insert(InternalFormatInitializerPair(GL_RGB16I, initialize4ComponentData<GLshort, 0x0000, 0x0000, 0x0000, 0x0001> ));
771 map.insert(InternalFormatInitializerPair(GL_RGB32UI, initialize4ComponentData<GLuint, 0x00000000, 0x00000000, 0x00000000, 0x00000001> ));
772 map.insert(InternalFormatInitializerPair(GL_RGB32I, initialize4ComponentData<GLint, 0x00000000, 0x00000000, 0x00000000, 0x00000001> ));
773
774 return map;
775}
Geoff Lang00f6bc32013-09-20 14:59:06 -0400776
777static const SwizzleInfoMap &GetSwizzleInfoMap()
778{
779 static const SwizzleInfoMap map = BuildSwizzleInfoMap();
780 return map;
781}
782
Geoff Lange4a492b2014-06-19 14:14:41 -0400783static const SwizzleFormatInfo GetSwizzleFormatInfo(GLenum internalFormat)
Geoff Lang00f6bc32013-09-20 14:59:06 -0400784{
785 // Get the maximum sized component
Jamie Madill80b5a552014-01-03 10:57:11 -0500786 unsigned int maxBits = 1;
787
Geoff Lange4a492b2014-06-19 14:14:41 -0400788 if (gl::IsFormatCompressed(internalFormat))
Jamie Madill80b5a552014-01-03 10:57:11 -0500789 {
Geoff Lange4a492b2014-06-19 14:14:41 -0400790 unsigned int compressedBitsPerBlock = gl::GetPixelBytes(internalFormat) * 8;
791 unsigned int blockSize = gl::GetCompressedBlockWidth(internalFormat) *
792 gl::GetCompressedBlockHeight(internalFormat);
Geoff Lang67938ef2014-01-07 16:17:21 -0500793 maxBits = std::max(compressedBitsPerBlock / blockSize, maxBits);
Jamie Madill80b5a552014-01-03 10:57:11 -0500794 }
795 else
796 {
Geoff Lange4a492b2014-06-19 14:14:41 -0400797 maxBits = std::max(maxBits, gl::GetAlphaBits( internalFormat));
798 maxBits = std::max(maxBits, gl::GetRedBits( internalFormat));
799 maxBits = std::max(maxBits, gl::GetGreenBits( internalFormat));
800 maxBits = std::max(maxBits, gl::GetBlueBits( internalFormat));
801 maxBits = std::max(maxBits, gl::GetLuminanceBits(internalFormat));
802 maxBits = std::max(maxBits, gl::GetDepthBits( internalFormat));
Jamie Madill80b5a552014-01-03 10:57:11 -0500803 }
804
Geoff Lang00f6bc32013-09-20 14:59:06 -0400805 maxBits = roundUp(maxBits, 8U);
806
Geoff Lange4a492b2014-06-19 14:14:41 -0400807 GLenum componentType = gl::GetComponentType(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -0400808
809 const SwizzleInfoMap &map = GetSwizzleInfoMap();
810 SwizzleInfoMap::const_iterator iter = map.find(SwizzleSizeType(maxBits, componentType));
811
812 if (iter != map.end())
813 {
814 return iter->second;
815 }
816 else
817 {
818 UNREACHABLE();
819 static const SwizzleFormatInfo defaultFormatInfo;
820 return defaultFormatInfo;
821 }
822}
823
Geoff Lang0c99b1b2013-09-30 15:07:43 -0400824static const InternalFormatInitializerMap &GetInternalFormatInitializerMap()
825{
826 static const InternalFormatInitializerMap map = BuildInternalFormatInitializerMap();
827 return map;
828}
829
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000830namespace d3d11
831{
832
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500833MipGenerationFunction GetMipGenerationFunction(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000834{
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000835 DXGIFormatInfo formatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500836 if (GetDXGIFormatInfo(format, &formatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000837 {
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000838 return formatInfo.mMipGenerationFunction;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000839 }
840 else
841 {
842 UNREACHABLE();
843 return NULL;
844 }
845}
846
Geoff Lange4a492b2014-06-19 14:14:41 -0400847LoadImageFunction GetImageLoadFunction(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000848{
Geoff Lange4a492b2014-06-19 14:14:41 -0400849 static const D3D11LoadFunctionMap loadImageMap = buildD3D11LoadFunctionMap();
850 D3D11LoadFunctionMap::const_iterator iter = loadImageMap.find(InternalFormatTypePair(internalFormat, type));
851 if (iter != loadImageMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000852 {
Geoff Lange4a492b2014-06-19 14:14:41 -0400853 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000854 }
855 else
856 {
857 UNREACHABLE();
858 return NULL;
859 }
860}
861
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500862GLuint GetFormatPixelBytes(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000863{
864 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500865 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000866 {
867 return dxgiFormatInfo.mPixelBits / 8;
868 }
869 else
870 {
871 UNREACHABLE();
872 return 0;
873 }
874}
875
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500876GLuint GetBlockWidth(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000877{
878 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500879 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000880 {
881 return dxgiFormatInfo.mBlockWidth;
882 }
883 else
884 {
885 UNREACHABLE();
886 return 0;
887 }
888}
889
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500890GLuint GetBlockHeight(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000891{
892 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500893 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000894 {
895 return dxgiFormatInfo.mBlockHeight;
896 }
897 else
898 {
899 UNREACHABLE();
900 return 0;
901 }
902}
903
Jamie Madill826f3d32014-01-29 09:26:49 -0500904GLenum GetComponentType(DXGI_FORMAT format)
905{
906 DXGIFormatInfo dxgiFormatInfo;
907 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
908 {
909 return dxgiFormatInfo.mComponentType;
910 }
911 else
912 {
913 UNREACHABLE();
914 return GL_NONE;
915 }
916}
917
Geoff Langd8c86132013-06-12 11:17:24 -0400918GLuint GetDepthBits(DXGI_FORMAT format)
919{
920 DXGIDepthStencilInfo dxgiDSInfo;
921 if (GetDepthStencilInfo(format, &dxgiDSInfo))
922 {
923 return dxgiDSInfo.mDepthBits;
924 }
925 else
926 {
927 // Since the depth stencil info map does not contain all used DXGI formats,
928 // we should not assert that the format exists
929 return 0;
930 }
931}
932
933GLuint GetDepthOffset(DXGI_FORMAT format)
934{
935 DXGIDepthStencilInfo dxgiDSInfo;
936 if (GetDepthStencilInfo(format, &dxgiDSInfo))
937 {
938 return dxgiDSInfo.mDepthOffset;
939 }
940 else
941 {
942 // Since the depth stencil info map does not contain all used DXGI formats,
943 // we should not assert that the format exists
944 return 0;
945 }
946}
947
948GLuint GetStencilBits(DXGI_FORMAT format)
949{
950 DXGIDepthStencilInfo dxgiDSInfo;
951 if (GetDepthStencilInfo(format, &dxgiDSInfo))
952 {
953 return dxgiDSInfo.mStencilBits;
954 }
955 else
956 {
957 // Since the depth stencil info map does not contain all used DXGI formats,
958 // we should not assert that the format exists
959 return 0;
960 }
961}
962
963GLuint GetStencilOffset(DXGI_FORMAT format)
964{
965 DXGIDepthStencilInfo dxgiDSInfo;
966 if (GetDepthStencilInfo(format, &dxgiDSInfo))
967 {
968 return dxgiDSInfo.mStencilOffset;
969 }
970 else
971 {
972 // Since the depth stencil info map does not contain all used DXGI formats,
973 // we should not assert that the format exists
974 return 0;
975 }
976}
977
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500978void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000979{
980 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500981 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000982 {
983 int upsampleCount = 0;
984
985 GLsizei blockWidth = dxgiFormatInfo.mBlockWidth;
986 GLsizei blockHeight = dxgiFormatInfo.mBlockHeight;
987
988 // Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
989 if (isImage || *requestWidth < blockWidth || *requestHeight < blockHeight)
990 {
991 while (*requestWidth % blockWidth != 0 || *requestHeight % blockHeight != 0)
992 {
993 *requestWidth <<= 1;
994 *requestHeight <<= 1;
995 upsampleCount++;
996 }
997 }
998 *levelOffset = upsampleCount;
999 }
1000 else
1001 {
1002 UNREACHABLE();
1003 }
1004}
1005
Geoff Lang61e49a52013-05-29 10:22:58 -04001006const DXGIFormatSet &GetAllUsedDXGIFormats()
1007{
1008 static DXGIFormatSet formatSet = BuildAllDXGIFormatSet();
1009 return formatSet;
1010}
1011
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001012ColorReadFunction GetColorReadFunction(DXGI_FORMAT format)
Geoff Langfe28ca02013-06-04 10:10:48 -04001013{
1014 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001015 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
Geoff Langfe28ca02013-06-04 10:10:48 -04001016 {
1017 return dxgiFormatInfo.mColorReadFunction;
1018 }
1019 else
1020 {
1021 UNREACHABLE();
1022 return NULL;
1023 }
1024}
1025
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001026ColorCopyFunction GetFastCopyFunction(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType)
Geoff Langfe28ca02013-06-04 10:10:48 -04001027{
1028 static const D3D11FastCopyMap fastCopyMap = BuildFastCopyMap();
1029 D3D11FastCopyMap::const_iterator iter = fastCopyMap.find(D3D11FastCopyFormat(sourceFormat, destFormat, destType));
1030 return (iter != fastCopyMap.end()) ? iter->second : NULL;
1031}
1032
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001033}
1034
1035namespace gl_d3d11
1036{
1037
Geoff Lange4a492b2014-06-19 14:14:41 -04001038DXGI_FORMAT GetTexFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001039{
Geoff Lange4a492b2014-06-19 14:14:41 -04001040 D3D11FormatInfo d3d11FormatInfo;
1041 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001042 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001043 return d3d11FormatInfo.mTexFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001044 }
1045 else
1046 {
1047 UNREACHABLE();
1048 return DXGI_FORMAT_UNKNOWN;
1049 }
1050}
1051
Geoff Lange4a492b2014-06-19 14:14:41 -04001052DXGI_FORMAT GetSRVFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001053{
Geoff Lange4a492b2014-06-19 14:14:41 -04001054 D3D11FormatInfo d3d11FormatInfo;
1055 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001056 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001057 return d3d11FormatInfo.mSRVFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001058 }
1059 else
1060 {
1061 UNREACHABLE();
1062 return DXGI_FORMAT_UNKNOWN;
1063 }
1064}
1065
Geoff Lange4a492b2014-06-19 14:14:41 -04001066DXGI_FORMAT GetRTVFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001067{
Geoff Lange4a492b2014-06-19 14:14:41 -04001068 D3D11FormatInfo d3d11FormatInfo;
1069 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001070 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001071 return d3d11FormatInfo.mRTVFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001072 }
1073 else
1074 {
1075 UNREACHABLE();
1076 return DXGI_FORMAT_UNKNOWN;
1077 }
1078}
1079
Geoff Lange4a492b2014-06-19 14:14:41 -04001080DXGI_FORMAT GetDSVFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001081{
Geoff Lange4a492b2014-06-19 14:14:41 -04001082 D3D11FormatInfo d3d11FormatInfo;
1083 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001084 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001085 return d3d11FormatInfo.mDSVFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001086 }
1087 else
1088 {
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001089 return DXGI_FORMAT_UNKNOWN;
1090 }
1091}
1092
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001093// Given a GL internal format, this function returns the DSV format if it is depth- or stencil-renderable,
1094// the RTV format if it is color-renderable, and the (nonrenderable) texture format otherwise.
Geoff Lange4a492b2014-06-19 14:14:41 -04001095DXGI_FORMAT GetRenderableFormat(GLenum internalFormat)
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001096{
Geoff Lange4a492b2014-06-19 14:14:41 -04001097 DXGI_FORMAT targetFormat = GetDSVFormat(internalFormat);
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001098 if (targetFormat == DXGI_FORMAT_UNKNOWN)
Geoff Lange4a492b2014-06-19 14:14:41 -04001099 targetFormat = GetRTVFormat(internalFormat);
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001100 if (targetFormat == DXGI_FORMAT_UNKNOWN)
Geoff Lange4a492b2014-06-19 14:14:41 -04001101 targetFormat = GetTexFormat(internalFormat);
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001102
1103 return targetFormat;
1104}
1105
Geoff Lange4a492b2014-06-19 14:14:41 -04001106DXGI_FORMAT GetSwizzleTexFormat(GLint internalFormat)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001107{
Geoff Lange4a492b2014-06-19 14:14:41 -04001108 if (GetRTVFormat(internalFormat) == DXGI_FORMAT_UNKNOWN || gl::GetComponentCount(internalFormat) != 4)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001109 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001110 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001111 return swizzleInfo.mTexFormat;
1112 }
1113 else
1114 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001115 return GetTexFormat(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001116 }
1117}
1118
Geoff Lange4a492b2014-06-19 14:14:41 -04001119DXGI_FORMAT GetSwizzleSRVFormat(GLint internalFormat)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001120{
Geoff Lange4a492b2014-06-19 14:14:41 -04001121 if (GetRTVFormat(internalFormat) == DXGI_FORMAT_UNKNOWN || gl::GetComponentCount(internalFormat) != 4)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001122 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001123 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001124 return swizzleInfo.mSRVFormat;
1125 }
1126 else
1127 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001128 return GetSRVFormat(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001129 }
1130}
1131
Geoff Lange4a492b2014-06-19 14:14:41 -04001132DXGI_FORMAT GetSwizzleRTVFormat(GLint internalFormat)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001133{
Geoff Lange4a492b2014-06-19 14:14:41 -04001134 if (GetRTVFormat(internalFormat) == DXGI_FORMAT_UNKNOWN || gl::GetComponentCount(internalFormat) != 4)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001135 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001136 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001137 return swizzleInfo.mRTVFormat;
1138 }
1139 else
1140 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001141 return GetRTVFormat(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001142 }
1143}
1144
Geoff Lang0c99b1b2013-09-30 15:07:43 -04001145bool RequiresTextureDataInitialization(GLint internalFormat)
1146{
1147 const InternalFormatInitializerMap &map = GetInternalFormatInitializerMap();
1148 return map.find(internalFormat) != map.end();
1149}
1150
1151InitializeTextureDataFunction GetTextureDataInitializationFunction(GLint internalFormat)
1152{
1153 const InternalFormatInitializerMap &map = GetInternalFormatInitializerMap();
1154 InternalFormatInitializerMap::const_iterator iter = map.find(internalFormat);
1155 if (iter != map.end())
1156 {
1157 return iter->second;
1158 }
1159 else
1160 {
1161 UNREACHABLE();
1162 return NULL;
1163 }
1164}
1165
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001166struct D3D11VertexFormatInfo
1167{
1168 rx::VertexConversionType mConversionType;
1169 DXGI_FORMAT mNativeFormat;
1170 VertexCopyFunction mCopyFunction;
1171
1172 D3D11VertexFormatInfo()
1173 : mConversionType(VERTEX_CONVERT_NONE),
1174 mNativeFormat(DXGI_FORMAT_UNKNOWN),
1175 mCopyFunction(NULL)
1176 {}
1177
1178 D3D11VertexFormatInfo(VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1179 : mConversionType(conversionType),
1180 mNativeFormat(nativeFormat),
1181 mCopyFunction(copyFunction)
1182 {}
1183};
1184
1185typedef std::map<gl::VertexFormat, D3D11VertexFormatInfo> D3D11VertexFormatInfoMap;
1186
1187typedef std::pair<gl::VertexFormat, D3D11VertexFormatInfo> D3D11VertexFormatPair;
1188
1189static void addVertexFormatInfo(D3D11VertexFormatInfoMap *map, GLenum inputType, GLboolean normalized, GLuint componentCount,
1190 VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1191{
1192 gl::VertexFormat inputFormat(inputType, normalized, componentCount, false);
1193 map->insert(D3D11VertexFormatPair(inputFormat, D3D11VertexFormatInfo(conversionType, nativeFormat, copyFunction)));
1194}
1195
1196static void addIntegerVertexFormatInfo(D3D11VertexFormatInfoMap *map, GLenum inputType, GLuint componentCount,
1197 VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1198{
1199 gl::VertexFormat inputFormat(inputType, GL_FALSE, componentCount, true);
1200 map->insert(D3D11VertexFormatPair(inputFormat, D3D11VertexFormatInfo(conversionType, nativeFormat, copyFunction)));
1201}
1202
1203static D3D11VertexFormatInfoMap BuildD3D11VertexFormatInfoMap()
1204{
1205 D3D11VertexFormatInfoMap map;
1206
1207 // TODO: column legend
1208
1209 //
1210 // Float formats
1211 //
1212
1213 // GL_BYTE -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001214 addVertexFormatInfo(&map, GL_BYTE, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_SINT, &copyVertexData<GLbyte, 1, 0>);
1215 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 -05001216 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 -05001217 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 -05001218
1219 // GL_BYTE -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001220 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SNORM, &copyVertexData<GLbyte, 1, 0>);
1221 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SNORM, &copyVertexData<GLbyte, 2, 0>);
1222 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SNORM, &copyVertexData<GLbyte, 3, INT8_MAX>);
1223 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 -05001224
1225 // GL_UNSIGNED_BYTE -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001226 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_UINT, &copyVertexData<GLubyte, 1, 0>);
1227 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 -05001228 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 -05001229 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 -05001230
1231 // GL_UNSIGNED_BYTE -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001232 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UNORM, &copyVertexData<GLubyte, 1, 0>);
1233 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UNORM, &copyVertexData<GLubyte, 2, 0>);
1234 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UNORM, &copyVertexData<GLubyte, 3, UINT8_MAX>);
1235 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 -05001236
1237 // GL_SHORT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001238 addVertexFormatInfo(&map, GL_SHORT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_SINT, &copyVertexData<GLshort, 1, 0>);
1239 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 -05001240 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 -05001241 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 -05001242
1243 // GL_SHORT -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001244 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SNORM, &copyVertexData<GLshort, 1, 0>);
1245 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SNORM, &copyVertexData<GLshort, 2, 0>);
1246 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SNORM, &copyVertexData<GLshort, 3, INT16_MAX>);
1247 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 -05001248
1249 // GL_UNSIGNED_SHORT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001250 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_UINT, &copyVertexData<GLushort, 1, 0>);
1251 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 -05001252 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 -05001253 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 -05001254
1255 // GL_UNSIGNED_SHORT -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001256 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UNORM, &copyVertexData<GLushort, 1, 0>);
1257 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UNORM, &copyVertexData<GLushort, 2, 0>);
1258 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UNORM, &copyVertexData<GLushort, 3, UINT16_MAX>);
1259 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 -05001260
1261 // GL_INT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001262 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_SINT, &copyVertexData<GLint, 1, 0>);
1263 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLint, 2, 0>);
1264 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 3, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLint, 3, 0>);
1265 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 -05001266
1267 // GL_INT -- normalized
1268 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 1, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, &copyToFloatVertexData<GLint, 1, true>);
1269 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 2, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, &copyToFloatVertexData<GLint, 2, true>);
1270 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyToFloatVertexData<GLint, 3, true>);
1271 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyToFloatVertexData<GLint, 4, true>);
1272
1273 // GL_UNSIGNED_INT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001274 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_UINT, &copyVertexData<GLuint, 1, 0>);
1275 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_UINT, &copyVertexData<GLuint, 2, 0>);
1276 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 3, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_UINT, &copyVertexData<GLuint, 3, 0>);
1277 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 -05001278
1279 // GL_UNSIGNED_INT -- normalized
1280 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_FLOAT, &copyToFloatVertexData<GLuint, 1, true>);
1281 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_FLOAT, &copyToFloatVertexData<GLuint, 2, true>);
1282 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyToFloatVertexData<GLuint, 3, true>);
1283 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyToFloatVertexData<GLuint, 4, true>);
1284
1285 // GL_FIXED
1286 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 1, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, &copyFixedVertexData<1>);
1287 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 2, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, &copyFixedVertexData<2>);
1288 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyFixedVertexData<3>);
1289 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyFixedVertexData<4>);
1290
1291 // GL_HALF_FLOAT
Jamie Madill2f612292014-03-05 09:53:29 -05001292 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_FLOAT, &copyVertexData<GLhalf, 1, 0>);
1293 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_FLOAT, &copyVertexData<GLhalf, 2, 0>);
1294 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_FLOAT, &copyVertexData<GLhalf, 3, gl::Float16One>);
1295 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 -05001296
1297 // GL_FLOAT
Jamie Madill2f612292014-03-05 09:53:29 -05001298 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_FLOAT, &copyVertexData<GLfloat, 1, 0>);
1299 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_FLOAT, &copyVertexData<GLfloat, 2, 0>);
1300 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_FLOAT, &copyVertexData<GLfloat, 3, 0>);
1301 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 -05001302
1303 // GL_INT_2_10_10_10_REV
1304 addVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, GL_FALSE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyPackedVertexData<true, false, true>);
1305 addVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, GL_TRUE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyPackedVertexData<true, true, true>);
1306
1307 // GL_UNSIGNED_INT_2_10_10_10_REV
Jamie Madill0c667202014-03-17 10:06:09 -04001308 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 -05001309 addVertexFormatInfo(&map, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UNORM, &copyPackedUnsignedVertexData);
1310
1311 //
1312 // Integer Formats
1313 //
1314
1315 // GL_BYTE
Jamie Madill2f612292014-03-05 09:53:29 -05001316 addIntegerVertexFormatInfo(&map, GL_BYTE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SINT, &copyVertexData<GLbyte, 1, 0>);
1317 addIntegerVertexFormatInfo(&map, GL_BYTE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SINT, &copyVertexData<GLbyte, 2, 0>);
1318 addIntegerVertexFormatInfo(&map, GL_BYTE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 3, 1>);
1319 addIntegerVertexFormatInfo(&map, GL_BYTE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001320
1321 // GL_UNSIGNED_BYTE
Jamie Madill2f612292014-03-05 09:53:29 -05001322 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UINT, &copyVertexData<GLubyte, 1, 0>);
1323 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UINT, &copyVertexData<GLubyte, 2, 0>);
1324 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 3, 1>);
1325 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001326
1327 // GL_SHORT
Jamie Madill2f612292014-03-05 09:53:29 -05001328 addIntegerVertexFormatInfo(&map, GL_SHORT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SINT, &copyVertexData<GLshort, 1, 0>);
1329 addIntegerVertexFormatInfo(&map, GL_SHORT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SINT, &copyVertexData<GLshort, 2, 0>);
1330 addIntegerVertexFormatInfo(&map, GL_SHORT, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 3, 1>);
1331 addIntegerVertexFormatInfo(&map, GL_SHORT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001332
1333 // GL_UNSIGNED_SHORT
Jamie Madill2f612292014-03-05 09:53:29 -05001334 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UINT, &copyVertexData<GLushort, 1, 0>);
1335 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UINT, &copyVertexData<GLushort, 2, 0>);
1336 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 3, 1>);
1337 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001338
1339 // GL_INT
Jamie Madill2f612292014-03-05 09:53:29 -05001340 addIntegerVertexFormatInfo(&map, GL_INT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, &copyVertexData<GLint, 1, 0>);
1341 addIntegerVertexFormatInfo(&map, GL_INT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLint, 2, 0>);
1342 addIntegerVertexFormatInfo(&map, GL_INT, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLint, 3, 0>);
1343 addIntegerVertexFormatInfo(&map, GL_INT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, &copyVertexData<GLint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001344
1345 // GL_UNSIGNED_INT
Jamie Madill2f612292014-03-05 09:53:29 -05001346 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, &copyVertexData<GLuint, 1, 0>);
1347 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLuint, 2, 0>);
1348 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLuint, 3, 0>);
1349 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, &copyVertexData<GLuint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001350
1351 // GL_INT_2_10_10_10_REV
1352 addIntegerVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, &copyPackedVertexData<true, true, false>);
1353
1354 // GL_UNSIGNED_INT_2_10_10_10_REV
1355 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT_2_10_10_10_REV, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UINT, &copyPackedUnsignedVertexData);
1356
1357 return map;
1358}
1359
1360static bool GetD3D11VertexFormatInfo(const gl::VertexFormat &vertexFormat, D3D11VertexFormatInfo *outVertexFormatInfo)
1361{
1362 static const D3D11VertexFormatInfoMap vertexFormatMap = BuildD3D11VertexFormatInfoMap();
1363
1364 D3D11VertexFormatInfoMap::const_iterator iter = vertexFormatMap.find(vertexFormat);
1365 if (iter != vertexFormatMap.end())
1366 {
1367 if (outVertexFormatInfo)
1368 {
1369 *outVertexFormatInfo = iter->second;
1370 }
1371 return true;
1372 }
1373 else
1374 {
1375 return false;
1376 }
1377}
1378
1379VertexCopyFunction GetVertexCopyFunction(const gl::VertexFormat &vertexFormat)
1380{
1381 D3D11VertexFormatInfo vertexFormatInfo;
1382 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1383 {
1384 return vertexFormatInfo.mCopyFunction;
1385 }
1386 else
1387 {
1388 UNREACHABLE();
1389 return NULL;
1390 }
1391}
1392
1393size_t GetVertexElementSize(const gl::VertexFormat &vertexFormat)
1394{
1395 D3D11VertexFormatInfo vertexFormatInfo;
1396 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1397 {
1398 // FIXME: should not need a client version, and is not a pixel!
1399 return d3d11::GetFormatPixelBytes(vertexFormatInfo.mNativeFormat);
1400 }
1401 else
1402 {
1403 UNREACHABLE();
1404 return 0;
1405 }
1406}
1407
1408rx::VertexConversionType GetVertexConversionType(const gl::VertexFormat &vertexFormat)
1409{
1410 D3D11VertexFormatInfo vertexFormatInfo;
1411 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1412 {
1413 return vertexFormatInfo.mConversionType;
1414 }
1415 else
1416 {
1417 UNREACHABLE();
1418 return VERTEX_CONVERT_NONE;
1419 }
1420}
1421
1422DXGI_FORMAT GetNativeVertexFormat(const gl::VertexFormat &vertexFormat)
1423{
1424 D3D11VertexFormatInfo vertexFormatInfo;
1425 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1426 {
1427 return vertexFormatInfo.mNativeFormat;
1428 }
1429 else
1430 {
1431 UNREACHABLE();
1432 return DXGI_FORMAT_UNKNOWN;
1433 }
1434}
1435
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001436}
1437
1438namespace d3d11_gl
1439{
1440
Geoff Lange4a492b2014-06-19 14:14:41 -04001441GLenum GetInternalFormat(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001442{
Geoff Lange4a492b2014-06-19 14:14:41 -04001443 const DXGIToESFormatMap &formatMap = GetDXGIToESFormatMap();
1444 DXGIToESFormatMap::const_iterator iter = formatMap.find(format);
1445 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001446 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001447 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001448 }
Geoff Lang66aaf722014-06-05 12:42:07 -04001449 else
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001450 {
Geoff Lang66aaf722014-06-05 12:42:07 -04001451 UNREACHABLE();
1452 return GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001453 }
1454}
1455
1456}
1457
1458}