mirror of
https://github.com/libretro/ppsspp.git
synced 2025-03-06 07:28:12 +00:00
Minor cleanup in thin3d
This commit is contained in:
parent
e3bca489be
commit
d43b3ef73f
@ -400,7 +400,7 @@ void DrawBuffer::MeasureTextCount(int font, const char *text, int count, float *
|
||||
}
|
||||
|
||||
void DrawBuffer::MeasureTextRect(int font, const char *text, int count, const Bounds &bounds, float *w, float *h, int align) {
|
||||
if (!text || (uint32_t)font >= atlas->num_fonts) {
|
||||
if (!text || (uint32_t)font >= (uint32_t)atlas->num_fonts) {
|
||||
*w = 0;
|
||||
*h = 0;
|
||||
return;
|
||||
|
@ -163,11 +163,11 @@ void Thin3DContext::CreatePresets() {
|
||||
sampsPresets_[SAMPS_NEAREST] = CreateSamplerState(nearest);
|
||||
sampsPresets_[SAMPS_LINEAR] = CreateSamplerState(linear);
|
||||
|
||||
vsPresets_[VS_TEXTURE_COLOR_2D] = CreateVertexShader(glsl_vsTexCol, hlslVsTexCol, vulkan_vsTexCol);
|
||||
vsPresets_[VS_COLOR_2D] = CreateVertexShader(glsl_vsCol, hlslVsCol, vulkan_vsCol);
|
||||
vsPresets_[VS_TEXTURE_COLOR_2D] = CreateShader(ShaderStage::VERTEX, glsl_vsTexCol, hlslVsTexCol, vulkan_vsTexCol);
|
||||
vsPresets_[VS_COLOR_2D] = CreateShader(ShaderStage::VERTEX, glsl_vsCol, hlslVsCol, vulkan_vsCol);
|
||||
|
||||
fsPresets_[FS_TEXTURE_COLOR_2D] = CreateFragmentShader(glsl_fsTexCol, hlslFsTexCol, vulkan_fsTexCol);
|
||||
fsPresets_[FS_COLOR_2D] = CreateFragmentShader(glsl_fsCol, hlslFsCol, vulkan_fsCol);
|
||||
fsPresets_[FS_TEXTURE_COLOR_2D] = CreateShader(ShaderStage::FRAGMENT, glsl_fsTexCol, hlslFsTexCol, vulkan_fsTexCol);
|
||||
fsPresets_[FS_COLOR_2D] = CreateShader(ShaderStage::FRAGMENT, glsl_fsCol, hlslFsCol, vulkan_fsCol);
|
||||
|
||||
ssPresets_[SS_TEXTURE_COLOR_2D] = CreateShaderSet(vsPresets_[VS_TEXTURE_COLOR_2D], fsPresets_[FS_TEXTURE_COLOR_2D]);
|
||||
ssPresets_[SS_COLOR_2D] = CreateShaderSet(vsPresets_[VS_COLOR_2D], fsPresets_[FS_COLOR_2D]);
|
||||
|
@ -299,6 +299,20 @@ public:
|
||||
virtual void SetMatrix4x4(const char *name, const float value[16]) = 0;
|
||||
};
|
||||
|
||||
enum class ShaderStage {
|
||||
VERTEX,
|
||||
FRAGMENT,
|
||||
};
|
||||
|
||||
enum class ShaderLanguage {
|
||||
GLSL_ES_200,
|
||||
GLSL_ES_300,
|
||||
GLSL_410,
|
||||
GLSL_VULKAN,
|
||||
HLSL_D3D9,
|
||||
HLSL_D3D11,
|
||||
};
|
||||
|
||||
struct T3DBlendStateDesc {
|
||||
bool enabled;
|
||||
T3DBlendEquation eqCol;
|
||||
@ -348,8 +362,7 @@ public:
|
||||
Thin3DShaderSet *GetShaderSetPreset(T3DShaderSetPreset preset) { return ssPresets_[preset]; }
|
||||
|
||||
// The implementation makes the choice of which shader code to use.
|
||||
virtual Thin3DShader *CreateVertexShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) = 0;
|
||||
virtual Thin3DShader *CreateFragmentShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) = 0;
|
||||
virtual Thin3DShader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) = 0;
|
||||
|
||||
// Bound state objects. Too cumbersome to add them all as parameters to Draw.
|
||||
virtual void SetBlendState(Thin3DBlendState *state) = 0;
|
||||
|
@ -224,7 +224,7 @@ private:
|
||||
|
||||
class Thin3DDX9Shader : public Thin3DShader {
|
||||
public:
|
||||
Thin3DDX9Shader(bool isPixelShader) : isPixelShader_(isPixelShader), vshader_(NULL), pshader_(NULL), constantTable_(NULL) {}
|
||||
Thin3DDX9Shader(ShaderStage stage) : stage_(stage), vshader_(NULL), pshader_(NULL), constantTable_(NULL) {}
|
||||
~Thin3DDX9Shader() {
|
||||
if (vshader_)
|
||||
vshader_->Release();
|
||||
@ -233,9 +233,9 @@ public:
|
||||
if (constantTable_)
|
||||
constantTable_->Release();
|
||||
}
|
||||
bool Compile(LPDIRECT3DDEVICE9 device, const char *source, const char *profile);
|
||||
bool Compile(LPDIRECT3DDEVICE9 device, const char *source);
|
||||
void Apply(LPDIRECT3DDEVICE9 device) {
|
||||
if (isPixelShader_) {
|
||||
if (stage_ == ShaderStage::FRAGMENT) {
|
||||
device->SetPixelShader(pshader_);
|
||||
} else {
|
||||
device->SetVertexShader(vshader_);
|
||||
@ -245,7 +245,7 @@ public:
|
||||
void SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]);
|
||||
|
||||
private:
|
||||
bool isPixelShader_;
|
||||
ShaderStage stage_;
|
||||
LPDIRECT3DVERTEXSHADER9 vshader_;
|
||||
LPDIRECT3DPIXELSHADER9 pshader_;
|
||||
LPD3DXCONSTANTTABLE constantTable_;
|
||||
@ -433,9 +433,7 @@ public:
|
||||
Thin3DVertexFormat *CreateVertexFormat(const std::vector<Thin3DVertexComponent> &components, int stride, Thin3DShader *vshader) override;
|
||||
Thin3DTexture *CreateTexture() override;
|
||||
Thin3DTexture *CreateTexture(T3DTextureType type, T3DImageFormat format, int width, int height, int depth, int mipLevels) override;
|
||||
|
||||
Thin3DShader *CreateVertexShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
Thin3DShader *CreateFragmentShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
Thin3DShader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
|
||||
// Bound state objects. Too cumbersome to add them all as parameters to Draw.
|
||||
void SetBlendState(Thin3DBlendState *state) {
|
||||
@ -502,19 +500,9 @@ Thin3DDX9Context::Thin3DDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int ada
|
||||
Thin3DDX9Context::~Thin3DDX9Context() {
|
||||
}
|
||||
|
||||
Thin3DShader *Thin3DDX9Context::CreateVertexShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DDX9Shader *shader = new Thin3DDX9Shader(false);
|
||||
if (shader->Compile(device_, hlsl_source, "vs_2_0")) {
|
||||
return shader;
|
||||
} else {
|
||||
delete shader;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Thin3DShader *Thin3DDX9Context::CreateFragmentShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DDX9Shader *shader = new Thin3DDX9Shader(true);
|
||||
if (shader->Compile(device_, hlsl_source, "ps_2_0")) {
|
||||
Thin3DShader *Thin3DDX9Context::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DDX9Shader *shader = new Thin3DDX9Shader(stage);
|
||||
if (shader->Compile(device_, hlsl_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
delete shader;
|
||||
@ -737,12 +725,13 @@ void Thin3DDX9Context::SetViewports(int count, T3DViewport *viewports) {
|
||||
device_->SetViewport(&vp);
|
||||
}
|
||||
|
||||
bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source, const char *profile) {
|
||||
bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source) {
|
||||
LPD3DXMACRO defines = NULL;
|
||||
LPD3DXINCLUDE includes = NULL;
|
||||
DWORD flags = 0;
|
||||
LPD3DXBUFFER codeBuffer;
|
||||
LPD3DXBUFFER errorBuffer;
|
||||
const char *profile = stage_ == ShaderStage::FRAGMENT ? "ps_2_0" : "vs_2_0";
|
||||
HRESULT hr = dyn_D3DXCompileShader(source, (UINT)strlen(source), defines, includes, "main", profile, flags, &codeBuffer, &errorBuffer, &constantTable_);
|
||||
if (FAILED(hr)) {
|
||||
const char *error = (const char *)errorBuffer->GetBufferPointer();
|
||||
@ -758,7 +747,7 @@ bool Thin3DDX9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source, cons
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
if (isPixelShader_) {
|
||||
if (stage_ == ShaderStage::FRAGMENT) {
|
||||
HRESULT result = device->CreatePixelShader((DWORD *)codeBuffer->GetBufferPointer(), &pshader_);
|
||||
success = SUCCEEDED(result);
|
||||
} else {
|
||||
|
@ -229,8 +229,8 @@ private:
|
||||
// invoke Compile again to recreate the shader then link them together.
|
||||
class Thin3DGLShader : public Thin3DShader {
|
||||
public:
|
||||
Thin3DGLShader(bool isFragmentShader) : shader_(0), type_(0) {
|
||||
type_ = isFragmentShader ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER;
|
||||
Thin3DGLShader(ShaderStage stage) : shader_(0), type_(0) {
|
||||
type_ = stage == ShaderStage::FRAGMENT ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER;
|
||||
}
|
||||
|
||||
bool Compile(const char *source);
|
||||
@ -400,9 +400,7 @@ public:
|
||||
s->Apply();
|
||||
}
|
||||
|
||||
// The implementation makes the choice of which shader code to use.
|
||||
Thin3DShader *CreateVertexShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
Thin3DShader *CreateFragmentShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
Thin3DShader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
|
||||
void SetScissorEnabled(bool enable) override {
|
||||
if (enable) {
|
||||
@ -760,18 +758,8 @@ void Thin3DGLContext::SetTextures(int start, int count, Thin3DTexture **textures
|
||||
}
|
||||
|
||||
|
||||
Thin3DShader *Thin3DGLContext::CreateVertexShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DGLShader *shader = new Thin3DGLShader(false);
|
||||
if (shader->Compile(glsl_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
shader->Release();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Thin3DShader *Thin3DGLContext::CreateFragmentShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DGLShader *shader = new Thin3DGLShader(true);
|
||||
Thin3DShader *Thin3DGLContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DGLShader *shader = new Thin3DGLShader(stage);
|
||||
if (shader->Compile(glsl_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
|
@ -188,8 +188,8 @@ private:
|
||||
// invoke Compile again to recreate the shader then link them together.
|
||||
class Thin3DVKShader : public Thin3DShader {
|
||||
public:
|
||||
Thin3DVKShader(bool isFragmentShader) : module_(VK_NULL_HANDLE), ok_(false) {
|
||||
stage_ = isFragmentShader ? VK_SHADER_STAGE_FRAGMENT_BIT : VK_SHADER_STAGE_VERTEX_BIT;
|
||||
Thin3DVKShader(ShaderStage stage) : module_(VK_NULL_HANDLE), ok_(false) {
|
||||
stage_ = stage == ShaderStage::FRAGMENT ? VK_SHADER_STAGE_FRAGMENT_BIT : VK_SHADER_STAGE_VERTEX_BIT;
|
||||
}
|
||||
bool Compile(VulkanContext *vulkan, const char *source);
|
||||
const std::string &GetSource() const { return source_; }
|
||||
@ -377,8 +377,7 @@ public:
|
||||
}
|
||||
|
||||
// The implementation makes the choice of which shader code to use.
|
||||
Thin3DShader *CreateVertexShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
Thin3DShader *CreateFragmentShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
Thin3DShader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
|
||||
void SetScissorEnabled(bool enable) override {
|
||||
scissorEnabled_ = enable;
|
||||
@ -1005,19 +1004,8 @@ void Thin3DVKContext::SetTextures(int start, int count, Thin3DTexture **textures
|
||||
}
|
||||
}
|
||||
|
||||
Thin3DShader *Thin3DVKContext::CreateVertexShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DVKShader *shader = new Thin3DVKShader(false);
|
||||
if (shader->Compile(vulkan_, vulkan_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
ELOG("Failed to compile shader: %s", vulkan_source);
|
||||
shader->Release();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Thin3DShader *Thin3DVKContext::CreateFragmentShader(const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DVKShader *shader = new Thin3DVKShader(true);
|
||||
Thin3DShader *Thin3DVKContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
Thin3DVKShader *shader = new Thin3DVKShader(stage);
|
||||
if (shader->Compile(vulkan_, vulkan_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user