2017-01-05 23:11:23 +01:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/vector_math.h"
|
2017-01-28 05:51:59 +01:00
|
|
|
#include "video_core/regs_texturing.h"
|
2017-01-05 23:11:23 +01:00
|
|
|
|
2019-02-19 09:09:57 +01:00
|
|
|
namespace Pica::Texture {
|
2017-01-05 23:11:23 +01:00
|
|
|
|
2017-01-06 04:19:06 +01:00
|
|
|
/// Returns the byte size of a 8*8 tile of the specified texture format.
|
2017-01-28 05:51:59 +01:00
|
|
|
size_t CalculateTileSize(TexturingRegs::TextureFormat format);
|
2017-01-06 04:19:06 +01:00
|
|
|
|
2017-01-05 23:11:23 +01:00
|
|
|
struct TextureInfo {
|
|
|
|
PAddr physical_address;
|
2017-01-06 04:19:06 +01:00
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
|
|
|
ptrdiff_t stride;
|
2017-01-28 05:51:59 +01:00
|
|
|
TexturingRegs::TextureFormat format;
|
2017-01-05 23:11:23 +01:00
|
|
|
|
2017-01-28 05:51:59 +01:00
|
|
|
static TextureInfo FromPicaRegister(const TexturingRegs::TextureConfig& config,
|
|
|
|
const TexturingRegs::TextureFormat& format);
|
2017-01-06 04:19:06 +01:00
|
|
|
|
|
|
|
/// Calculates stride from format and width, assuming that the entire texture is contiguous.
|
|
|
|
void SetDefaultStride() {
|
2017-01-28 05:51:59 +01:00
|
|
|
stride = CalculateTileSize(format) * (width / 8);
|
2017-01-06 04:19:06 +01:00
|
|
|
}
|
2017-01-05 23:11:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup texel located at the given coordinates and return an RGBA vector of its color.
|
|
|
|
* @param source Source pointer to read data from
|
2017-01-06 04:19:06 +01:00
|
|
|
* @param x,y Texture coordinates to read from
|
2017-01-05 23:11:23 +01:00
|
|
|
* @param info TextureInfo object describing the texture setup
|
|
|
|
* @param disable_alpha This is used for debug widgets which use this method to display textures
|
|
|
|
* without providing a good way to visualize alpha by themselves. If true, this will return 255 for
|
|
|
|
* the alpha component, and either drop the information entirely or store it in an "unused" color
|
|
|
|
* channel.
|
|
|
|
* @todo Eventually we should get rid of the disable_alpha parameter.
|
|
|
|
*/
|
2019-02-27 04:38:34 +01:00
|
|
|
Common::Vec4<u8> LookupTexture(const u8* source, unsigned int x, unsigned int y,
|
|
|
|
const TextureInfo& info, bool disable_alpha = false);
|
2017-01-06 04:19:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Looks up a texel from a single 8x8 texture tile.
|
|
|
|
*
|
|
|
|
* @param source Pointer to the beginning of the tile.
|
|
|
|
* @param x, y In-tile coordinates to read from. Must be < 8.
|
|
|
|
* @param info TextureInfo describing the texture format.
|
|
|
|
* @param disable_alpha Used for debugging. Sets the result alpha to 255 and either discards the
|
|
|
|
* real alpha or inserts it in an otherwise unused channel.
|
|
|
|
*/
|
2019-02-27 04:38:34 +01:00
|
|
|
Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned int y,
|
|
|
|
const TextureInfo& info, bool disable_alpha);
|
2017-01-05 23:11:23 +01:00
|
|
|
|
2019-02-19 09:09:57 +01:00
|
|
|
} // namespace Pica::Texture
|