2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2008-12-07 21:46:09 -07:00
|
|
|
|
|
|
|
#include <map>
|
2017-09-16 23:54:03 -06:00
|
|
|
#include <utility>
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2017-02-01 08:56:13 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
#include "Common/GL/GLUtil.h"
|
2017-04-22 22:44:34 -06:00
|
|
|
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
2017-09-16 23:54:03 -06:00
|
|
|
#include "VideoCommon/TextureConversionShader.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
class AbstractTexture;
|
2017-09-16 23:54:03 -06:00
|
|
|
class StreamBuffer;
|
2017-04-22 22:44:34 -06:00
|
|
|
struct TextureConfig;
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
namespace OGL
|
|
|
|
{
|
2015-11-05 17:28:05 -07:00
|
|
|
class TextureCache : public TextureCacheBase
|
2008-12-07 21:46:09 -07:00
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
TextureCache();
|
|
|
|
~TextureCache();
|
2015-12-20 19:49:49 -07:00
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
static TextureCache* GetInstance();
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2017-07-30 13:45:55 -06:00
|
|
|
bool SupportsGPUTextureDecode(TextureFormat format, TLUTFormat palette_format) override;
|
2017-04-22 22:44:34 -06:00
|
|
|
void DecodeTextureOnGPU(TCacheEntry* entry, u32 dst_level, const u8* data, size_t data_size,
|
2016-11-27 01:15:00 -07:00
|
|
|
TextureFormat format, u32 width, u32 height, u32 aligned_width,
|
|
|
|
u32 aligned_height, u32 row_stride, const u8* palette,
|
2017-07-30 13:45:55 -06:00
|
|
|
TLUTFormat palette_format) override;
|
2016-11-27 01:15:00 -07:00
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
const SHADER& GetColorCopyProgram() const;
|
|
|
|
GLuint GetColorCopyPositionUniform() const;
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
private:
|
2017-09-16 23:54:03 -06:00
|
|
|
struct PaletteShader
|
|
|
|
{
|
|
|
|
SHADER shader;
|
|
|
|
GLuint buffer_offset_uniform;
|
|
|
|
GLuint multiplier_uniform;
|
|
|
|
GLuint copy_position_uniform;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextureDecodingProgramInfo
|
|
|
|
{
|
|
|
|
const TextureConversionShader::DecodingShaderInfo* base_info = nullptr;
|
|
|
|
SHADER program;
|
|
|
|
GLint uniform_dst_size = -1;
|
|
|
|
GLint uniform_src_size = -1;
|
|
|
|
GLint uniform_src_row_stride = -1;
|
|
|
|
GLint uniform_src_offset = -1;
|
|
|
|
GLint uniform_palette_offset = -1;
|
|
|
|
bool valid = false;
|
|
|
|
};
|
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
|
2017-07-30 13:45:55 -06:00
|
|
|
void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette,
|
|
|
|
TLUTFormat format) override;
|
2014-11-03 16:53:14 -07:00
|
|
|
|
2017-07-30 13:45:55 -06:00
|
|
|
void CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width, u32 bytes_per_row,
|
|
|
|
u32 num_blocks_y, u32 memory_stride, const EFBRectangle& src_rect,
|
|
|
|
bool scale_by_half) override;
|
2015-10-29 10:48:35 -06:00
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, const EFBRectangle& src_rect,
|
|
|
|
bool scale_by_half, unsigned int cbuf_id, const float* colmat) override;
|
|
|
|
|
2016-08-13 06:56:01 -06:00
|
|
|
bool CompileShaders() override;
|
2016-06-24 02:43:46 -06:00
|
|
|
void DeleteShaders() override;
|
2017-04-22 22:44:34 -06:00
|
|
|
|
2017-09-16 23:54:03 -06:00
|
|
|
bool CompilePaletteShader(TLUTFormat tlutfmt, const std::string& vcode, const std::string& pcode,
|
|
|
|
const std::string& gcode);
|
|
|
|
|
|
|
|
void CreateTextureDecodingResources();
|
|
|
|
void DestroyTextureDecodingResources();
|
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
SHADER m_colorCopyProgram;
|
|
|
|
SHADER m_colorMatrixProgram;
|
|
|
|
SHADER m_depthMatrixProgram;
|
|
|
|
GLuint m_colorMatrixUniform;
|
|
|
|
GLuint m_depthMatrixUniform;
|
|
|
|
GLuint m_colorCopyPositionUniform;
|
|
|
|
GLuint m_colorMatrixPositionUniform;
|
|
|
|
GLuint m_depthCopyPositionUniform;
|
2017-09-16 23:54:03 -06:00
|
|
|
|
|
|
|
u32 m_color_cbuf_id;
|
|
|
|
u32 m_depth_cbuf_id;
|
|
|
|
|
2017-09-17 00:26:45 -06:00
|
|
|
std::array<PaletteShader, 3> m_palette_shaders;
|
2017-09-16 23:54:03 -06:00
|
|
|
std::unique_ptr<StreamBuffer> m_palette_stream_buffer;
|
|
|
|
GLuint m_palette_resolv_texture = 0;
|
|
|
|
|
|
|
|
std::map<std::pair<u32, u32>, TextureDecodingProgramInfo> m_texture_decoding_program_info;
|
|
|
|
std::array<GLuint, TextureConversionShader::BUFFER_FORMAT_COUNT> m_texture_decoding_buffer_views;
|
2008-12-07 21:46:09 -07:00
|
|
|
};
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool SaveTexture(const std::string& filename, u32 textarget, u32 tex, int virtual_width,
|
|
|
|
int virtual_height, unsigned int level);
|
2010-10-19 16:24:27 -06:00
|
|
|
}
|