mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-27 15:30:35 +00:00
A bit closer to working. Shadow visible
This commit is contained in:
parent
8fba7fa98e
commit
d0e65054a4
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2014- PPSSPP Project.
|
// Copyright (c) 2014- PPSSPP Project.
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#define SHADERLOG
|
||||||
|
|
||||||
|
#include "base/logging.h"
|
||||||
#include "Common/Log.h"
|
#include "Common/Log.h"
|
||||||
#include "DepalettizeShader.h"
|
#include "DepalettizeShader.h"
|
||||||
#include "GPU/GPUState.h"
|
#include "GPU/GPUState.h"
|
||||||
@ -24,6 +27,7 @@
|
|||||||
|
|
||||||
static const char *depalVShader =
|
static const char *depalVShader =
|
||||||
"#version 100\n"
|
"#version 100\n"
|
||||||
|
"precision highp float;\n"
|
||||||
"// Depal shader\n"
|
"// Depal shader\n"
|
||||||
"attribute vec4 a_position;\n"
|
"attribute vec4 a_position;\n"
|
||||||
"attribute vec2 a_texcoord0;\n"
|
"attribute vec2 a_texcoord0;\n"
|
||||||
@ -82,11 +86,12 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat) {
|
|||||||
#define WRITE p+=sprintf
|
#define WRITE p+=sprintf
|
||||||
|
|
||||||
WRITE(p, "#version 100\n");
|
WRITE(p, "#version 100\n");
|
||||||
WRITE(p, "varying vec2 texcoord0;\n");
|
WRITE(p, "precision mediump float;\n");
|
||||||
|
WRITE(p, "varying vec2 v_texcoord0;\n");
|
||||||
WRITE(p, "uniform sampler2D tex;\n");
|
WRITE(p, "uniform sampler2D tex;\n");
|
||||||
WRITE(p, "uniform sampler2D pal;\n");
|
WRITE(p, "uniform sampler2D pal;\n");
|
||||||
WRITE(p, "void main() {\n");
|
WRITE(p, "void main() {\n");
|
||||||
WRITE(p, " vec4 index = texture2D(tex);\n");
|
WRITE(p, " vec4 index = texture2D(tex, v_texcoord0);\n");
|
||||||
|
|
||||||
char lookupMethod[128] = "index.r";
|
char lookupMethod[128] = "index.r";
|
||||||
char offset[128] = "";
|
char offset[128] = "";
|
||||||
@ -97,6 +102,7 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat) {
|
|||||||
int shift = gstate.getClutIndexShift();
|
int shift = gstate.getClutIndexShift();
|
||||||
int mask = gstate.getClutIndexMask();
|
int mask = gstate.getClutIndexMask();
|
||||||
|
|
||||||
|
float multiplier = 1.0f;
|
||||||
// pixelformat is the format of the texture we are sampling.
|
// pixelformat is the format of the texture we are sampling.
|
||||||
switch (pixelFormat) {
|
switch (pixelFormat) {
|
||||||
case GE_FORMAT_8888:
|
case GE_FORMAT_8888:
|
||||||
@ -121,6 +127,7 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat) {
|
|||||||
default:
|
default:
|
||||||
case 12: strcpy(lookupMethod, "index.a"); break;
|
case 12: strcpy(lookupMethod, "index.a"); break;
|
||||||
}
|
}
|
||||||
|
multiplier = 1.0f / 15.0f;
|
||||||
} else {
|
} else {
|
||||||
// Ugh
|
// Ugh
|
||||||
}
|
}
|
||||||
@ -133,6 +140,7 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat) {
|
|||||||
default:
|
default:
|
||||||
case 11: strcpy(lookupMethod, "index.b"); break;
|
case 11: strcpy(lookupMethod, "index.b"); break;
|
||||||
}
|
}
|
||||||
|
multiplier = 1.0f / 31.0f;
|
||||||
} else {
|
} else {
|
||||||
// Ugh
|
// Ugh
|
||||||
}
|
}
|
||||||
@ -156,8 +164,13 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat) {
|
|||||||
sprintf(offset, " + %.0f", (float)clutBase / 255.0f); // 256?
|
sprintf(offset, " + %.0f", (float)clutBase / 255.0f); // 256?
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, " vec4 color = texture2D(pal, vec2(%s%s, 0.0));\n", lookupMethod, offset);
|
if (true) {
|
||||||
WRITE(p, " gl_Color = color;\n");
|
|
||||||
|
WRITE(p, " gl_FragColor = vec4(index.r);\n", lookupMethod, offset);
|
||||||
|
//WRITE(p, " gl_FragColor = vec4(index) + texture2D(pal, vec2(v_texcoord0.x, 0));\n", lookupMethod, offset);
|
||||||
|
} else {
|
||||||
|
WRITE(p, " gl_FragColor = texture2D(pal, vec2((%s * %f)%s, 0.0));\n", lookupMethod, multiplier, offset);
|
||||||
|
}
|
||||||
WRITE(p, "}\n");
|
WRITE(p, "}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +188,6 @@ GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) {
|
|||||||
|
|
||||||
DepalTexture *tex = new DepalTexture();
|
DepalTexture *tex = new DepalTexture();
|
||||||
glGenTextures(1, &tex->texture);
|
glGenTextures(1, &tex->texture);
|
||||||
glActiveTexture(1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tex->texture);
|
glBindTexture(GL_TEXTURE_2D, tex->texture);
|
||||||
GLuint components = dstFmt == GL_UNSIGNED_SHORT_5_6_5 ? GL_RGB : GL_RGBA;
|
GLuint components = dstFmt == GL_UNSIGNED_SHORT_5_6_5 ? GL_RGB : GL_RGBA;
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, components, 256, 1, 0, components, dstFmt, (void *)rawClut);
|
glTexImage2D(GL_TEXTURE_2D, 0, components, 256, 1, 0, components, dstFmt, (void *)rawClut);
|
||||||
@ -183,7 +195,6 @@ GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) {
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glActiveTexture(0);
|
|
||||||
|
|
||||||
texCache_[clutID] = tex;
|
texCache_[clutID] = tex;
|
||||||
return tex->texture;
|
return tex->texture;
|
||||||
@ -213,13 +224,19 @@ GLuint DepalShaderCache::GetDepalettizeShader(GEBufferFormat pixelFormat) {
|
|||||||
return shader->second->program;
|
return shader->second->program;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[2048];
|
char *buffer = new char[2048];
|
||||||
|
|
||||||
GenerateDepalShader(buffer, pixelFormat);
|
GenerateDepalShader(buffer, pixelFormat);
|
||||||
|
|
||||||
GLuint fragShader = glCreateShader(GL_VERTEX_SHADER);
|
GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(vertexShader_, 1, &depalVShader, 0);
|
|
||||||
glCompileShader(vertexShader_);
|
const char *buf = buffer;
|
||||||
|
glShaderSource(fragShader, 1, &buf, 0);
|
||||||
|
glCompileShader(fragShader);
|
||||||
|
|
||||||
|
CheckShaderCompileSuccess(fragShader, buffer);
|
||||||
|
|
||||||
|
delete[] buffer;
|
||||||
|
|
||||||
GLuint program = glCreateProgram();
|
GLuint program = glCreateProgram();
|
||||||
glAttachShader(program, vertexShader_);
|
glAttachShader(program, vertexShader_);
|
||||||
|
@ -610,6 +610,7 @@ void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, flo
|
|||||||
shaderManager_->DirtyLastShader(); // dirty lastShader_
|
shaderManager_->DirtyLastShader(); // dirty lastShader_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VirtualFramebuffer *FramebufferManager::GetVFBAt(u32 addr) {
|
VirtualFramebuffer *FramebufferManager::GetVFBAt(u32 addr) {
|
||||||
VirtualFramebuffer *match = NULL;
|
VirtualFramebuffer *match = NULL;
|
||||||
for (size_t i = 0; i < vfbs_.size(); ++i) {
|
for (size_t i = 0; i < vfbs_.size(); ++i) {
|
||||||
@ -684,6 +685,10 @@ void FramebufferManager::DestroyFramebuf(VirtualFramebuffer *v) {
|
|||||||
delete v;
|
delete v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FramebufferManager::RebindFramebuffer() {
|
||||||
|
fbo_bind_as_render_target(currentRenderVfb_->fbo);
|
||||||
|
}
|
||||||
|
|
||||||
void FramebufferManager::DoSetRenderFrameBuffer() {
|
void FramebufferManager::DoSetRenderFrameBuffer() {
|
||||||
/*
|
/*
|
||||||
if (useBufferedRendering_ && currentRenderVfb_) {
|
if (useBufferedRendering_ && currentRenderVfb_) {
|
||||||
|
@ -220,6 +220,8 @@ public:
|
|||||||
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer);
|
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer);
|
||||||
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer);
|
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer);
|
||||||
|
|
||||||
|
void RebindFramebuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CompileDraw2DProgram();
|
void CompileDraw2DProgram();
|
||||||
void DestroyDraw2DProgram();
|
void DestroyDraw2DProgram();
|
||||||
|
@ -915,30 +915,67 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry) {
|
|||||||
entry->framebuffer->usageFlags |= FB_USAGE_TEXTURE;
|
entry->framebuffer->usageFlags |= FB_USAGE_TEXTURE;
|
||||||
bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
|
bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
|
||||||
if (useBufferedRendering) {
|
if (useBufferedRendering) {
|
||||||
framebufferManager_->BindFramebufferColor(entry->framebuffer);
|
|
||||||
|
|
||||||
if (entry->status & TexCacheEntry::STATUS_DEPALETTIZE) {
|
if (entry->status & TexCacheEntry::STATUS_DEPALETTIZE) {
|
||||||
GLuint program = depalShaderCache_->GetDepalettizeShader(entry->framebuffer->format);
|
|
||||||
glUseProgram(program);
|
|
||||||
|
|
||||||
// Check if we can handle the current setup
|
// Check if we can handle the current setup
|
||||||
|
|
||||||
GLuint clutTexture = depalShaderCache_->GetClutTexture(clutHash_, clutBufConverted_);
|
GLuint clutTexture = depalShaderCache_->GetClutTexture(clutHash_, clutBufConverted_);
|
||||||
glActiveTexture(1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, clutTexture);
|
|
||||||
glActiveTexture(0);
|
|
||||||
|
|
||||||
if (!entry->depalFBO) {
|
if (!entry->depalFBO) {
|
||||||
entry->depalFBO = fbo_create(entry->framebuffer->bufferWidth, entry->framebuffer->bufferHeight, 1, false, FBO_8888);
|
entry->depalFBO = fbo_create(entry->framebuffer->bufferWidth, entry->framebuffer->bufferHeight, 1, false, FBO_8888);
|
||||||
}
|
}
|
||||||
fbo_bind_as_render_target(entry->depalFBO);
|
fbo_bind_as_render_target(entry->depalFBO);
|
||||||
|
glViewport(0, 0, entry->framebuffer->bufferWidth, entry->framebuffer->bufferHeight);
|
||||||
|
|
||||||
// ...
|
static const float pos[12] = {
|
||||||
|
-1, -1, -1,
|
||||||
|
1, -1, -1,
|
||||||
|
1, 1, -1,
|
||||||
|
-1, 1, -1
|
||||||
|
};
|
||||||
|
static const float uv[8] = {
|
||||||
|
0, 0,
|
||||||
|
1, 0,
|
||||||
|
1, 1,
|
||||||
|
0, 1,
|
||||||
|
};
|
||||||
|
static const GLubyte indices[4] = { 0, 1, 3, 2 };
|
||||||
|
|
||||||
|
GLuint program = depalShaderCache_->GetDepalettizeShader(entry->framebuffer->format);
|
||||||
|
glUseProgram(program);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, clutTexture);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
|
framebufferManager_->BindFramebufferColor(entry->framebuffer);
|
||||||
|
|
||||||
|
glstate.blend.disable();
|
||||||
|
glstate.colorMask.set(true, true, true, true);
|
||||||
|
glstate.scissorTest.disable();
|
||||||
|
glstate.cullFace.disable();
|
||||||
|
glstate.depthTest.disable();
|
||||||
|
glstate.viewport.set(0, 0, entry->framebuffer->bufferWidth, entry->framebuffer->bufferHeight);
|
||||||
|
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 12, pos);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8, uv);
|
||||||
|
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||||
|
|
||||||
|
/*
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
glDisableVertexAttribArray(1);
|
||||||
|
*/
|
||||||
fbo_bind_color_as_texture(entry->depalFBO, 0);
|
fbo_bind_color_as_texture(entry->depalFBO, 0);
|
||||||
|
glstate.Restore();
|
||||||
|
framebufferManager_->RebindFramebuffer();
|
||||||
|
} else {
|
||||||
|
framebufferManager_->BindFramebufferColor(entry->framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Keep the framebuffer alive.
|
// Keep the framebuffer alive.
|
||||||
entry->framebuffer->last_frame_used = gpuStats.numFlips;
|
entry->framebuffer->last_frame_used = gpuStats.numFlips;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user