Skip to content

Commit

Permalink
texFiltering
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhno591 committed Nov 14, 2016
1 parent e499418 commit 4b9e701
Show file tree
Hide file tree
Showing 17 changed files with 1,627 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/citra/config.cpp
Expand Up @@ -76,6 +76,9 @@ void Config::ReadValues() {
// Layout
Settings::values.layout_option = static_cast<Settings::LayoutOption>(sdl2_config->GetInteger("Layout", "layout_option", 0));
Settings::values.swap_screen = sdl2_config->GetBoolean("Layout", "swap_screen", false);

Settings::values.tex_filter = sdl2_config->GetInteger("Renderer", "tex_filter", 0);
Settings::values.tex_filter_scaling = sdl2_config->GetInteger("Renderer", "tex_filter_scaling", 1);

// Audio
Settings::values.sink_id = sdl2_config->Get("Audio", "output_engine", "auto");
Expand Down
8 changes: 8 additions & 0 deletions src/citra/default_ini.h
Expand Up @@ -79,6 +79,14 @@ bg_red =
bg_blue =
bg_green =
# What texture filter to use
# 0 (default): Nothing, 1: xbRZ
tex_filter =
# What texture filtering size to use (if enabled)
# 1 (default): Disabled, 2-6: Enabled at x times scaling
tex_filter_scaling =
[Audio]
# Which audio output engine to use.
# auto (default): Auto-select, null: No audio output, sdl2: SDL2 (if available)
Expand Down
6 changes: 6 additions & 0 deletions src/citra_qt/config.cpp
Expand Up @@ -55,6 +55,9 @@ void Config::ReadValues() {
Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat();
Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat();
Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat();

Settings::values.tex_filter = qt_config->value("tex_filter", 0).toInt();
Settings::values.tex_filter_scaling = qt_config->value("tex_filter_scaling", 1).toInt();
qt_config->endGroup();

qt_config->beginGroup("Layout");
Expand Down Expand Up @@ -162,6 +165,9 @@ void Config::SaveValues() {
qt_config->setValue("bg_red", (double)Settings::values.bg_red);
qt_config->setValue("bg_green", (double)Settings::values.bg_green);
qt_config->setValue("bg_blue", (double)Settings::values.bg_blue);

qt_config->setValue("tex_filter", Settings::values.tex_filter);
qt_config->setValue("tex_filter_scaling", Settings::values.tex_filter_scaling);
qt_config->endGroup();

qt_config->beginGroup("Layout");
Expand Down
4 changes: 4 additions & 0 deletions src/citra_qt/configure_graphics.cpp
Expand Up @@ -23,6 +23,8 @@ void ConfigureGraphics::setConfiguration() {
ui->toggle_shader_jit->setChecked(Settings::values.use_shader_jit);
ui->toggle_scaled_resolution->setChecked(Settings::values.use_scaled_resolution);
ui->toggle_vsync->setChecked(Settings::values.use_vsync);
ui->combo_filtering->setCurrentIndex(Settings::values.tex_filter);
ui->slider_filtering_scale->setValue(Settings::values.tex_filter_scaling);
ui->layout_combobox->setCurrentIndex(static_cast<int>(Settings::values.layout_option));
ui->swap_screen->setChecked(Settings::values.swap_screen);
ui->toggle_framelimit->setChecked(Settings::values.toggle_framelimit);
Expand All @@ -33,6 +35,8 @@ void ConfigureGraphics::applyConfiguration() {
Settings::values.use_shader_jit = ui->toggle_shader_jit->isChecked();
Settings::values.use_scaled_resolution = ui->toggle_scaled_resolution->isChecked();
Settings::values.use_vsync = ui->toggle_vsync->isChecked();
Settings::values.tex_filter = ui->combo_filtering->currentIndex();
Settings::values.tex_filter_scaling = ui->slider_filtering_scale->value();
Settings::values.layout_option = static_cast<Settings::LayoutOption>(ui->layout_combobox->currentIndex());
Settings::values.swap_screen = ui->swap_screen->isChecked();
Settings::values.toggle_framelimit = ui->toggle_framelimit->isChecked();
Expand Down
92 changes: 92 additions & 0 deletions src/citra_qt/configure_graphics.ui
Expand Up @@ -63,6 +63,98 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Filtering</string>
</property>
<layout class="QGridLayout" name="verticalLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_filtering_type">
<property name="text">
<string>Texture Mode:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_filtering">
<item>
<widget class="QComboBox" name="combo_filtering">
<item>
<property name="text">
<string>Disabled</string>
</property>
</item>
<item>
<property name="text">
<string>xBRZ</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_filtering_type">
<property name="text">
<string>Scale:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_filtering_scale">
<item>
<widget class="QSlider" name="slider_filtering_scale">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>6</number>
</property>
<property name="tickInterval">
<number>1</number>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_filtering_scale_names">
<item>
<layout class="QGridLayout" name="verticalLayout_filtering_scale_names">
<item row="0" column="0">
<widget class="QLabel" name="label_filtering_scale_names_x2">
<property name="text">
<string>x1</string>
</property>
<property name="alignment">
<enum>Qt::AlignLeft</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_filtering_scale_names_x6">
<property name="text">
<string>x6</string>
</property>
<property name="alignment">
<enum>Qt::AlignRight</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
3 changes: 3 additions & 0 deletions src/core/settings.cpp
Expand Up @@ -28,6 +28,9 @@ void Apply() {
VideoCore::g_emu_window->UpdateCurrentFramebufferLayout(layout.width, layout.height);
}

// Ensure that texture caches are empty
VideoCore::g_is_rasterizer_dirty = true;

AudioCore::SelectSink(values.sink_id);
AudioCore::EnableStretching(values.enable_audio_stretching);

Expand Down
3 changes: 3 additions & 0 deletions src/core/settings.h
Expand Up @@ -160,6 +160,9 @@ struct Values {
float bg_red;
float bg_green;
float bg_blue;

int tex_filter;
int tex_filter_scaling;

std::string log_filter;

Expand Down
5 changes: 5 additions & 0 deletions src/video_core/CMakeLists.txt
Expand Up @@ -17,6 +17,8 @@ set(SRCS
swrasterizer.cpp
vertex_loader.cpp
video_core.cpp
filtering/texture_filterer.cpp
filtering/xbrz/xbrz.cpp
)

set(HEADERS
Expand Down Expand Up @@ -45,6 +47,9 @@ set(HEADERS
utils.h
vertex_loader.h
video_core.h
filtering/texture_filterer.h
filtering/xbrz/config.h
filtering/xbrz/xbrz.h
)

if(ARCHITECTURE_x86_64)
Expand Down
58 changes: 58 additions & 0 deletions src/video_core/filtering/texture_filterer.cpp
@@ -0,0 +1,58 @@
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <vector>
#include "common/vector_math.h"
#include "core/memory.h"
#include "core/settings.h"
#include "video_core/debug_utils/debug_utils.h"
#include "video_core/filtering/texture_filterer.h"
#include "video_core/filtering/xbrz/xbrz.h"

bool Filtering::isScalingEnabled() {
int scaling = Filtering::getScaling();
return Filtering::getScalingType() != Filtering::FilteringTypes::NONE && scaling >= 2 &&
scaling <= 6;
}

int Filtering::getScaling() {
int scaling = Settings::values.tex_filter_scaling;

if (scaling < 1 || scaling > 6) {
return 1;
} else {
return scaling;
}
}

Filtering::FilteringTypes Filtering::getScalingType() {
return (Filtering::FilteringTypes)Settings::values.tex_filter;
}

void Filtering::filterTexture(Pica::DebugUtils::TextureInfo tex_info, unsigned int* fromBuffer,
unsigned int* toBuffer) {
// Discover filtering type
Filtering::FilteringTypes type = getScalingType();

switch (type) {
case Filtering::FilteringTypes::XBRZ:
if (tex_info.format == Pica::Regs::TextureFormat::RGB8) {
xbrz::scale(Filtering::getScaling(), fromBuffer, toBuffer, tex_info.width,
tex_info.height, xbrz::ColorFormat::RGB);
} else {
xbrz::scale(Filtering::getScaling(), fromBuffer, toBuffer, tex_info.width,
tex_info.height, xbrz::ColorFormat::ARGB);
}
break;
}
}

int Filtering::getScaledTextureSize(Pica::Regs::TextureFormat format, int width, int height) {
if (Filtering::isScalingEnabled() && (int)format < 14) { // Check that this is in range
int scaling = Filtering::getScaling();
return (width * scaling) * (height * scaling);
} else {
return width * height;
}
}
32 changes: 32 additions & 0 deletions src/video_core/filtering/texture_filterer.h
@@ -0,0 +1,32 @@
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include "video_core/debug_utils/debug_utils.h"
#include "video_core/renderer_opengl/gl_rasterizer_cache.h"

namespace Filtering {

enum class FilteringTypes {
NONE = 0,
XBRZ = 1,
};

// Checks if scaling is enabled
bool isScalingEnabled();

// Returns the currently configured scaling size
int getScaling();

// Returns the currently configured scaling type
Filtering::FilteringTypes getScalingType();

// Filters a texture using the specified texture
void filterTexture(Pica::DebugUtils::TextureInfo tex_info, unsigned int* fromBuffer,
unsigned int* toBuffer);

// Returns the scaled texture size (width * height) of this texture
int getScaledTextureSize(Pica::Regs::TextureFormat format, int width, int height);
}
31 changes: 31 additions & 0 deletions src/video_core/filtering/xbrz/config.h
@@ -0,0 +1,31 @@
// ****************************************************************************
// * This file is part of the HqMAME project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// * *
// * Additionally and as a special exception, the author gives permission *
// * to link the code of this program with the MAME library (or with modified *
// * versions of MAME that use the same license as MAME), and distribute *
// * linked combinations including the two. You must obey the GNU General *
// * Public License in all respects for all of the code used other than MAME. *
// * If you modify this file, you may extend this exception to your version *
// * of the file, but you are not obligated to do so. If you do not wish to *
// * do so, delete this exception statement from your version. *
// ****************************************************************************

#ifndef XBRZ_CONFIG_HEADER_284578425345
#define XBRZ_CONFIG_HEADER_284578425345

// do NOT include any headers here! used by xBRZ_dll!!!

namespace xbrz {
struct ScalerCfg {
double luminanceWeight = 1;
double equalColorTolerance = 30;
double dominantDirectionThreshold = 3.6;
double steepDirectionThreshold = 2.2;
double newTestAttribute = 0; // unused; test new parameters
};
}

#endif

0 comments on commit 4b9e701

Please sign in to comment.