2017-09-17 20:35:48 +00:00
|
|
|
/*
|
|
|
|
* Modern effects for a modern Streamer
|
|
|
|
* Copyright (C) 2017 Michael Fabian Dirks
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "gs-mipmapper.hpp"
|
2021-11-09 10:34:27 +00:00
|
|
|
#include <sstream>
|
2019-09-04 00:59:04 +00:00
|
|
|
#include <stdexcept>
|
2019-04-02 22:16:13 +00:00
|
|
|
#include "obs/gs/gs-helper.hpp"
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "plugin.hpp"
|
2018-09-27 04:09:43 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
// Direct3D 11
|
2020-04-25 06:15:20 +00:00
|
|
|
#ifdef _WIN32
|
2020-03-27 17:41:18 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
2020-07-12 16:41:50 +00:00
|
|
|
#pragma warning(disable : 4191 4242 4244 4365 4777 4986 5039 5204)
|
2020-03-27 17:41:18 +00:00
|
|
|
#endif
|
2019-04-19 07:42:15 +00:00
|
|
|
#include <Windows.h>
|
2020-04-25 06:15:20 +00:00
|
|
|
#include <atlutil.h>
|
2020-03-27 17:41:18 +00:00
|
|
|
#include <d3d11.h>
|
|
|
|
#include <dxgi.h>
|
2019-03-01 11:00:30 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2018-09-27 04:09:43 +00:00
|
|
|
#endif
|
2017-09-17 20:35:48 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
// OpenGL
|
|
|
|
#include "glad/gl.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
struct d3d_info {
|
|
|
|
ID3D11Device* device = nullptr;
|
|
|
|
ID3D11DeviceContext* context = nullptr;
|
|
|
|
ID3D11Resource* target = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void d3d_initialize(d3d_info& info, std::shared_ptr<streamfx::obs::gs::texture> source,
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> target)
|
2018-09-27 04:09:43 +00:00
|
|
|
{
|
2021-11-09 10:34:27 +00:00
|
|
|
info.target = reinterpret_cast<ID3D11Resource*>(gs_texture_get_obj(target->get_object()));
|
|
|
|
info.device = reinterpret_cast<ID3D11Device*>(gs_get_device_obj());
|
|
|
|
info.device->GetImmediateContext(&info.context);
|
2018-09-27 04:09:43 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
void d3d_copy_subregion(d3d_info& info, std::shared_ptr<streamfx::obs::gs::texture> source, uint32_t mip_level,
|
|
|
|
uint32_t width, uint32_t height)
|
2018-09-27 04:09:43 +00:00
|
|
|
{
|
2021-11-27 00:33:43 +00:00
|
|
|
D3D11_BOX box = {0, 0, 0, width, height, 1};
|
|
|
|
auto source_ref = reinterpret_cast<ID3D11Resource*>(gs_texture_get_obj(source->get_object()));
|
|
|
|
info.context->CopySubresourceRegion(info.target, mip_level, 0, 0, 0, source_ref, 0, &box);
|
2021-11-09 10:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2021-11-07 13:37:05 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
struct opengl_info {
|
|
|
|
GLuint target = 0;
|
|
|
|
GLuint fbo = 0;
|
|
|
|
};
|
2020-04-25 06:15:20 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
std::string opengl_translate_error(GLenum error)
|
|
|
|
{
|
|
|
|
#define TRANSLATE_CASE(X) \
|
|
|
|
case X: \
|
|
|
|
return #X;
|
|
|
|
|
|
|
|
switch (error) {
|
|
|
|
TRANSLATE_CASE(GL_NO_ERROR);
|
|
|
|
TRANSLATE_CASE(GL_INVALID_ENUM);
|
|
|
|
TRANSLATE_CASE(GL_INVALID_VALUE);
|
|
|
|
TRANSLATE_CASE(GL_INVALID_OPERATION);
|
|
|
|
TRANSLATE_CASE(GL_STACK_OVERFLOW);
|
|
|
|
TRANSLATE_CASE(GL_STACK_UNDERFLOW);
|
|
|
|
TRANSLATE_CASE(GL_OUT_OF_MEMORY);
|
|
|
|
TRANSLATE_CASE(GL_INVALID_FRAMEBUFFER_OPERATION);
|
2020-04-25 06:15:20 +00:00
|
|
|
}
|
2021-11-09 10:34:27 +00:00
|
|
|
|
|
|
|
return std::to_string(error);
|
|
|
|
#undef TRANSLATE_CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string opengl_translate_framebuffer_status(GLenum error)
|
|
|
|
{
|
|
|
|
#define TRANSLATE_CASE(X) \
|
|
|
|
case X: \
|
|
|
|
return #X;
|
|
|
|
|
|
|
|
switch (error) {
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_COMPLETE);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_UNDEFINED);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_UNSUPPORTED);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
|
|
|
|
TRANSLATE_CASE(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS);
|
2020-04-25 06:15:20 +00:00
|
|
|
}
|
2021-11-09 10:34:27 +00:00
|
|
|
|
|
|
|
return std::to_string(error);
|
|
|
|
#undef TRANSLATE_CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
#define D_OPENGL_CHECK_ERROR(FUNCTION) \
|
|
|
|
if (auto err = glGetError(); err != GL_NO_ERROR) { \
|
|
|
|
std::stringstream sstr; \
|
|
|
|
sstr << opengl_translate_error(err) << " = " << FUNCTION; \
|
|
|
|
throw std::runtime_error(sstr.str()); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define D_OPENGL_CHECK_FRAMEBUFFERSTATUS(BUFFER, FUNCTION) \
|
|
|
|
if (auto err = glCheckFramebufferStatus(BUFFER); err != GL_FRAMEBUFFER_COMPLETE) { \
|
|
|
|
std::stringstream sstr; \
|
|
|
|
sstr << opengl_translate_framebuffer_status(err) << " = " << FUNCTION; \
|
|
|
|
throw std::runtime_error(sstr.str()); \
|
2020-04-25 06:15:20 +00:00
|
|
|
}
|
2018-09-27 04:09:43 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
void opengl_initialize(opengl_info& info, std::shared_ptr<streamfx::obs::gs::texture> source,
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> target)
|
|
|
|
{
|
|
|
|
info.target = *reinterpret_cast<GLuint*>(gs_texture_get_obj(target->get_object()));
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &info.fbo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void opengl_finalize(opengl_info& info)
|
|
|
|
{
|
|
|
|
glDeleteFramebuffers(1, &info.fbo);
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:33:43 +00:00
|
|
|
void opengl_copy_subregion(opengl_info& info, std::shared_ptr<streamfx::obs::gs::texture> source, uint32_t mip_level,
|
|
|
|
uint32_t width, uint32_t height)
|
2021-11-09 10:34:27 +00:00
|
|
|
{
|
2021-11-27 00:33:43 +00:00
|
|
|
GLuint source_ref = *reinterpret_cast<GLuint*>(gs_texture_get_obj(source->get_object()));
|
2021-11-09 10:34:27 +00:00
|
|
|
|
|
|
|
// Source -> Texture Unit 0, Read Color Framebuffer
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
D_OPENGL_CHECK_ERROR("glActiveTexture(GL_TEXTURE0);");
|
2021-11-27 00:33:43 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, source_ref);
|
2021-11-09 10:34:27 +00:00
|
|
|
D_OPENGL_CHECK_ERROR("glBindTexture(GL_TEXTURE_2D, origin);");
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, info.fbo);
|
|
|
|
D_OPENGL_CHECK_ERROR("glBindFramebuffer(GL_READ_FRAMEBUFFER, info.fbo);");
|
2021-11-27 00:33:43 +00:00
|
|
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, source_ref,
|
2021-11-09 10:34:27 +00:00
|
|
|
0); // Origin is a render target, not a texture
|
|
|
|
D_OPENGL_CHECK_ERROR(
|
|
|
|
"glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, origin, mip_level);");
|
|
|
|
D_OPENGL_CHECK_FRAMEBUFFERSTATUS(
|
|
|
|
GL_READ_FRAMEBUFFER,
|
|
|
|
"glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, origin, mip_level);");
|
|
|
|
|
|
|
|
// Target -> Texture Unit 1
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
D_OPENGL_CHECK_ERROR("glActiveTexture(GL_TEXTURE1);");
|
|
|
|
glBindTexture(GL_TEXTURE_2D, info.target);
|
|
|
|
D_OPENGL_CHECK_ERROR("glBindTexture(GL_TEXTURE_2D, info.target);");
|
|
|
|
|
|
|
|
// Copy Data
|
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, mip_level, 0, 0, 0, 0, width, height);
|
|
|
|
D_OPENGL_CHECK_ERROR("glCopyTexSubImage2D(GL_TEXTURE_2D, mip_level, 0, 0, 0, 0, width, height);");
|
|
|
|
|
|
|
|
// Target -/-> Texture Unit 1
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
D_OPENGL_CHECK_ERROR("glActiveTexture(GL_TEXTURE1);");
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
D_OPENGL_CHECK_ERROR("glBindTexture(GL_TEXTURE_2D, 0);");
|
|
|
|
|
|
|
|
// Source -/-> Texture Unit 0, Read Color Framebuffer
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
D_OPENGL_CHECK_ERROR("glActiveTexture(GL_TEXTURE0);");
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
D_OPENGL_CHECK_ERROR("glBindTexture(GL_TEXTURE_2D, 0);");
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, info.fbo);
|
|
|
|
D_OPENGL_CHECK_ERROR("glBindFramebuffer(GL_READ_FRAMEBUFFER, info.fbo);");
|
|
|
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
|
|
|
D_OPENGL_CHECK_ERROR("glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);");
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
|
|
|
D_OPENGL_CHECK_ERROR("glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);");
|
|
|
|
}
|
|
|
|
|
|
|
|
streamfx::obs::gs::mipmapper::~mipmapper()
|
|
|
|
{
|
|
|
|
_rt.reset();
|
|
|
|
_effect.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
streamfx::obs::gs::mipmapper::mipmapper()
|
|
|
|
{
|
|
|
|
auto gctx = streamfx::obs::gs::context();
|
2018-09-27 04:09:43 +00:00
|
|
|
|
2021-11-07 13:37:05 +00:00
|
|
|
{
|
|
|
|
auto file = streamfx::data_file_path("effects/mipgen.effect");
|
|
|
|
try {
|
|
|
|
_effect = streamfx::obs::gs::effect::create(file);
|
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
DLOG_ERROR("Error loading '%s': %s", file.generic_u8string().c_str(), ex.what());
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 20:35:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
uint32_t streamfx::obs::gs::mipmapper::calculate_max_mip_level(uint32_t width, uint32_t height)
|
|
|
|
{
|
|
|
|
return static_cast<uint32_t>(1 + std::lroundl(floor(log2(std::max<GLint>(width, height)))));
|
|
|
|
}
|
|
|
|
|
2021-06-08 02:38:24 +00:00
|
|
|
void streamfx::obs::gs::mipmapper::rebuild(std::shared_ptr<streamfx::obs::gs::texture> source,
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> target)
|
2018-09-27 04:09:43 +00:00
|
|
|
{
|
2020-04-25 06:15:20 +00:00
|
|
|
{ // Validate arguments and structure.
|
|
|
|
if (!source || !target)
|
|
|
|
return; // Do nothing if source or target are missing.
|
2018-09-27 04:09:43 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
if (!_effect)
|
2020-04-25 06:15:20 +00:00
|
|
|
return; // Do nothing if the necessary data failed to load.
|
2018-09-28 12:24:30 +00:00
|
|
|
|
2020-04-25 06:15:20 +00:00
|
|
|
// Ensure texture sizes match
|
|
|
|
if ((source->get_width() != target->get_width()) || (source->get_height() != target->get_height())) {
|
|
|
|
throw std::invalid_argument("source and target must have same size");
|
|
|
|
}
|
2018-09-27 04:09:43 +00:00
|
|
|
|
2020-04-25 06:15:20 +00:00
|
|
|
// Ensure texture types match
|
|
|
|
if ((source->get_type() != target->get_type())) {
|
|
|
|
throw std::invalid_argument("source and target must have same type");
|
|
|
|
}
|
2018-09-28 12:24:30 +00:00
|
|
|
|
2020-04-25 06:15:20 +00:00
|
|
|
// Ensure texture formats match
|
|
|
|
if ((source->get_color_format() != target->get_color_format())) {
|
|
|
|
throw std::invalid_argument("source and target must have same format");
|
|
|
|
}
|
2018-09-28 12:24:30 +00:00
|
|
|
}
|
2018-09-28 21:32:35 +00:00
|
|
|
|
2020-04-25 06:15:20 +00:00
|
|
|
// Get a unique lock on the graphics context.
|
2021-06-08 02:38:24 +00:00
|
|
|
auto gctx = streamfx::obs::gs::context();
|
2017-09-17 20:35:48 +00:00
|
|
|
|
2020-04-25 06:15:20 +00:00
|
|
|
// Do we need to recreate the render target for a different format?
|
2019-08-04 14:20:26 +00:00
|
|
|
if ((!_rt) || (source->get_color_format() != _rt->get_color_format())) {
|
2021-06-08 02:38:24 +00:00
|
|
|
_rt = std::make_unique<streamfx::obs::gs::rendertarget>(source->get_color_format(), GS_ZS_NONE);
|
2018-09-27 04:09:43 +00:00
|
|
|
}
|
2017-09-17 20:35:48 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
// Initialize API Handlers.
|
|
|
|
opengl_info oglinfo;
|
|
|
|
if (gs_get_device_type() == GS_DEVICE_OPENGL) {
|
|
|
|
opengl_initialize(oglinfo, source, target);
|
|
|
|
}
|
2020-04-25 06:15:20 +00:00
|
|
|
#ifdef _WIN32
|
2021-11-09 10:34:27 +00:00
|
|
|
d3d_info d3dinfo;
|
2020-04-25 06:15:20 +00:00
|
|
|
if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) {
|
2021-11-09 10:34:27 +00:00
|
|
|
d3d_initialize(d3dinfo, source, target);
|
2020-04-25 06:15:20 +00:00
|
|
|
}
|
2019-01-14 10:23:21 +00:00
|
|
|
#endif
|
2018-09-27 04:09:43 +00:00
|
|
|
|
2020-04-25 06:15:20 +00:00
|
|
|
// Use different methods for different types of textures.
|
2021-06-08 02:38:24 +00:00
|
|
|
if (source->get_type() == streamfx::obs::gs::texture::type::Normal) {
|
2021-11-09 10:34:27 +00:00
|
|
|
uint32_t width = source->get_width();
|
|
|
|
uint32_t height = source->get_height();
|
|
|
|
size_t max_mip_level = calculate_max_mip_level(width, height);
|
2020-04-25 06:15:20 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
{
|
2020-04-25 23:04:04 +00:00
|
|
|
#ifdef ENABLE_PROFILING
|
2021-11-09 10:34:27 +00:00
|
|
|
auto cctr = streamfx::obs::gs::debug_marker(streamfx::obs::gs::debug_color_azure_radiance,
|
|
|
|
"Mip Level %" PRId64 "", 0);
|
2020-04-25 23:04:04 +00:00
|
|
|
#endif
|
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
// Retrieve maximum mip map level.
|
2020-04-25 06:15:20 +00:00
|
|
|
#ifdef _WIN32
|
2021-11-09 10:34:27 +00:00
|
|
|
if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) {
|
|
|
|
d3d_copy_subregion(d3dinfo, source, 0, width, height);
|
|
|
|
}
|
2018-09-28 23:06:30 +00:00
|
|
|
#endif
|
2021-11-09 10:34:27 +00:00
|
|
|
if (gs_get_device_type() == GS_DEVICE_OPENGL) {
|
|
|
|
opengl_copy_subregion(oglinfo, source, 0, width, height);
|
2018-09-29 14:57:17 +00:00
|
|
|
}
|
2021-11-09 10:34:27 +00:00
|
|
|
}
|
2018-09-29 14:57:17 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
// Render each mip map level.
|
|
|
|
for (size_t mip = 1; mip < max_mip_level; mip++) {
|
2020-04-25 23:04:04 +00:00
|
|
|
#ifdef ENABLE_PROFILING
|
2021-11-09 10:34:27 +00:00
|
|
|
auto cctr = streamfx::obs::gs::debug_marker(streamfx::obs::gs::debug_color_azure_radiance,
|
|
|
|
"Mip Level %" PRIuMAX, mip);
|
2020-04-25 23:04:04 +00:00
|
|
|
#endif
|
2018-09-28 23:06:30 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
uint32_t cwidth = std::max<uint32_t>(width >> mip, 1);
|
|
|
|
uint32_t cheight = std::max<uint32_t>(height >> mip, 1);
|
|
|
|
float_t iwidth = 1.f / static_cast<float_t>(cwidth);
|
|
|
|
float_t iheight = 1.f / static_cast<float_t>(cheight);
|
2018-09-28 23:06:30 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
// Set up rendering state.
|
|
|
|
gs_blend_state_push();
|
|
|
|
gs_reset_blend_state();
|
|
|
|
gs_enable_blending(false);
|
|
|
|
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
|
|
|
|
gs_enable_color(true, true, true, true);
|
|
|
|
gs_enable_depth_test(false);
|
|
|
|
gs_enable_stencil_test(false);
|
|
|
|
gs_enable_stencil_write(false);
|
|
|
|
gs_set_cull_mode(GS_NEITHER);
|
2021-11-27 00:33:43 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
try {
|
2021-11-27 00:33:43 +00:00
|
|
|
auto op = _rt->render(cwidth, cheight);
|
2021-11-09 10:34:27 +00:00
|
|
|
gs_ortho(0, 1, 0, 1, 0, 1);
|
2018-09-28 23:06:30 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
_effect.get_parameter("image").set_texture(target);
|
|
|
|
_effect.get_parameter("imageTexel").set_float2(iwidth, iheight);
|
|
|
|
_effect.get_parameter("level").set_int(int32_t(mip - 1));
|
|
|
|
while (gs_effect_loop(_effect.get_object(), "Draw")) {
|
|
|
|
streamfx::gs_draw_fullscreen_tri();
|
2018-09-27 04:09:43 +00:00
|
|
|
}
|
2021-11-09 10:34:27 +00:00
|
|
|
} catch (...) {
|
2018-09-28 23:06:30 +00:00
|
|
|
}
|
2018-09-27 04:09:43 +00:00
|
|
|
|
2021-11-09 10:34:27 +00:00
|
|
|
// Clean up rendering state.
|
|
|
|
gs_blend_state_pop();
|
|
|
|
|
|
|
|
// Copy from the render target to the target mip level.
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) {
|
|
|
|
d3d_copy_subregion(d3dinfo, _rt->get_texture(), mip, cwidth, cheight);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (gs_get_device_type() == GS_DEVICE_OPENGL) {
|
|
|
|
opengl_copy_subregion(oglinfo, _rt->get_texture(), mip, cwidth, cheight);
|
|
|
|
}
|
2018-09-27 04:21:39 +00:00
|
|
|
}
|
2021-11-09 10:34:27 +00:00
|
|
|
|
2020-04-25 06:15:20 +00:00
|
|
|
} else {
|
2021-11-09 10:34:27 +00:00
|
|
|
throw std::runtime_error("Only 2D Textures support Mip-mapping.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finalize API handlers.
|
|
|
|
if (gs_get_device_type() == GS_DEVICE_OPENGL) {
|
|
|
|
opengl_finalize(oglinfo);
|
2018-09-27 04:09:43 +00:00
|
|
|
}
|
2021-11-09 10:34:27 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) {
|
|
|
|
//d3d_finalize(d3dinfo);
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-17 20:35:48 +00:00
|
|
|
}
|