mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Add math dataconv funcs for packed values.
This commit is contained in:
parent
438c7c1344
commit
d67b148712
@ -404,12 +404,12 @@ void ShaderManagerDX9::VSUpdateUniforms(int dirtyUniforms) {
|
||||
}
|
||||
if (allDirty) {
|
||||
// Set them all with one call
|
||||
glUniformMatrix4fv(u_bone, numBones, GL_FALSE, allBones);
|
||||
//glUniformMatrix4fv(u_bone, numBones, GL_FALSE, allBones);
|
||||
} else {
|
||||
// Set them one by one. Could try to coalesce two in a row etc but too lazy.
|
||||
for (int i = 0; i < numBones; i++) {
|
||||
if (dirtyUniforms & (DIRTY_BONEMATRIX0 << i)) {
|
||||
glUniformMatrix4fv(u_bone + i, 1, GL_FALSE, allBones + 16 * i);
|
||||
//glUniformMatrix4fv(u_bone + i, 1, GL_FALSE, allBones + 16 * i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ static const GLushort cullingMode[] = {
|
||||
GL_BACK,
|
||||
};
|
||||
|
||||
static const GLushort ztests[] = {
|
||||
static const GLushort compareOps[] = {
|
||||
GL_NEVER, GL_ALWAYS, GL_EQUAL, GL_NOTEQUAL,
|
||||
GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL,
|
||||
};
|
||||
@ -289,7 +289,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
|
||||
// Depth Test
|
||||
if (gstate.isDepthTestEnabled()) {
|
||||
glstate.depthTest.enable();
|
||||
glstate.depthFunc.set(ztests[gstate.getDepthTestFunction()]);
|
||||
glstate.depthFunc.set(compareOps[gstate.getDepthTestFunction()]);
|
||||
glstate.depthWrite.set(gstate.isDepthWriteEnabled() || alwaysDepthWrite ? GL_TRUE : GL_FALSE);
|
||||
if (gstate.isDepthWriteEnabled() || alwaysDepthWrite) {
|
||||
framebufferManager_->SetDepthUpdated();
|
||||
@ -337,7 +337,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
|
||||
// Stencil Test
|
||||
if (stencilState.enabled) {
|
||||
glstate.stencilTest.enable();
|
||||
glstate.stencilFunc.set(ztests[stencilState.testFunc], stencilState.testRef, stencilState.testMask);
|
||||
glstate.stencilFunc.set(compareOps[stencilState.testFunc], stencilState.testRef, stencilState.testMask);
|
||||
glstate.stencilOp.set(stencilOps[stencilState.sFail], stencilOps[stencilState.zFail], stencilOps[stencilState.zPass]);
|
||||
glstate.stencilMask.set(stencilState.writeMask);
|
||||
} else {
|
||||
|
88
ext/native/math/dataconv.h
Normal file
88
ext/native/math/dataconv.h
Normal file
@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cstring>
|
||||
|
||||
// Utilities useful for filling in std140-layout uniform buffers.
|
||||
|
||||
|
||||
// LSBs in f[0], etc.
|
||||
// Could be SSE optimized.
|
||||
inline void Uint8x4ToFloat4(float f[4], uint32_t u) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = ((u >> 8) & 0xFF) * (1.0f / 255.0f);
|
||||
f[2] = ((u >> 16) & 0xFF) * (1.0f / 255.0f);
|
||||
f[3] = ((u >> 24) & 0xFF) * (1.0f / 255.0f);
|
||||
}
|
||||
|
||||
inline void Uint8x3ToFloat4(float f[4], uint32_t u) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = ((u >> 8) & 0xFF) * (1.0f / 255.0f);
|
||||
f[2] = ((u >> 16) & 0xFF) * (1.0f / 255.0f);
|
||||
f[3] = 0.0f;
|
||||
}
|
||||
|
||||
inline void Uint8x3ToInt4(int i[4], uint32_t u) {
|
||||
i[0] = ((u >> 0) & 0xFF);
|
||||
i[1] = ((u >> 8) & 0xFF);
|
||||
i[2] = ((u >> 16) & 0xFF);
|
||||
i[3] = 0;
|
||||
}
|
||||
|
||||
inline void Uint8x3ToFloat4_Alpha(float f[4], uint32_t u, float alpha) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = ((u >> 8) & 0xFF) * (1.0f / 255.0f);
|
||||
f[2] = ((u >> 16) & 0xFF) * (1.0f / 255.0f);
|
||||
f[3] = alpha;
|
||||
}
|
||||
|
||||
inline void Uint8x3ToFloat4_AlphaUint8(float f[4], uint32_t u, uint8_t alpha) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = ((u >> 8) & 0xFF) * (1.0f / 255.0f);
|
||||
f[2] = ((u >> 16) & 0xFF) * (1.0f / 255.0f);
|
||||
f[3] = alpha * (1.0f / 255.0f);
|
||||
}
|
||||
|
||||
inline void Uint8x1ToFloat4(float f[4], uint32_t u) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = 0.0f;
|
||||
f[2] = 0.0f;
|
||||
f[3] = 0.0f;
|
||||
}
|
||||
|
||||
// These are just for readability.
|
||||
|
||||
inline void CopyFloat2(float dest[2], const float src[2]) {
|
||||
memcpy(dest, src, sizeof(float) * 2);
|
||||
}
|
||||
|
||||
inline void CopyFloat1To4(float dest[4], const float src) {
|
||||
dest[0] = src;
|
||||
dest[1] = 0.0f;
|
||||
dest[2] = 0.0f;
|
||||
dest[3] = 0.0f;
|
||||
}
|
||||
|
||||
inline void CopyFloat2To4(float dest[4], const float src[2]) {
|
||||
memcpy(dest, src, sizeof(float) * 2);
|
||||
dest[2] = 0.0f;
|
||||
dest[3] = 0.0f;
|
||||
}
|
||||
|
||||
inline void CopyFloat3To4(float dest[4], const float src[3]) {
|
||||
memcpy(dest, src, sizeof(float) * 3);
|
||||
dest[3] = 0.0f;
|
||||
}
|
||||
|
||||
inline void CopyFloat4(float dest[4], const float src[4]) {
|
||||
memcpy(dest, src, sizeof(float) * 4);
|
||||
}
|
||||
|
||||
inline void CopyMatrix4x4(float dest[16], const float src[16]) {
|
||||
memcpy(dest, src, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
inline void ExpandFloat24x3ToFloat4(float dest[4], uint32_t src[3]) {
|
||||
uint32_t temp[4] = { src[0] << 8, src[1] << 8, src[2] << 8, 0 };
|
||||
memcpy(dest, temp, sizeof(float) * 4);
|
||||
}
|
@ -247,6 +247,7 @@
|
||||
<ClInclude Include="input\keycodes.h" />
|
||||
<ClInclude Include="json\json_writer.h" />
|
||||
<ClInclude Include="math\curves.h" />
|
||||
<ClInclude Include="math\dataconv.h" />
|
||||
<ClInclude Include="math\expression_parser.h" />
|
||||
<ClInclude Include="math\geom2d.h" />
|
||||
<ClInclude Include="math\lin\matrix4x4.h" />
|
||||
|
@ -305,6 +305,9 @@
|
||||
<ClInclude Include="file\free.h">
|
||||
<Filter>file</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="math\dataconv.h">
|
||||
<Filter>math</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="gfx\gl_debug_log.cpp">
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "image/zim_load.h"
|
||||
#include "math/dataconv.h"
|
||||
#include "math/lin/matrix4x4.h"
|
||||
#include "thin3d/thin3d.h"
|
||||
#include "gfx/gl_common.h"
|
||||
@ -74,13 +75,6 @@ static const char *glsl_fragment_prelude =
|
||||
"precision mediump float;\n"
|
||||
"#endif\n";
|
||||
|
||||
static inline void Uint32ToFloat4(uint32_t u, float f[4]) {
|
||||
f[0] = ((u >> 0) & 0xFF) * (1.0f / 255.0f);
|
||||
f[1] = ((u >> 8) & 0xFF) * (1.0f / 255.0f);
|
||||
f[2] = ((u >> 16) & 0xFF) * (1.0f / 255.0f);
|
||||
f[3] = ((u >> 24) & 0xFF) * (1.0f / 255.0f);
|
||||
}
|
||||
|
||||
class Thin3DGLBlendState : public Thin3DBlendState {
|
||||
public:
|
||||
bool enabled;
|
||||
@ -810,7 +804,7 @@ void Thin3DGLContext::DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin
|
||||
|
||||
void Thin3DGLContext::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) {
|
||||
float col[4];
|
||||
Uint32ToFloat4(colorval, col);
|
||||
Uint8x4ToFloat4(col, colorval);
|
||||
GLuint glMask = 0;
|
||||
if (mask & T3DClear::COLOR) {
|
||||
glClearColor(col[0], col[1], col[2], col[3]);
|
||||
|
Loading…
Reference in New Issue
Block a user