1 // Copyright 2017 Citra Emulator Project 2 // Licensed under GPLv2 or any later version 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include "common/common_types.h" 8 #include "common/vector_math.h" 9 #include "video_core/regs_texturing.h" 10 11 namespace Pica::Texture { 12 13 /// Returns the byte size of a 8*8 tile of the specified texture format. 14 size_t CalculateTileSize(TexturingRegs::TextureFormat format); 15 16 struct TextureInfo { 17 PAddr physical_address; 18 unsigned int width; 19 unsigned int height; 20 ptrdiff_t stride; 21 TexturingRegs::TextureFormat format; 22 23 static TextureInfo FromPicaRegister(const TexturingRegs::TextureConfig& config, 24 const TexturingRegs::TextureFormat& format); 25 26 /// Calculates stride from format and width, assuming that the entire texture is contiguous. SetDefaultStrideTextureInfo27 void SetDefaultStride() { 28 stride = CalculateTileSize(format) * (width / 8); 29 } 30 }; 31 32 /** 33 * Lookup texel located at the given coordinates and return an RGBA vector of its color. 34 * @param source Source pointer to read data from 35 * @param x,y Texture coordinates to read from 36 * @param info TextureInfo object describing the texture setup 37 * @param disable_alpha This is used for debug widgets which use this method to display textures 38 * without providing a good way to visualize alpha by themselves. If true, this will return 255 for 39 * the alpha component, and either drop the information entirely or store it in an "unused" color 40 * channel. 41 * @todo Eventually we should get rid of the disable_alpha parameter. 42 */ 43 Common::Vec4<u8> LookupTexture(const u8* source, unsigned int x, unsigned int y, 44 const TextureInfo& info, bool disable_alpha = false); 45 46 /** 47 * Looks up a texel from a single 8x8 texture tile. 48 * 49 * @param source Pointer to the beginning of the tile. 50 * @param x, y In-tile coordinates to read from. Must be < 8. 51 * @param info TextureInfo describing the texture format. 52 * @param disable_alpha Used for debugging. Sets the result alpha to 255 and either discards the 53 * real alpha or inserts it in an otherwise unused channel. 54 */ 55 Common::Vec4<u8> LookupTexelInTile(const u8* source, unsigned int x, unsigned int y, 56 const TextureInfo& info, bool disable_alpha); 57 58 } // namespace Pica::Texture 59