2018-03-25 03:09:30 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <glad/glad.h>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2018-04-07 10:54:52 +02:00
|
|
|
using GLvec2 = std::array<GLfloat, 2>;
|
|
|
|
using GLvec3 = std::array<GLfloat, 3>;
|
|
|
|
using GLvec4 = std::array<GLfloat, 4>;
|
|
|
|
|
|
|
|
using GLuvec2 = std::array<GLuint, 2>;
|
|
|
|
using GLuvec3 = std::array<GLuint, 3>;
|
|
|
|
using GLuvec4 = std::array<GLuint, 4>;
|
|
|
|
|
2018-03-25 03:09:30 +02:00
|
|
|
namespace MaxwellToGL {
|
|
|
|
|
|
|
|
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
|
|
|
|
|
|
|
inline GLenum VertexType(Maxwell::VertexAttribute attrib) {
|
|
|
|
switch (attrib.type) {
|
2019-04-03 09:33:36 +02:00
|
|
|
case Maxwell::VertexAttribute::Type::UnsignedNorm:
|
2020-06-28 08:48:14 +02:00
|
|
|
case Maxwell::VertexAttribute::Type::UnsignedScaled:
|
|
|
|
case Maxwell::VertexAttribute::Type::UnsignedInt:
|
2018-03-25 03:09:30 +02:00
|
|
|
switch (attrib.size) {
|
2018-08-13 07:18:13 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8:
|
2018-08-08 07:09:44 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8_8:
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8_8_8:
|
2018-03-25 03:09:30 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8_8_8_8:
|
|
|
|
return GL_UNSIGNED_BYTE;
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_16:
|
2018-07-04 22:22:34 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16:
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16_16:
|
2018-08-09 04:07:16 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16_16_16:
|
2018-07-04 22:22:34 +02:00
|
|
|
return GL_UNSIGNED_SHORT;
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32_32_32:
|
|
|
|
return GL_UNSIGNED_INT;
|
2018-07-04 22:22:34 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_10_10_10_2:
|
|
|
|
return GL_UNSIGNED_INT_2_10_10_10_REV;
|
2018-03-25 03:09:30 +02:00
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
break;
|
2019-04-03 09:33:36 +02:00
|
|
|
case Maxwell::VertexAttribute::Type::SignedNorm:
|
2020-06-28 08:48:14 +02:00
|
|
|
case Maxwell::VertexAttribute::Type::SignedScaled:
|
|
|
|
case Maxwell::VertexAttribute::Type::SignedInt:
|
2018-04-29 19:50:02 +02:00
|
|
|
switch (attrib.size) {
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8:
|
2018-08-10 18:17:49 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8_8:
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8_8_8:
|
2018-04-29 19:50:02 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_8_8_8_8:
|
|
|
|
return GL_BYTE;
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_16:
|
2018-07-04 22:22:34 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16:
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16_16:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16_16_16:
|
2018-07-04 22:22:34 +02:00
|
|
|
return GL_SHORT;
|
2018-08-15 00:53:11 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32_32_32:
|
|
|
|
return GL_INT;
|
2018-07-04 22:22:34 +02:00
|
|
|
case Maxwell::VertexAttribute::Size::Size_10_10_10_2:
|
|
|
|
return GL_INT_2_10_10_10_REV;
|
2018-04-29 19:50:02 +02:00
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
break;
|
2019-04-03 09:33:36 +02:00
|
|
|
case Maxwell::VertexAttribute::Type::Float:
|
2018-10-22 15:27:00 +02:00
|
|
|
switch (attrib.size) {
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_16:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16_16:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_16_16_16_16:
|
|
|
|
return GL_HALF_FLOAT;
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32_32:
|
|
|
|
case Maxwell::VertexAttribute::Size::Size_32_32_32_32:
|
|
|
|
return GL_FLOAT;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
break;
|
2018-10-22 15:27:00 +02:00
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented vertex type={} and size={}", attrib.TypeString(),
|
|
|
|
attrib.SizeString());
|
|
|
|
return {};
|
2018-03-25 03:09:30 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 20:18:37 +02:00
|
|
|
inline GLenum IndexFormat(Maxwell::IndexFormat index_format) {
|
|
|
|
switch (index_format) {
|
|
|
|
case Maxwell::IndexFormat::UnsignedByte:
|
|
|
|
return GL_UNSIGNED_BYTE;
|
|
|
|
case Maxwell::IndexFormat::UnsignedShort:
|
|
|
|
return GL_UNSIGNED_SHORT;
|
|
|
|
case Maxwell::IndexFormat::UnsignedInt:
|
|
|
|
return GL_UNSIGNED_INT;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNREACHABLE_MSG("Invalid index_format={}", static_cast<u32>(index_format));
|
2018-04-13 20:18:37 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-03-27 02:09:01 +02:00
|
|
|
inline GLenum PrimitiveTopology(Maxwell::PrimitiveTopology topology) {
|
|
|
|
switch (topology) {
|
2018-08-09 04:16:27 +02:00
|
|
|
case Maxwell::PrimitiveTopology::Points:
|
|
|
|
return GL_POINTS;
|
2018-08-22 07:01:06 +02:00
|
|
|
case Maxwell::PrimitiveTopology::Lines:
|
|
|
|
return GL_LINES;
|
2019-12-23 02:14:37 +01:00
|
|
|
case Maxwell::PrimitiveTopology::LineLoop:
|
|
|
|
return GL_LINE_LOOP;
|
2018-08-13 05:07:44 +02:00
|
|
|
case Maxwell::PrimitiveTopology::LineStrip:
|
|
|
|
return GL_LINE_STRIP;
|
2018-04-07 10:54:52 +02:00
|
|
|
case Maxwell::PrimitiveTopology::Triangles:
|
|
|
|
return GL_TRIANGLES;
|
2018-03-27 02:09:01 +02:00
|
|
|
case Maxwell::PrimitiveTopology::TriangleStrip:
|
|
|
|
return GL_TRIANGLE_STRIP;
|
2019-05-18 00:58:02 +02:00
|
|
|
case Maxwell::PrimitiveTopology::TriangleFan:
|
|
|
|
return GL_TRIANGLE_FAN;
|
2019-05-22 00:21:57 +02:00
|
|
|
case Maxwell::PrimitiveTopology::Quads:
|
|
|
|
return GL_QUADS;
|
2019-12-23 02:14:37 +01:00
|
|
|
case Maxwell::PrimitiveTopology::QuadStrip:
|
|
|
|
return GL_QUAD_STRIP;
|
|
|
|
case Maxwell::PrimitiveTopology::Polygon:
|
|
|
|
return GL_POLYGON;
|
|
|
|
case Maxwell::PrimitiveTopology::LinesAdjacency:
|
|
|
|
return GL_LINES_ADJACENCY;
|
|
|
|
case Maxwell::PrimitiveTopology::LineStripAdjacency:
|
|
|
|
return GL_LINE_STRIP_ADJACENCY;
|
|
|
|
case Maxwell::PrimitiveTopology::TrianglesAdjacency:
|
|
|
|
return GL_TRIANGLES_ADJACENCY;
|
|
|
|
case Maxwell::PrimitiveTopology::TriangleStripAdjacency:
|
|
|
|
return GL_TRIANGLE_STRIP_ADJACENCY;
|
|
|
|
case Maxwell::PrimitiveTopology::Patches:
|
|
|
|
return GL_PATCHES;
|
2018-03-27 02:09:01 +02:00
|
|
|
}
|
2019-12-23 02:14:37 +01:00
|
|
|
UNREACHABLE_MSG("Invalid topology={}", static_cast<int>(topology));
|
|
|
|
return GL_POINTS;
|
2018-03-27 02:09:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 01:25:28 +02:00
|
|
|
inline GLenum TextureFilterMode(Tegra::Texture::TextureFilter filter_mode,
|
2020-06-13 14:17:37 +02:00
|
|
|
Tegra::Texture::TextureMipmapFilter mipmap_filter_mode) {
|
2018-03-27 04:41:05 +02:00
|
|
|
switch (filter_mode) {
|
2020-06-13 14:17:37 +02:00
|
|
|
case Tegra::Texture::TextureFilter::Nearest:
|
|
|
|
switch (mipmap_filter_mode) {
|
2018-10-25 01:25:28 +02:00
|
|
|
case Tegra::Texture::TextureMipmapFilter::None:
|
2020-06-13 14:17:37 +02:00
|
|
|
return GL_NEAREST;
|
2018-10-25 01:25:28 +02:00
|
|
|
case Tegra::Texture::TextureMipmapFilter::Nearest:
|
2020-06-13 14:17:37 +02:00
|
|
|
return GL_NEAREST_MIPMAP_NEAREST;
|
2018-10-25 01:25:28 +02:00
|
|
|
case Tegra::Texture::TextureMipmapFilter::Linear:
|
2020-06-13 14:17:37 +02:00
|
|
|
return GL_NEAREST_MIPMAP_LINEAR;
|
2018-10-25 01:25:28 +02:00
|
|
|
}
|
2020-04-17 23:43:35 +02:00
|
|
|
break;
|
2020-06-13 14:17:37 +02:00
|
|
|
case Tegra::Texture::TextureFilter::Linear:
|
|
|
|
switch (mipmap_filter_mode) {
|
2018-10-25 01:25:28 +02:00
|
|
|
case Tegra::Texture::TextureMipmapFilter::None:
|
2020-06-13 14:17:37 +02:00
|
|
|
return GL_LINEAR;
|
2018-10-25 01:25:28 +02:00
|
|
|
case Tegra::Texture::TextureMipmapFilter::Nearest:
|
2020-06-13 14:17:37 +02:00
|
|
|
return GL_LINEAR_MIPMAP_NEAREST;
|
2018-10-25 01:25:28 +02:00
|
|
|
case Tegra::Texture::TextureMipmapFilter::Linear:
|
2020-06-13 14:17:37 +02:00
|
|
|
return GL_LINEAR_MIPMAP_LINEAR;
|
2018-10-25 01:25:28 +02:00
|
|
|
}
|
2020-04-17 23:43:35 +02:00
|
|
|
break;
|
2018-10-25 01:25:28 +02:00
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNREACHABLE_MSG("Invalid texture filter mode={} and mipmap filter mode={}",
|
|
|
|
static_cast<u32>(filter_mode), static_cast<u32>(mipmap_filter_mode));
|
|
|
|
return GL_NEAREST;
|
2018-03-27 04:41:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline GLenum WrapMode(Tegra::Texture::WrapMode wrap_mode) {
|
|
|
|
switch (wrap_mode) {
|
2018-04-17 17:17:18 +02:00
|
|
|
case Tegra::Texture::WrapMode::Wrap:
|
|
|
|
return GL_REPEAT;
|
2018-06-06 03:49:57 +02:00
|
|
|
case Tegra::Texture::WrapMode::Mirror:
|
|
|
|
return GL_MIRRORED_REPEAT;
|
2018-03-27 04:41:05 +02:00
|
|
|
case Tegra::Texture::WrapMode::ClampToEdge:
|
|
|
|
return GL_CLAMP_TO_EDGE;
|
2018-07-24 00:55:24 +02:00
|
|
|
case Tegra::Texture::WrapMode::Border:
|
|
|
|
return GL_CLAMP_TO_BORDER;
|
2019-05-22 01:29:41 +02:00
|
|
|
case Tegra::Texture::WrapMode::Clamp:
|
|
|
|
return GL_CLAMP;
|
2018-08-18 18:26:50 +02:00
|
|
|
case Tegra::Texture::WrapMode::MirrorOnceClampToEdge:
|
|
|
|
return GL_MIRROR_CLAMP_TO_EDGE;
|
2018-11-14 01:26:29 +01:00
|
|
|
case Tegra::Texture::WrapMode::MirrorOnceBorder:
|
|
|
|
if (GL_EXT_texture_mirror_clamp) {
|
|
|
|
return GL_MIRROR_CLAMP_TO_BORDER_EXT;
|
|
|
|
} else {
|
|
|
|
return GL_MIRROR_CLAMP_TO_EDGE;
|
|
|
|
}
|
2018-03-27 04:41:05 +02:00
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented texture wrap mode={}", static_cast<u32>(wrap_mode));
|
|
|
|
return GL_REPEAT;
|
2018-03-27 04:41:05 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 07:18:20 +02:00
|
|
|
inline GLenum DepthCompareFunc(Tegra::Texture::DepthCompareFunc func) {
|
|
|
|
switch (func) {
|
|
|
|
case Tegra::Texture::DepthCompareFunc::Never:
|
|
|
|
return GL_NEVER;
|
|
|
|
case Tegra::Texture::DepthCompareFunc::Less:
|
|
|
|
return GL_LESS;
|
|
|
|
case Tegra::Texture::DepthCompareFunc::LessEqual:
|
|
|
|
return GL_LEQUAL;
|
|
|
|
case Tegra::Texture::DepthCompareFunc::Equal:
|
|
|
|
return GL_EQUAL;
|
|
|
|
case Tegra::Texture::DepthCompareFunc::NotEqual:
|
|
|
|
return GL_NOTEQUAL;
|
|
|
|
case Tegra::Texture::DepthCompareFunc::Greater:
|
|
|
|
return GL_GREATER;
|
|
|
|
case Tegra::Texture::DepthCompareFunc::GreaterEqual:
|
|
|
|
return GL_GEQUAL;
|
|
|
|
case Tegra::Texture::DepthCompareFunc::Always:
|
|
|
|
return GL_ALWAYS;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented texture depth compare function={}", static_cast<u32>(func));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_GREATER;
|
2018-09-19 07:18:20 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 05:13:47 +02:00
|
|
|
inline GLenum BlendEquation(Maxwell::Blend::Equation equation) {
|
|
|
|
switch (equation) {
|
|
|
|
case Maxwell::Blend::Equation::Add:
|
2018-11-22 06:51:01 +01:00
|
|
|
case Maxwell::Blend::Equation::AddGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_FUNC_ADD;
|
|
|
|
case Maxwell::Blend::Equation::Subtract:
|
2018-11-22 06:51:01 +01:00
|
|
|
case Maxwell::Blend::Equation::SubtractGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_FUNC_SUBTRACT;
|
|
|
|
case Maxwell::Blend::Equation::ReverseSubtract:
|
2018-11-22 06:51:01 +01:00
|
|
|
case Maxwell::Blend::Equation::ReverseSubtractGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_FUNC_REVERSE_SUBTRACT;
|
|
|
|
case Maxwell::Blend::Equation::Min:
|
2018-11-22 06:51:01 +01:00
|
|
|
case Maxwell::Blend::Equation::MinGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_MIN;
|
|
|
|
case Maxwell::Blend::Equation::Max:
|
2018-11-22 06:51:01 +01:00
|
|
|
case Maxwell::Blend::Equation::MaxGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_MAX;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented blend equation={}", static_cast<u32>(equation));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_FUNC_ADD;
|
2018-04-14 05:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline GLenum BlendFunc(Maxwell::Blend::Factor factor) {
|
|
|
|
switch (factor) {
|
|
|
|
case Maxwell::Blend::Factor::Zero:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::ZeroGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ZERO;
|
|
|
|
case Maxwell::Blend::Factor::One:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE;
|
|
|
|
case Maxwell::Blend::Factor::SourceColor:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::SourceColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_SRC_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusSourceColor:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusSourceColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_SRC_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::SourceAlpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::SourceAlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_SRC_ALPHA;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusSourceAlpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusSourceAlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_SRC_ALPHA;
|
|
|
|
case Maxwell::Blend::Factor::DestAlpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::DestAlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_DST_ALPHA;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusDestAlpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusDestAlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_DST_ALPHA;
|
|
|
|
case Maxwell::Blend::Factor::DestColor:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::DestColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_DST_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusDestColor:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusDestColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_DST_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::SourceAlphaSaturate:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::SourceAlphaSaturateGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_SRC_ALPHA_SATURATE;
|
|
|
|
case Maxwell::Blend::Factor::Source1Color:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::Source1ColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_SRC1_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusSource1Color:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusSource1ColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_SRC1_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::Source1Alpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::Source1AlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_SRC1_ALPHA;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusSource1Alpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusSource1AlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_SRC1_ALPHA;
|
|
|
|
case Maxwell::Blend::Factor::ConstantColor:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::ConstantColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_CONSTANT_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusConstantColor:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusConstantColorGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_CONSTANT_COLOR;
|
|
|
|
case Maxwell::Blend::Factor::ConstantAlpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::ConstantAlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_CONSTANT_ALPHA;
|
|
|
|
case Maxwell::Blend::Factor::OneMinusConstantAlpha:
|
2018-08-12 03:57:16 +02:00
|
|
|
case Maxwell::Blend::Factor::OneMinusConstantAlphaGL:
|
2018-04-14 05:13:47 +02:00
|
|
|
return GL_ONE_MINUS_CONSTANT_ALPHA;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented blend factor={}", static_cast<u32>(factor));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_ZERO;
|
2018-04-14 05:13:47 +02:00
|
|
|
}
|
|
|
|
|
2018-06-07 01:28:09 +02:00
|
|
|
inline GLenum SwizzleSource(Tegra::Texture::SwizzleSource source) {
|
|
|
|
switch (source) {
|
|
|
|
case Tegra::Texture::SwizzleSource::Zero:
|
|
|
|
return GL_ZERO;
|
|
|
|
case Tegra::Texture::SwizzleSource::R:
|
|
|
|
return GL_RED;
|
|
|
|
case Tegra::Texture::SwizzleSource::G:
|
|
|
|
return GL_GREEN;
|
|
|
|
case Tegra::Texture::SwizzleSource::B:
|
|
|
|
return GL_BLUE;
|
|
|
|
case Tegra::Texture::SwizzleSource::A:
|
|
|
|
return GL_ALPHA;
|
|
|
|
case Tegra::Texture::SwizzleSource::OneInt:
|
|
|
|
case Tegra::Texture::SwizzleSource::OneFloat:
|
|
|
|
return GL_ONE;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented swizzle source={}", static_cast<u32>(source));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_ZERO;
|
2018-06-07 01:28:09 +02:00
|
|
|
}
|
|
|
|
|
2018-07-02 20:31:49 +02:00
|
|
|
inline GLenum ComparisonOp(Maxwell::ComparisonOp comparison) {
|
|
|
|
switch (comparison) {
|
|
|
|
case Maxwell::ComparisonOp::Never:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::NeverOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_NEVER;
|
|
|
|
case Maxwell::ComparisonOp::Less:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::LessOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_LESS;
|
|
|
|
case Maxwell::ComparisonOp::Equal:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::EqualOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_EQUAL;
|
|
|
|
case Maxwell::ComparisonOp::LessEqual:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::LessEqualOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_LEQUAL;
|
|
|
|
case Maxwell::ComparisonOp::Greater:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::GreaterOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_GREATER;
|
|
|
|
case Maxwell::ComparisonOp::NotEqual:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::NotEqualOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_NOTEQUAL;
|
|
|
|
case Maxwell::ComparisonOp::GreaterEqual:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::GreaterEqualOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_GEQUAL;
|
|
|
|
case Maxwell::ComparisonOp::Always:
|
2018-07-05 20:01:31 +02:00
|
|
|
case Maxwell::ComparisonOp::AlwaysOld:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_ALWAYS;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented comparison op={}", static_cast<u32>(comparison));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_ALWAYS;
|
2018-07-02 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 06:35:31 +02:00
|
|
|
inline GLenum StencilOp(Maxwell::StencilOp stencil) {
|
|
|
|
switch (stencil) {
|
|
|
|
case Maxwell::StencilOp::Keep:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::KeepOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_KEEP;
|
|
|
|
case Maxwell::StencilOp::Zero:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::ZeroOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_ZERO;
|
|
|
|
case Maxwell::StencilOp::Replace:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::ReplaceOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_REPLACE;
|
|
|
|
case Maxwell::StencilOp::Incr:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::IncrOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_INCR;
|
|
|
|
case Maxwell::StencilOp::Decr:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::DecrOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_DECR;
|
|
|
|
case Maxwell::StencilOp::Invert:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::InvertOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_INVERT;
|
|
|
|
case Maxwell::StencilOp::IncrWrap:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::IncrWrapOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_INCR_WRAP;
|
|
|
|
case Maxwell::StencilOp::DecrWrap:
|
2018-11-07 04:27:12 +01:00
|
|
|
case Maxwell::StencilOp::DecrWrapOGL:
|
2018-08-22 06:35:31 +02:00
|
|
|
return GL_DECR_WRAP;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented stencil op={}", static_cast<u32>(stencil));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_KEEP;
|
2018-08-22 06:35:31 +02:00
|
|
|
}
|
|
|
|
|
2019-12-29 01:41:41 +01:00
|
|
|
inline GLenum FrontFace(Maxwell::FrontFace front_face) {
|
2018-07-02 20:31:49 +02:00
|
|
|
switch (front_face) {
|
2019-12-29 01:41:41 +01:00
|
|
|
case Maxwell::FrontFace::ClockWise:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_CW;
|
2019-12-29 01:41:41 +01:00
|
|
|
case Maxwell::FrontFace::CounterClockWise:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_CCW;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented front face cull={}", static_cast<u32>(front_face));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_CCW;
|
2018-07-02 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2019-12-29 01:41:41 +01:00
|
|
|
inline GLenum CullFace(Maxwell::CullFace cull_face) {
|
2018-07-02 20:31:49 +02:00
|
|
|
switch (cull_face) {
|
2019-12-29 01:41:41 +01:00
|
|
|
case Maxwell::CullFace::Front:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_FRONT;
|
2019-12-29 01:41:41 +01:00
|
|
|
case Maxwell::CullFace::Back:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_BACK;
|
2019-12-29 01:41:41 +01:00
|
|
|
case Maxwell::CullFace::FrontAndBack:
|
2018-07-02 20:31:49 +02:00
|
|
|
return GL_FRONT_AND_BACK;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented cull face={}", static_cast<u32>(cull_face));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_BACK;
|
2018-07-02 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-21 01:44:47 +02:00
|
|
|
inline GLenum LogicOp(Maxwell::LogicOperation operation) {
|
|
|
|
switch (operation) {
|
|
|
|
case Maxwell::LogicOperation::Clear:
|
|
|
|
return GL_CLEAR;
|
|
|
|
case Maxwell::LogicOperation::And:
|
|
|
|
return GL_AND;
|
|
|
|
case Maxwell::LogicOperation::AndReverse:
|
|
|
|
return GL_AND_REVERSE;
|
|
|
|
case Maxwell::LogicOperation::Copy:
|
|
|
|
return GL_COPY;
|
|
|
|
case Maxwell::LogicOperation::AndInverted:
|
|
|
|
return GL_AND_INVERTED;
|
|
|
|
case Maxwell::LogicOperation::NoOp:
|
|
|
|
return GL_NOOP;
|
|
|
|
case Maxwell::LogicOperation::Xor:
|
|
|
|
return GL_XOR;
|
|
|
|
case Maxwell::LogicOperation::Or:
|
|
|
|
return GL_OR;
|
|
|
|
case Maxwell::LogicOperation::Nor:
|
|
|
|
return GL_NOR;
|
|
|
|
case Maxwell::LogicOperation::Equiv:
|
|
|
|
return GL_EQUIV;
|
|
|
|
case Maxwell::LogicOperation::Invert:
|
|
|
|
return GL_INVERT;
|
|
|
|
case Maxwell::LogicOperation::OrReverse:
|
|
|
|
return GL_OR_REVERSE;
|
|
|
|
case Maxwell::LogicOperation::CopyInverted:
|
|
|
|
return GL_COPY_INVERTED;
|
|
|
|
case Maxwell::LogicOperation::OrInverted:
|
|
|
|
return GL_OR_INVERTED;
|
|
|
|
case Maxwell::LogicOperation::Nand:
|
|
|
|
return GL_NAND;
|
|
|
|
case Maxwell::LogicOperation::Set:
|
|
|
|
return GL_SET;
|
|
|
|
}
|
2020-06-13 14:17:37 +02:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented logic operation={}", static_cast<u32>(operation));
|
2018-11-07 04:27:12 +01:00
|
|
|
return GL_COPY;
|
2018-08-21 01:44:47 +02:00
|
|
|
}
|
|
|
|
|
2020-02-24 23:43:57 +01:00
|
|
|
inline GLenum PolygonMode(Maxwell::PolygonMode polygon_mode) {
|
|
|
|
switch (polygon_mode) {
|
|
|
|
case Maxwell::PolygonMode::Point:
|
|
|
|
return GL_POINT;
|
|
|
|
case Maxwell::PolygonMode::Line:
|
|
|
|
return GL_LINE;
|
|
|
|
case Maxwell::PolygonMode::Fill:
|
|
|
|
return GL_FILL;
|
|
|
|
}
|
|
|
|
UNREACHABLE_MSG("Invalid polygon mode={}", static_cast<int>(polygon_mode));
|
|
|
|
return GL_FILL;
|
|
|
|
}
|
|
|
|
|
2020-05-04 22:51:30 +02:00
|
|
|
inline GLenum ViewportSwizzle(Maxwell::ViewportSwizzle swizzle) {
|
|
|
|
// Enumeration order matches register order. We can convert it arithmetically.
|
|
|
|
return GL_VIEWPORT_SWIZZLE_POSITIVE_X_NV + static_cast<GLenum>(swizzle);
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:09:30 +02:00
|
|
|
} // namespace MaxwellToGL
|
2018-08-21 10:18:27 +02:00
|
|
|
} // namespace OpenGL
|