mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-15 10:40:01 +01:00
Merge pull request #6362 from unknownbrackets/gpu-minor
Upload stencil/color on FBO create, clear depth/stencil to 0, fix software transform
This commit is contained in:
commit
413704f674
4 files changed
+58
-32
No files matched your search
@@ -70,8 +70,7 @@ static const char tex_fs[] =
|
||||
"uniform sampler2D sampler0;\n"
|
||||
"varying vec2 v_texcoord0;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor.rgb = texture2D(sampler0, v_texcoord0).rgb;\n"
|
||||
" gl_FragColor.a = 1.0;\n"
|
||||
" gl_FragColor = texture2D(sampler0, v_texcoord0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char basic_vs[] =
|
||||
@@ -176,17 +175,28 @@ void FramebufferManager::ClearBuffer() {
|
||||
glstate.scissorTest.disable();
|
||||
glstate.depthWrite.set(GL_TRUE);
|
||||
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glstate.stencilFunc.set(GL_ALWAYS, 0xFF, 0xFF);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearStencil(0xFF);
|
||||
glstate.stencilFunc.set(GL_ALWAYS, 0, 0);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClearStencil(0);
|
||||
#ifdef USING_GLES2
|
||||
glClearDepthf(1.0f);
|
||||
glClearDepthf(0.0f);
|
||||
#else
|
||||
glClearDepth(1.0);
|
||||
glClearDepth(0.0);
|
||||
#endif
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void FramebufferManager::ClearDepthBuffer() {
|
||||
glstate.scissorTest.disable();
|
||||
glstate.depthWrite.set(GL_TRUE);
|
||||
#ifdef USING_GLES2
|
||||
glClearDepthf(0.0f);
|
||||
#else
|
||||
glClearDepth(0.0);
|
||||
#endif
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void FramebufferManager::DisableState() {
|
||||
glstate.blend.disable();
|
||||
glstate.cullFace.disable();
|
||||
@@ -961,7 +971,6 @@ void FramebufferManager::DoSetRenderFrameBuffer() {
|
||||
}
|
||||
|
||||
INFO_LOG(SCEGE, "Creating FBO for %08x : %i x %i x %i", vfb->fb_address, vfb->width, vfb->height, vfb->format);
|
||||
ClearBuffer();
|
||||
|
||||
textureCache_->NotifyFramebuffer(vfb->fb_address, vfb, NOTIFY_FB_CREATED);
|
||||
|
||||
@@ -977,6 +986,15 @@ void FramebufferManager::DoSetRenderFrameBuffer() {
|
||||
framebufRangeEnd_ = fb_address_mem + byteSize;
|
||||
}
|
||||
|
||||
if (useBufferedRendering_ && !updateVRAM_) {
|
||||
gpu->PerformMemoryUpload(fb_address_mem, byteSize);
|
||||
gpu->PerformStencilUpload(fb_address_mem, byteSize);
|
||||
// TODO: Is it worth trying to upload the depth buffer?
|
||||
ClearDepthBuffer();
|
||||
} else {
|
||||
ClearBuffer();
|
||||
}
|
||||
|
||||
// Let's check for depth buffer overlap. Might be interesting.
|
||||
bool sharingReported = false;
|
||||
for (size_t i = 0, end = vfbs_.size(); i < end; ++i) {
|
||||
|
||||
@@ -251,6 +251,7 @@ private:
|
||||
void EstimateDrawingSize(int &drawing_width, int &drawing_height);
|
||||
static void DisableState();
|
||||
static void ClearBuffer();
|
||||
static void ClearDepthBuffer();
|
||||
static bool MaskedEqual(u32 addr1, u32 addr2);
|
||||
|
||||
void SetColorUpdated(VirtualFramebuffer *dstBuffer) {
|
||||
|
||||
@@ -203,34 +203,40 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
||||
// Scale UV?
|
||||
} else {
|
||||
// We do software T&L for now
|
||||
float out[3], norm[3];
|
||||
float pos[3], nrm[3];
|
||||
float out[3];
|
||||
float pos[3];
|
||||
Vec3f normal(0, 0, 1);
|
||||
Vec3f worldnormal(0, 0, 1);
|
||||
reader.ReadPos(pos);
|
||||
if (reader.hasNormal())
|
||||
reader.ReadNrm(nrm);
|
||||
|
||||
if (!skinningEnabled) {
|
||||
Vec3ByMatrix43(out, pos, gstate.worldMatrix);
|
||||
if (reader.hasNormal()) {
|
||||
Norm3ByMatrix43(norm, nrm, gstate.worldMatrix);
|
||||
normal = Vec3f(norm).Normalized();
|
||||
reader.ReadNrm(normal.AsArray());
|
||||
if (gstate.areNormalsReversed()) {
|
||||
normal = -normal;
|
||||
}
|
||||
Norm3ByMatrix43(worldnormal.AsArray(), normal.AsArray(), gstate.worldMatrix);
|
||||
worldnormal = worldnormal.Normalized();
|
||||
}
|
||||
} else {
|
||||
float weights[8];
|
||||
reader.ReadWeights(weights);
|
||||
if (reader.hasNormal())
|
||||
reader.ReadNrm(normal.AsArray());
|
||||
|
||||
// Skinning
|
||||
Vec3f psum(0,0,0);
|
||||
Vec3f nsum(0,0,0);
|
||||
Vec3f psum(0, 0, 0);
|
||||
Vec3f nsum(0, 0, 0);
|
||||
for (int i = 0; i < vertTypeGetNumBoneWeights(vertType); i++) {
|
||||
if (weights[i] != 0.0f) {
|
||||
Vec3ByMatrix43(out, pos, gstate.boneMatrix+i*12);
|
||||
Vec3f tpos(out);
|
||||
psum += tpos * weights[i];
|
||||
if (reader.hasNormal()) {
|
||||
Norm3ByMatrix43(norm, nrm, gstate.boneMatrix+i*12);
|
||||
Vec3f tnorm(norm);
|
||||
nsum += tnorm * weights[i];
|
||||
Vec3f norm;
|
||||
Norm3ByMatrix43(norm.AsArray(), normal.AsArray(), gstate.boneMatrix+i*12);
|
||||
nsum += norm * weights[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,8 +244,12 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
||||
// Yes, we really must multiply by the world matrix too.
|
||||
Vec3ByMatrix43(out, psum.AsArray(), gstate.worldMatrix);
|
||||
if (reader.hasNormal()) {
|
||||
Norm3ByMatrix43(norm, nsum.AsArray(), gstate.worldMatrix);
|
||||
normal = Vec3f(norm).Normalized();
|
||||
normal = nsum;
|
||||
if (gstate.areNormalsReversed()) {
|
||||
normal = -normal;
|
||||
}
|
||||
Norm3ByMatrix43(worldnormal.AsArray(), normal.AsArray(), gstate.worldMatrix);
|
||||
worldnormal = worldnormal.Normalized();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +264,7 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
||||
if (gstate.isLightingEnabled()) {
|
||||
float litColor0[4];
|
||||
float litColor1[4];
|
||||
lighter.Light(litColor0, litColor1, unlitColor.AsArray(), out, normal);
|
||||
lighter.Light(litColor0, litColor1, unlitColor.AsArray(), out, worldnormal);
|
||||
|
||||
// Don't ignore gstate.lmode - we should send two colors in that case
|
||||
for (int j = 0; j < 4; j++) {
|
||||
@@ -317,20 +327,16 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
||||
break;
|
||||
|
||||
case GE_PROJMAP_NORMALIZED_NORMAL: // Use normalized normal as source
|
||||
if (reader.hasNormal()) {
|
||||
source = Vec3f(norm).Normalized();
|
||||
} else {
|
||||
source = normal.Normalized();
|
||||
if (!reader.hasNormal()) {
|
||||
ERROR_LOG_REPORT(G3D, "Normal projection mapping without normal?");
|
||||
source = Vec3f(0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
break;
|
||||
|
||||
case GE_PROJMAP_NORMAL: // Use non-normalized normal as source!
|
||||
if (reader.hasNormal()) {
|
||||
source = Vec3f(norm);
|
||||
} else {
|
||||
source = normal;
|
||||
if (!reader.hasNormal()) {
|
||||
ERROR_LOG_REPORT(G3D, "Normal projection mapping without normal?");
|
||||
source = Vec3f(0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -349,8 +355,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
||||
Vec3f lightpos0 = Vec3f(&lighter.lpos[gstate.getUVLS0() * 3]).Normalized();
|
||||
Vec3f lightpos1 = Vec3f(&lighter.lpos[gstate.getUVLS1() * 3]).Normalized();
|
||||
|
||||
uv[0] = (1.0f + Dot(lightpos0, normal))/2.0f;
|
||||
uv[1] = (1.0f + Dot(lightpos1, normal))/2.0f;
|
||||
uv[0] = (1.0f + Dot(lightpos0, worldnormal))/2.0f;
|
||||
uv[1] = (1.0f + Dot(lightpos1, worldnormal))/2.0f;
|
||||
uv[2] = 1.0f;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -88,6 +88,7 @@ bool FramebufferManager::NotifyStencilUpload(u32 addr, int size) {
|
||||
|
||||
shaderManager_->DirtyLastShader();
|
||||
|
||||
// TODO: Check if it's all the same value, commonly 0?
|
||||
MakePixelTexture(Memory::GetPointer(addr), dstBuffer->format, dstBuffer->fb_stride, dstBuffer->bufferWidth, dstBuffer->bufferHeight);
|
||||
DisableState();
|
||||
glstate.colorMask.set(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
|
||||
|
||||
Reference in new issue
Block a user