blob: 506404b376900f3384cdd1e518e930a7202ee317 [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
Geoff Lang86846e22014-06-03 15:48:54 -0400186static void UnimplementedLoadFunction(size_t width, size_t height, size_t depth,
187 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
188 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000189{
190 UNIMPLEMENTED();
191}
192
Geoff Lang86846e22014-06-03 15:48:54 -0400193static void UnreachableLoadFunction(size_t width, size_t height, size_t depth,
194 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
195 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Langd3ff2162013-06-07 15:10:59 -0400196{
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 |
Geoff Lang86846e22014-06-03 15:48:54 -0400212 insertLoadFunction(&map, GL_RGBA8, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 4> );
213 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 4> );
214 insertLoadFunction(&map, GL_RGBA4, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 4> );
215 insertLoadFunction(&map, GL_SRGB8_ALPHA8, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 4> );
216 insertLoadFunction(&map, GL_RGBA8_SNORM, GL_BYTE, LoadToNative<GLbyte, 4> );
217 insertLoadFunction(&map, GL_RGBA4, GL_UNSIGNED_SHORT_4_4_4_4, LoadRGBA4ToRGBA8 );
218 insertLoadFunction(&map, GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV, LoadToNative<GLuint, 1> );
219 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_SHORT_5_5_5_1, LoadRGB5A1ToRGBA8 );
220 insertLoadFunction(&map, GL_RGB5_A1, GL_UNSIGNED_INT_2_10_10_10_REV, LoadRGB10A2ToRGBA8 );
221 insertLoadFunction(&map, GL_RGBA16F, GL_HALF_FLOAT, LoadToNative<GLhalf, 4> );
222 insertLoadFunction(&map, GL_RGBA16F, GL_HALF_FLOAT_OES, LoadToNative<GLhalf, 4> );
223 insertLoadFunction(&map, GL_RGBA32F, GL_FLOAT, LoadToNative<GLfloat, 4> );
224 insertLoadFunction(&map, GL_RGBA16F, GL_FLOAT, Load32FTo16F<4> );
225 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> );
232 insertLoadFunction(&map, GL_RGB8, GL_UNSIGNED_BYTE, LoadToNative3To4<GLubyte, 0xFF> );
233 insertLoadFunction(&map, GL_RGB565, GL_UNSIGNED_BYTE, LoadToNative3To4<GLubyte, 0xFF> );
234 insertLoadFunction(&map, GL_SRGB8, GL_UNSIGNED_BYTE, LoadToNative3To4<GLubyte, 0xFF> );
235 insertLoadFunction(&map, GL_RGB8_SNORM, GL_BYTE, LoadToNative3To4<GLbyte, 0x7F> );
236 insertLoadFunction(&map, GL_RGB565, GL_UNSIGNED_SHORT_5_6_5, LoadR5G6B5ToRGBA8 );
237 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_UNSIGNED_INT_10F_11F_11F_REV, LoadToNative<GLuint, 1> );
238 insertLoadFunction(&map, GL_RGB9_E5, GL_UNSIGNED_INT_5_9_9_9_REV, LoadToNative<GLuint, 1> );
239 insertLoadFunction(&map, GL_RGB16F, GL_HALF_FLOAT, LoadToNative3To4<GLhalf, gl::Float16One>);
240 insertLoadFunction(&map, GL_RGB16F, GL_HALF_FLOAT_OES, LoadToNative3To4<GLhalf, gl::Float16One>);
241 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_HALF_FLOAT, LoadRGB16FToRG11B10F );
242 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_HALF_FLOAT_OES, LoadRGB16FToRG11B10F );
243 insertLoadFunction(&map, GL_RGB9_E5, GL_HALF_FLOAT, LoadRGB16FToRGB9E5 );
244 insertLoadFunction(&map, GL_RGB9_E5, GL_HALF_FLOAT_OES, LoadRGB16FToRGB9E5 );
245 insertLoadFunction(&map, GL_RGB32F, GL_FLOAT, LoadToNative3To4<GLfloat, gl::Float32One>);
246 insertLoadFunction(&map, GL_RGB16F, GL_FLOAT, LoadRGB32FToRGBA16F );
247 insertLoadFunction(&map, GL_R11F_G11F_B10F, GL_FLOAT, LoadRGB32FToRG11B10F );
248 insertLoadFunction(&map, GL_RGB9_E5, GL_FLOAT, LoadRGB32FToRGB9E5 );
249 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> );
253 insertLoadFunction(&map, GL_RGB32UI, GL_UNSIGNED_INT, LoadToNative3To4<GLuint, 0x00000001> );
254 insertLoadFunction(&map, GL_RGB32I, GL_INT, LoadToNative3To4<GLint, 0x00000001> );
255 insertLoadFunction(&map, GL_RG8, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 2> );
256 insertLoadFunction(&map, GL_RG8_SNORM, GL_BYTE, LoadToNative<GLbyte, 2> );
257 insertLoadFunction(&map, GL_RG16F, GL_HALF_FLOAT, LoadToNative<GLhalf, 2> );
258 insertLoadFunction(&map, GL_RG16F, GL_HALF_FLOAT_OES, LoadToNative<GLhalf, 2> );
259 insertLoadFunction(&map, GL_RG32F, GL_FLOAT, LoadToNative<GLfloat, 2> );
260 insertLoadFunction(&map, GL_RG16F, GL_FLOAT, Load32FTo16F<2> );
261 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> );
267 insertLoadFunction(&map, GL_R8, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 1> );
268 insertLoadFunction(&map, GL_R8_SNORM, GL_BYTE, LoadToNative<GLbyte, 1> );
269 insertLoadFunction(&map, GL_R16F, GL_HALF_FLOAT, LoadToNative<GLhalf, 1> );
270 insertLoadFunction(&map, GL_R16F, GL_HALF_FLOAT_OES, LoadToNative<GLhalf, 1> );
271 insertLoadFunction(&map, GL_R32F, GL_FLOAT, LoadToNative<GLfloat, 1> );
272 insertLoadFunction(&map, GL_R16F, GL_FLOAT, Load32FTo16F<1> );
273 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> );
279 insertLoadFunction(&map, GL_DEPTH_COMPONENT16, GL_UNSIGNED_SHORT, LoadToNative<GLushort, 1> );
280 insertLoadFunction(&map, GL_DEPTH_COMPONENT24, GL_UNSIGNED_INT, LoadR32ToR24G8 );
281 insertLoadFunction(&map, GL_DEPTH_COMPONENT16, GL_UNSIGNED_INT, LoadR32ToR16 );
282 insertLoadFunction(&map, GL_DEPTH_COMPONENT32F, GL_FLOAT, LoadToNative<GLfloat, 1> );
283 insertLoadFunction(&map, GL_DEPTH24_STENCIL8, GL_UNSIGNED_INT_24_8, LoadR32ToR24G8 );
284 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
Geoff Lang86846e22014-06-03 15:48:54 -0400299 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, LoadLA32FToRGBA32F );
300 insertLoadFunction(&map, GL_LUMINANCE, GL_FLOAT, LoadL32FToRGBA32F );
301 insertLoadFunction(&map, GL_ALPHA, GL_FLOAT, LoadA32FToRGBA32F );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000302
303 // From GL_OES_texture_half_float
Geoff Lang86846e22014-06-03 15:48:54 -0400304 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, LoadLA16FToRGBA16F );
305 insertLoadFunction(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, LoadLA16FToRGBA16F );
306 insertLoadFunction(&map, GL_LUMINANCE, GL_HALF_FLOAT, LoadL16FToRGBA16F );
307 insertLoadFunction(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, LoadL16FToRGBA16F );
308 insertLoadFunction(&map, GL_ALPHA, GL_HALF_FLOAT, LoadA16FToRGBA16F );
309 insertLoadFunction(&map, GL_ALPHA, GL_HALF_FLOAT_OES, LoadA16FToRGBA16F );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000310
311 // From GL_EXT_texture_storage
Geoff Lang86846e22014-06-03 15:48:54 -0400312 insertLoadFunction(&map, GL_ALPHA8_EXT, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 1> );
313 insertLoadFunction(&map, GL_LUMINANCE8_EXT, GL_UNSIGNED_BYTE, LoadL8ToRGBA8 );
314 insertLoadFunction(&map, GL_LUMINANCE8_ALPHA8_EXT, GL_UNSIGNED_BYTE, LoadLA8ToRGBA8 );
315 insertLoadFunction(&map, GL_ALPHA32F_EXT, GL_FLOAT, LoadA32FToRGBA32F );
316 insertLoadFunction(&map, GL_LUMINANCE32F_EXT, GL_FLOAT, LoadL32FToRGBA32F );
317 insertLoadFunction(&map, GL_LUMINANCE_ALPHA32F_EXT, GL_FLOAT, LoadLA32FToRGBA32F );
318 insertLoadFunction(&map, GL_ALPHA16F_EXT, GL_HALF_FLOAT, LoadA16FToRGBA16F );
319 insertLoadFunction(&map, GL_ALPHA16F_EXT, GL_HALF_FLOAT_OES, LoadA16FToRGBA16F );
320 insertLoadFunction(&map, GL_LUMINANCE16F_EXT, GL_HALF_FLOAT, LoadL16FToRGBA16F );
321 insertLoadFunction(&map, GL_LUMINANCE16F_EXT, GL_HALF_FLOAT_OES, LoadL16FToRGBA16F );
322 insertLoadFunction(&map, GL_LUMINANCE_ALPHA16F_EXT, GL_HALF_FLOAT, LoadLA16FToRGBA16F );
323 insertLoadFunction(&map, GL_LUMINANCE_ALPHA16F_EXT, GL_HALF_FLOAT_OES, LoadLA16FToRGBA16F );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000324
Geoff Lange4a492b2014-06-19 14:14:41 -0400325 // From GL_ANGLE_depth_texture
Geoff Lang86846e22014-06-03 15:48:54 -0400326 insertLoadFunction(&map, GL_DEPTH_COMPONENT32_OES, GL_UNSIGNED_INT, LoadR32ToR24G8 );
Geoff Lange4a492b2014-06-19 14:14:41 -0400327
328 // From GL_EXT_texture_format_BGRA8888
Geoff Lang86846e22014-06-03 15:48:54 -0400329 insertLoadFunction(&map, GL_BGRA8_EXT, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 4> );
330 insertLoadFunction(&map, GL_BGRA4_ANGLEX, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, LoadRGBA4ToRGBA8 );
331 insertLoadFunction(&map, GL_BGRA4_ANGLEX, GL_UNSIGNED_BYTE, LoadToNative<GLubyte, 4> );
332 insertLoadFunction(&map, GL_BGR5_A1_ANGLEX, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, LoadRGB5A1ToRGBA8 );
333 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
Geoff Lang86846e22014-06-03 15:48:54 -0400351 insertLoadFunction(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, LoadCompressedToNative<4, 4, 8>);
352 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, LoadCompressedToNative<4, 4, 8>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000353
354 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang86846e22014-06-03 15:48:54 -0400355 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, LoadCompressedToNative<4, 4, 16>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000356
357 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang86846e22014-06-03 15:48:54 -0400358 insertLoadFunction(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, LoadCompressedToNative<4, 4, 16>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000359
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
Geoff Lang86846e22014-06-03 15:48:54 -0400762 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> ));
Geoff Lang0c99b1b2013-09-30 15:07:43 -0400773
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 Lang5d601382014-07-22 15:14:06 -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 Lang5d601382014-07-22 15:14:06 -0400788 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
789
790 if (formatInfo.compressed)
Jamie Madill80b5a552014-01-03 10:57:11 -0500791 {
Geoff Lang5d601382014-07-22 15:14:06 -0400792 unsigned int compressedBitsPerBlock = formatInfo.pixelBytes * 8;
793 unsigned int blockSize = formatInfo.compressedBlockWidth * formatInfo.compressedBlockHeight;
Geoff Lang67938ef2014-01-07 16:17:21 -0500794 maxBits = std::max(compressedBitsPerBlock / blockSize, maxBits);
Jamie Madill80b5a552014-01-03 10:57:11 -0500795 }
796 else
797 {
Geoff Lang5d601382014-07-22 15:14:06 -0400798 maxBits = std::max(maxBits, formatInfo.alphaBits);
799 maxBits = std::max(maxBits, formatInfo.redBits);
800 maxBits = std::max(maxBits, formatInfo.greenBits);
801 maxBits = std::max(maxBits, formatInfo.blueBits);
802 maxBits = std::max(maxBits, formatInfo.luminanceBits);
803 maxBits = std::max(maxBits, formatInfo.depthBits);
Jamie Madill80b5a552014-01-03 10:57:11 -0500804 }
805
Geoff Lang00f6bc32013-09-20 14:59:06 -0400806 maxBits = roundUp(maxBits, 8U);
807
Geoff Lang00f6bc32013-09-20 14:59:06 -0400808 const SwizzleInfoMap &map = GetSwizzleInfoMap();
Geoff Lang5d601382014-07-22 15:14:06 -0400809 SwizzleInfoMap::const_iterator iter = map.find(SwizzleSizeType(maxBits, formatInfo.componentType));
Geoff Lang00f6bc32013-09-20 14:59:06 -0400810
811 if (iter != map.end())
812 {
813 return iter->second;
814 }
815 else
816 {
817 UNREACHABLE();
818 static const SwizzleFormatInfo defaultFormatInfo;
819 return defaultFormatInfo;
820 }
821}
822
Geoff Lang0c99b1b2013-09-30 15:07:43 -0400823static const InternalFormatInitializerMap &GetInternalFormatInitializerMap()
824{
825 static const InternalFormatInitializerMap map = BuildInternalFormatInitializerMap();
826 return map;
827}
828
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000829namespace d3d11
830{
831
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500832MipGenerationFunction GetMipGenerationFunction(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000833{
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000834 DXGIFormatInfo formatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500835 if (GetDXGIFormatInfo(format, &formatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000836 {
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000837 return formatInfo.mMipGenerationFunction;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000838 }
839 else
840 {
841 UNREACHABLE();
842 return NULL;
843 }
844}
845
Geoff Lange4a492b2014-06-19 14:14:41 -0400846LoadImageFunction GetImageLoadFunction(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000847{
Geoff Lange4a492b2014-06-19 14:14:41 -0400848 static const D3D11LoadFunctionMap loadImageMap = buildD3D11LoadFunctionMap();
849 D3D11LoadFunctionMap::const_iterator iter = loadImageMap.find(InternalFormatTypePair(internalFormat, type));
850 if (iter != loadImageMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000851 {
Geoff Lange4a492b2014-06-19 14:14:41 -0400852 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000853 }
854 else
855 {
856 UNREACHABLE();
857 return NULL;
858 }
859}
860
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500861GLuint GetFormatPixelBytes(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000862{
863 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500864 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000865 {
866 return dxgiFormatInfo.mPixelBits / 8;
867 }
868 else
869 {
870 UNREACHABLE();
871 return 0;
872 }
873}
874
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500875GLuint GetBlockWidth(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000876{
877 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500878 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000879 {
880 return dxgiFormatInfo.mBlockWidth;
881 }
882 else
883 {
884 UNREACHABLE();
885 return 0;
886 }
887}
888
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500889GLuint GetBlockHeight(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000890{
891 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500892 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000893 {
894 return dxgiFormatInfo.mBlockHeight;
895 }
896 else
897 {
898 UNREACHABLE();
899 return 0;
900 }
901}
902
Jamie Madill826f3d32014-01-29 09:26:49 -0500903GLenum GetComponentType(DXGI_FORMAT format)
904{
905 DXGIFormatInfo dxgiFormatInfo;
906 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
907 {
908 return dxgiFormatInfo.mComponentType;
909 }
910 else
911 {
912 UNREACHABLE();
913 return GL_NONE;
914 }
915}
916
Geoff Langd8c86132013-06-12 11:17:24 -0400917GLuint GetDepthBits(DXGI_FORMAT format)
918{
919 DXGIDepthStencilInfo dxgiDSInfo;
920 if (GetDepthStencilInfo(format, &dxgiDSInfo))
921 {
922 return dxgiDSInfo.mDepthBits;
923 }
924 else
925 {
926 // Since the depth stencil info map does not contain all used DXGI formats,
927 // we should not assert that the format exists
928 return 0;
929 }
930}
931
932GLuint GetDepthOffset(DXGI_FORMAT format)
933{
934 DXGIDepthStencilInfo dxgiDSInfo;
935 if (GetDepthStencilInfo(format, &dxgiDSInfo))
936 {
937 return dxgiDSInfo.mDepthOffset;
938 }
939 else
940 {
941 // Since the depth stencil info map does not contain all used DXGI formats,
942 // we should not assert that the format exists
943 return 0;
944 }
945}
946
947GLuint GetStencilBits(DXGI_FORMAT format)
948{
949 DXGIDepthStencilInfo dxgiDSInfo;
950 if (GetDepthStencilInfo(format, &dxgiDSInfo))
951 {
952 return dxgiDSInfo.mStencilBits;
953 }
954 else
955 {
956 // Since the depth stencil info map does not contain all used DXGI formats,
957 // we should not assert that the format exists
958 return 0;
959 }
960}
961
962GLuint GetStencilOffset(DXGI_FORMAT format)
963{
964 DXGIDepthStencilInfo dxgiDSInfo;
965 if (GetDepthStencilInfo(format, &dxgiDSInfo))
966 {
967 return dxgiDSInfo.mStencilOffset;
968 }
969 else
970 {
971 // Since the depth stencil info map does not contain all used DXGI formats,
972 // we should not assert that the format exists
973 return 0;
974 }
975}
976
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500977void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000978{
979 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -0500980 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000981 {
982 int upsampleCount = 0;
983
984 GLsizei blockWidth = dxgiFormatInfo.mBlockWidth;
985 GLsizei blockHeight = dxgiFormatInfo.mBlockHeight;
986
987 // Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
988 if (isImage || *requestWidth < blockWidth || *requestHeight < blockHeight)
989 {
990 while (*requestWidth % blockWidth != 0 || *requestHeight % blockHeight != 0)
991 {
992 *requestWidth <<= 1;
993 *requestHeight <<= 1;
994 upsampleCount++;
995 }
996 }
997 *levelOffset = upsampleCount;
998 }
999 else
1000 {
1001 UNREACHABLE();
1002 }
1003}
1004
Geoff Lang61e49a52013-05-29 10:22:58 -04001005const DXGIFormatSet &GetAllUsedDXGIFormats()
1006{
1007 static DXGIFormatSet formatSet = BuildAllDXGIFormatSet();
1008 return formatSet;
1009}
1010
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001011ColorReadFunction GetColorReadFunction(DXGI_FORMAT format)
Geoff Langfe28ca02013-06-04 10:10:48 -04001012{
1013 DXGIFormatInfo dxgiFormatInfo;
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001014 if (GetDXGIFormatInfo(format, &dxgiFormatInfo))
Geoff Langfe28ca02013-06-04 10:10:48 -04001015 {
1016 return dxgiFormatInfo.mColorReadFunction;
1017 }
1018 else
1019 {
1020 UNREACHABLE();
1021 return NULL;
1022 }
1023}
1024
Jamie Madill9eeecfc2014-01-29 09:26:48 -05001025ColorCopyFunction GetFastCopyFunction(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType)
Geoff Langfe28ca02013-06-04 10:10:48 -04001026{
1027 static const D3D11FastCopyMap fastCopyMap = BuildFastCopyMap();
1028 D3D11FastCopyMap::const_iterator iter = fastCopyMap.find(D3D11FastCopyFormat(sourceFormat, destFormat, destType));
1029 return (iter != fastCopyMap.end()) ? iter->second : NULL;
1030}
1031
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001032}
1033
1034namespace gl_d3d11
1035{
1036
Geoff Lange4a492b2014-06-19 14:14:41 -04001037DXGI_FORMAT GetTexFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001038{
Geoff Lange4a492b2014-06-19 14:14:41 -04001039 D3D11FormatInfo d3d11FormatInfo;
1040 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001041 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001042 return d3d11FormatInfo.mTexFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001043 }
1044 else
1045 {
1046 UNREACHABLE();
1047 return DXGI_FORMAT_UNKNOWN;
1048 }
1049}
1050
Geoff Lange4a492b2014-06-19 14:14:41 -04001051DXGI_FORMAT GetSRVFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001052{
Geoff Lange4a492b2014-06-19 14:14:41 -04001053 D3D11FormatInfo d3d11FormatInfo;
1054 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001055 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001056 return d3d11FormatInfo.mSRVFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001057 }
1058 else
1059 {
1060 UNREACHABLE();
1061 return DXGI_FORMAT_UNKNOWN;
1062 }
1063}
1064
Geoff Lange4a492b2014-06-19 14:14:41 -04001065DXGI_FORMAT GetRTVFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001066{
Geoff Lange4a492b2014-06-19 14:14:41 -04001067 D3D11FormatInfo d3d11FormatInfo;
1068 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001069 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001070 return d3d11FormatInfo.mRTVFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001071 }
1072 else
1073 {
1074 UNREACHABLE();
1075 return DXGI_FORMAT_UNKNOWN;
1076 }
1077}
1078
Geoff Lange4a492b2014-06-19 14:14:41 -04001079DXGI_FORMAT GetDSVFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001080{
Geoff Lange4a492b2014-06-19 14:14:41 -04001081 D3D11FormatInfo d3d11FormatInfo;
1082 if (GetD3D11FormatInfo(internalFormat, &d3d11FormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001083 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001084 return d3d11FormatInfo.mDSVFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001085 }
1086 else
1087 {
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001088 return DXGI_FORMAT_UNKNOWN;
1089 }
1090}
1091
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001092// Given a GL internal format, this function returns the DSV format if it is depth- or stencil-renderable,
1093// the RTV format if it is color-renderable, and the (nonrenderable) texture format otherwise.
Geoff Lange4a492b2014-06-19 14:14:41 -04001094DXGI_FORMAT GetRenderableFormat(GLenum internalFormat)
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001095{
Geoff Lange4a492b2014-06-19 14:14:41 -04001096 DXGI_FORMAT targetFormat = GetDSVFormat(internalFormat);
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001097 if (targetFormat == DXGI_FORMAT_UNKNOWN)
Geoff Lange4a492b2014-06-19 14:14:41 -04001098 targetFormat = GetRTVFormat(internalFormat);
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001099 if (targetFormat == DXGI_FORMAT_UNKNOWN)
Geoff Lange4a492b2014-06-19 14:14:41 -04001100 targetFormat = GetTexFormat(internalFormat);
Shannon Woodsdd4674f2013-07-08 10:32:15 -04001101
1102 return targetFormat;
1103}
1104
Geoff Lange4a492b2014-06-19 14:14:41 -04001105DXGI_FORMAT GetSwizzleTexFormat(GLint internalFormat)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001106{
Geoff Lang5d601382014-07-22 15:14:06 -04001107 if (GetRTVFormat(internalFormat) == DXGI_FORMAT_UNKNOWN || gl::GetInternalFormatInfo(internalFormat).componentCount != 4)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001108 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001109 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001110 return swizzleInfo.mTexFormat;
1111 }
1112 else
1113 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001114 return GetTexFormat(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001115 }
1116}
1117
Geoff Lange4a492b2014-06-19 14:14:41 -04001118DXGI_FORMAT GetSwizzleSRVFormat(GLint internalFormat)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001119{
Geoff Lang5d601382014-07-22 15:14:06 -04001120 if (GetRTVFormat(internalFormat) == DXGI_FORMAT_UNKNOWN || gl::GetInternalFormatInfo(internalFormat).componentCount != 4)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001121 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001122 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001123 return swizzleInfo.mSRVFormat;
1124 }
1125 else
1126 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001127 return GetSRVFormat(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001128 }
1129}
1130
Geoff Lange4a492b2014-06-19 14:14:41 -04001131DXGI_FORMAT GetSwizzleRTVFormat(GLint internalFormat)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001132{
Geoff Lang5d601382014-07-22 15:14:06 -04001133 if (GetRTVFormat(internalFormat) == DXGI_FORMAT_UNKNOWN || gl::GetInternalFormatInfo(internalFormat).componentCount != 4)
Geoff Lang00f6bc32013-09-20 14:59:06 -04001134 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001135 const SwizzleFormatInfo &swizzleInfo = GetSwizzleFormatInfo(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001136 return swizzleInfo.mRTVFormat;
1137 }
1138 else
1139 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001140 return GetRTVFormat(internalFormat);
Geoff Lang00f6bc32013-09-20 14:59:06 -04001141 }
1142}
1143
Geoff Lang0c99b1b2013-09-30 15:07:43 -04001144bool RequiresTextureDataInitialization(GLint internalFormat)
1145{
1146 const InternalFormatInitializerMap &map = GetInternalFormatInitializerMap();
1147 return map.find(internalFormat) != map.end();
1148}
1149
1150InitializeTextureDataFunction GetTextureDataInitializationFunction(GLint internalFormat)
1151{
1152 const InternalFormatInitializerMap &map = GetInternalFormatInitializerMap();
1153 InternalFormatInitializerMap::const_iterator iter = map.find(internalFormat);
1154 if (iter != map.end())
1155 {
1156 return iter->second;
1157 }
1158 else
1159 {
1160 UNREACHABLE();
1161 return NULL;
1162 }
1163}
1164
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001165struct D3D11VertexFormatInfo
1166{
1167 rx::VertexConversionType mConversionType;
1168 DXGI_FORMAT mNativeFormat;
1169 VertexCopyFunction mCopyFunction;
1170
1171 D3D11VertexFormatInfo()
1172 : mConversionType(VERTEX_CONVERT_NONE),
1173 mNativeFormat(DXGI_FORMAT_UNKNOWN),
1174 mCopyFunction(NULL)
1175 {}
1176
1177 D3D11VertexFormatInfo(VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1178 : mConversionType(conversionType),
1179 mNativeFormat(nativeFormat),
1180 mCopyFunction(copyFunction)
1181 {}
1182};
1183
1184typedef std::map<gl::VertexFormat, D3D11VertexFormatInfo> D3D11VertexFormatInfoMap;
1185
1186typedef std::pair<gl::VertexFormat, D3D11VertexFormatInfo> D3D11VertexFormatPair;
1187
1188static void addVertexFormatInfo(D3D11VertexFormatInfoMap *map, GLenum inputType, GLboolean normalized, GLuint componentCount,
1189 VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1190{
1191 gl::VertexFormat inputFormat(inputType, normalized, componentCount, false);
1192 map->insert(D3D11VertexFormatPair(inputFormat, D3D11VertexFormatInfo(conversionType, nativeFormat, copyFunction)));
1193}
1194
1195static void addIntegerVertexFormatInfo(D3D11VertexFormatInfoMap *map, GLenum inputType, GLuint componentCount,
1196 VertexConversionType conversionType, DXGI_FORMAT nativeFormat, VertexCopyFunction copyFunction)
1197{
1198 gl::VertexFormat inputFormat(inputType, GL_FALSE, componentCount, true);
1199 map->insert(D3D11VertexFormatPair(inputFormat, D3D11VertexFormatInfo(conversionType, nativeFormat, copyFunction)));
1200}
1201
1202static D3D11VertexFormatInfoMap BuildD3D11VertexFormatInfoMap()
1203{
1204 D3D11VertexFormatInfoMap map;
1205
1206 // TODO: column legend
1207
1208 //
1209 // Float formats
1210 //
1211
1212 // GL_BYTE -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001213 addVertexFormatInfo(&map, GL_BYTE, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_SINT, &copyVertexData<GLbyte, 1, 0>);
1214 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 -05001215 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 -05001216 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 -05001217
1218 // GL_BYTE -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001219 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SNORM, &copyVertexData<GLbyte, 1, 0>);
1220 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SNORM, &copyVertexData<GLbyte, 2, 0>);
1221 addVertexFormatInfo(&map, GL_BYTE, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SNORM, &copyVertexData<GLbyte, 3, INT8_MAX>);
1222 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 -05001223
1224 // GL_UNSIGNED_BYTE -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001225 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R8_UINT, &copyVertexData<GLubyte, 1, 0>);
1226 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 -05001227 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 -05001228 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 -05001229
1230 // GL_UNSIGNED_BYTE -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001231 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UNORM, &copyVertexData<GLubyte, 1, 0>);
1232 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UNORM, &copyVertexData<GLubyte, 2, 0>);
1233 addVertexFormatInfo(&map, GL_UNSIGNED_BYTE, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UNORM, &copyVertexData<GLubyte, 3, UINT8_MAX>);
1234 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 -05001235
1236 // GL_SHORT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001237 addVertexFormatInfo(&map, GL_SHORT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_SINT, &copyVertexData<GLshort, 1, 0>);
1238 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 -05001239 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 -05001240 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 -05001241
1242 // GL_SHORT -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001243 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SNORM, &copyVertexData<GLshort, 1, 0>);
1244 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SNORM, &copyVertexData<GLshort, 2, 0>);
1245 addVertexFormatInfo(&map, GL_SHORT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SNORM, &copyVertexData<GLshort, 3, INT16_MAX>);
1246 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 -05001247
1248 // GL_UNSIGNED_SHORT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001249 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R16_UINT, &copyVertexData<GLushort, 1, 0>);
1250 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 -05001251 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 -05001252 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 -05001253
1254 // GL_UNSIGNED_SHORT -- normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001255 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UNORM, &copyVertexData<GLushort, 1, 0>);
1256 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UNORM, &copyVertexData<GLushort, 2, 0>);
1257 addVertexFormatInfo(&map, GL_UNSIGNED_SHORT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UNORM, &copyVertexData<GLushort, 3, UINT16_MAX>);
1258 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 -05001259
1260 // GL_INT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001261 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_SINT, &copyVertexData<GLint, 1, 0>);
1262 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLint, 2, 0>);
1263 addVertexFormatInfo(&map, GL_INT, GL_FALSE, 3, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLint, 3, 0>);
1264 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 -05001265
1266 // GL_INT -- normalized
1267 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 1, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, &copyToFloatVertexData<GLint, 1, true>);
1268 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 2, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, &copyToFloatVertexData<GLint, 2, true>);
1269 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyToFloatVertexData<GLint, 3, true>);
1270 addVertexFormatInfo(&map, GL_INT, GL_TRUE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyToFloatVertexData<GLint, 4, true>);
1271
1272 // GL_UNSIGNED_INT -- un-normalized
Jamie Madill2f612292014-03-05 09:53:29 -05001273 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 1, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32_UINT, &copyVertexData<GLuint, 1, 0>);
1274 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 2, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32_UINT, &copyVertexData<GLuint, 2, 0>);
1275 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_FALSE, 3, VERTEX_CONVERT_GPU, DXGI_FORMAT_R32G32B32_UINT, &copyVertexData<GLuint, 3, 0>);
1276 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 -05001277
1278 // GL_UNSIGNED_INT -- normalized
1279 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_FLOAT, &copyToFloatVertexData<GLuint, 1, true>);
1280 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_FLOAT, &copyToFloatVertexData<GLuint, 2, true>);
1281 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyToFloatVertexData<GLuint, 3, true>);
1282 addVertexFormatInfo(&map, GL_UNSIGNED_INT, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyToFloatVertexData<GLuint, 4, true>);
1283
1284 // GL_FIXED
1285 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 1, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32_FLOAT, &copyFixedVertexData<1>);
1286 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 2, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32_FLOAT, &copyFixedVertexData<2>);
1287 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32_FLOAT, &copyFixedVertexData<3>);
1288 addVertexFormatInfo(&map, GL_FIXED, GL_FALSE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyFixedVertexData<4>);
1289
1290 // GL_HALF_FLOAT
Jamie Madill2f612292014-03-05 09:53:29 -05001291 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_FLOAT, &copyVertexData<GLhalf, 1, 0>);
1292 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_FLOAT, &copyVertexData<GLhalf, 2, 0>);
1293 addVertexFormatInfo(&map, GL_HALF_FLOAT, GL_FALSE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_FLOAT, &copyVertexData<GLhalf, 3, gl::Float16One>);
1294 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 -05001295
1296 // GL_FLOAT
Jamie Madill2f612292014-03-05 09:53:29 -05001297 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_FLOAT, &copyVertexData<GLfloat, 1, 0>);
1298 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_FLOAT, &copyVertexData<GLfloat, 2, 0>);
1299 addVertexFormatInfo(&map, GL_FLOAT, GL_FALSE, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_FLOAT, &copyVertexData<GLfloat, 3, 0>);
1300 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 -05001301
1302 // GL_INT_2_10_10_10_REV
1303 addVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, GL_FALSE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyPackedVertexData<true, false, true>);
1304 addVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, GL_TRUE, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R32G32B32A32_FLOAT, &copyPackedVertexData<true, true, true>);
1305
1306 // GL_UNSIGNED_INT_2_10_10_10_REV
Jamie Madill0c667202014-03-17 10:06:09 -04001307 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 -05001308 addVertexFormatInfo(&map, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UNORM, &copyPackedUnsignedVertexData);
1309
1310 //
1311 // Integer Formats
1312 //
1313
1314 // GL_BYTE
Jamie Madill2f612292014-03-05 09:53:29 -05001315 addIntegerVertexFormatInfo(&map, GL_BYTE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_SINT, &copyVertexData<GLbyte, 1, 0>);
1316 addIntegerVertexFormatInfo(&map, GL_BYTE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_SINT, &copyVertexData<GLbyte, 2, 0>);
1317 addIntegerVertexFormatInfo(&map, GL_BYTE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 3, 1>);
1318 addIntegerVertexFormatInfo(&map, GL_BYTE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_SINT, &copyVertexData<GLbyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001319
1320 // GL_UNSIGNED_BYTE
Jamie Madill2f612292014-03-05 09:53:29 -05001321 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8_UINT, &copyVertexData<GLubyte, 1, 0>);
1322 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8_UINT, &copyVertexData<GLubyte, 2, 0>);
1323 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 3, 1>);
1324 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_BYTE, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R8G8B8A8_UINT, &copyVertexData<GLubyte, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001325
1326 // GL_SHORT
Jamie Madill2f612292014-03-05 09:53:29 -05001327 addIntegerVertexFormatInfo(&map, GL_SHORT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_SINT, &copyVertexData<GLshort, 1, 0>);
1328 addIntegerVertexFormatInfo(&map, GL_SHORT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_SINT, &copyVertexData<GLshort, 2, 0>);
1329 addIntegerVertexFormatInfo(&map, GL_SHORT, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 3, 1>);
1330 addIntegerVertexFormatInfo(&map, GL_SHORT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_SINT, &copyVertexData<GLshort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001331
1332 // GL_UNSIGNED_SHORT
Jamie Madill2f612292014-03-05 09:53:29 -05001333 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16_UINT, &copyVertexData<GLushort, 1, 0>);
1334 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16_UINT, &copyVertexData<GLushort, 2, 0>);
1335 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 3, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 3, 1>);
1336 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_SHORT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R16G16B16A16_UINT, &copyVertexData<GLushort, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001337
1338 // GL_INT
Jamie Madill2f612292014-03-05 09:53:29 -05001339 addIntegerVertexFormatInfo(&map, GL_INT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, &copyVertexData<GLint, 1, 0>);
1340 addIntegerVertexFormatInfo(&map, GL_INT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLint, 2, 0>);
1341 addIntegerVertexFormatInfo(&map, GL_INT, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLint, 3, 0>);
1342 addIntegerVertexFormatInfo(&map, GL_INT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, &copyVertexData<GLint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001343
1344 // GL_UNSIGNED_INT
Jamie Madill2f612292014-03-05 09:53:29 -05001345 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 1, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32_SINT, &copyVertexData<GLuint, 1, 0>);
1346 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 2, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32_SINT, &copyVertexData<GLuint, 2, 0>);
1347 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 3, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32_SINT, &copyVertexData<GLuint, 3, 0>);
1348 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R32G32B32A32_SINT, &copyVertexData<GLuint, 4, 0>);
Jamie Madill7ab02fa2014-02-04 16:04:08 -05001349
1350 // GL_INT_2_10_10_10_REV
1351 addIntegerVertexFormatInfo(&map, GL_INT_2_10_10_10_REV, 4, VERTEX_CONVERT_CPU, DXGI_FORMAT_R16G16B16A16_SINT, &copyPackedVertexData<true, true, false>);
1352
1353 // GL_UNSIGNED_INT_2_10_10_10_REV
1354 addIntegerVertexFormatInfo(&map, GL_UNSIGNED_INT_2_10_10_10_REV, 4, VERTEX_CONVERT_NONE, DXGI_FORMAT_R10G10B10A2_UINT, &copyPackedUnsignedVertexData);
1355
1356 return map;
1357}
1358
1359static bool GetD3D11VertexFormatInfo(const gl::VertexFormat &vertexFormat, D3D11VertexFormatInfo *outVertexFormatInfo)
1360{
1361 static const D3D11VertexFormatInfoMap vertexFormatMap = BuildD3D11VertexFormatInfoMap();
1362
1363 D3D11VertexFormatInfoMap::const_iterator iter = vertexFormatMap.find(vertexFormat);
1364 if (iter != vertexFormatMap.end())
1365 {
1366 if (outVertexFormatInfo)
1367 {
1368 *outVertexFormatInfo = iter->second;
1369 }
1370 return true;
1371 }
1372 else
1373 {
1374 return false;
1375 }
1376}
1377
1378VertexCopyFunction GetVertexCopyFunction(const gl::VertexFormat &vertexFormat)
1379{
1380 D3D11VertexFormatInfo vertexFormatInfo;
1381 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1382 {
1383 return vertexFormatInfo.mCopyFunction;
1384 }
1385 else
1386 {
1387 UNREACHABLE();
1388 return NULL;
1389 }
1390}
1391
1392size_t GetVertexElementSize(const gl::VertexFormat &vertexFormat)
1393{
1394 D3D11VertexFormatInfo vertexFormatInfo;
1395 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1396 {
1397 // FIXME: should not need a client version, and is not a pixel!
1398 return d3d11::GetFormatPixelBytes(vertexFormatInfo.mNativeFormat);
1399 }
1400 else
1401 {
1402 UNREACHABLE();
1403 return 0;
1404 }
1405}
1406
1407rx::VertexConversionType GetVertexConversionType(const gl::VertexFormat &vertexFormat)
1408{
1409 D3D11VertexFormatInfo vertexFormatInfo;
1410 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1411 {
1412 return vertexFormatInfo.mConversionType;
1413 }
1414 else
1415 {
1416 UNREACHABLE();
1417 return VERTEX_CONVERT_NONE;
1418 }
1419}
1420
1421DXGI_FORMAT GetNativeVertexFormat(const gl::VertexFormat &vertexFormat)
1422{
1423 D3D11VertexFormatInfo vertexFormatInfo;
1424 if (GetD3D11VertexFormatInfo(vertexFormat, &vertexFormatInfo))
1425 {
1426 return vertexFormatInfo.mNativeFormat;
1427 }
1428 else
1429 {
1430 UNREACHABLE();
1431 return DXGI_FORMAT_UNKNOWN;
1432 }
1433}
1434
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001435}
1436
1437namespace d3d11_gl
1438{
1439
Geoff Lange4a492b2014-06-19 14:14:41 -04001440GLenum GetInternalFormat(DXGI_FORMAT format)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001441{
Geoff Lange4a492b2014-06-19 14:14:41 -04001442 const DXGIToESFormatMap &formatMap = GetDXGIToESFormatMap();
1443 DXGIToESFormatMap::const_iterator iter = formatMap.find(format);
1444 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001445 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001446 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001447 }
Geoff Lang66aaf722014-06-05 12:42:07 -04001448 else
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001449 {
Geoff Lang66aaf722014-06-05 12:42:07 -04001450 UNREACHABLE();
1451 return GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001452 }
1453}
1454
1455}
1456
1457}