Permalink
Browse files

video-gliden64: Update to commit db38b2f.

gonetz/GLideN64@db38b2f

* db38b2f Fix compilation on Android.
* 74afd9f Fix getTextureShiftScale for case of one-level mip-map.
* 1dc2bd1 Fix compilation on Linux.
* 2199dd4 Correct Lod calculaton and mipmaping.
* 5f42da7 Correct min_lod load.
* 2714906 Correct load to TMEM functions: wrap tmem address in case of overflow.
* a13e632 Code cleanup: correct class TextDrawer definition.
* 68941f6 Optimize frame buffer copy to RDRAM: read from pixel buffer one time per pixel. Old code does 4 reads from the pixel buffer per pixel.
* 7ee974f Remove debug calls of isGLError() from FrameBufferToRDRAM::CopyToRDRAM.
* eb23f38 New fix for issue #563. It does not break CBFD work.
* 48959f0 Revert "Correct coronas emulation in Perfect Dark."
* 5e56691 Fix compilation of depth_compare_shader_float for GL ES 3.1
* e4b440e Fix compilation of shadow_map_fragment_shader_float for GL ES 3.1
* c2476e8 Remove debug calls of isGLError() from NoiseTexture::update().
* 5e5a48e Make shaders GL ES 3.1 conformant.
* 563f167 Correct FBOTextureFormats::init() Now GLES2 setup should be compatible with all GLES2 devices.
* 5e114a7 Fix compilation with gcc, issue #572
* e3dcba0 Minor correction in GetCI16RGBA functions.
* 8472453 Add debugPrint function for VisualStudio debug output.
* 36fbcd5 Correct coronas emulation in Perfect Dark.
* 4b6df9b Fix possible crash in texturedRectDepthBufferCopy.
  • Loading branch information...
Gilles Siberlin authored and Gillou68310 committed Jun 18, 2015
1 parent 14f135d commit a077a17e8466d3bfb7d230f0421c479600f8a45b
@@ -71,11 +71,11 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer)
m_pDepthImageTexture->mirrorT = 0;
m_pDepthImageTexture->realWidth = m_pDepthImageTexture->width;
m_pDepthImageTexture->realHeight = m_pDepthImageTexture->height;
- m_pDepthImageTexture->textureBytes = m_pDepthImageTexture->realWidth * m_pDepthImageTexture->realHeight * 2 * sizeof(float); // Width*Height*RG*sizeof(GL_RGBA32F)
+ m_pDepthImageTexture->textureBytes = m_pDepthImageTexture->realWidth * m_pDepthImageTexture->realHeight * fboFormats.depthImageFormatBytes;
textureCache().addFrameBufferTextureSize(m_pDepthImageTexture->textureBytes);
glBindTexture(GL_TEXTURE_2D, m_pDepthImageTexture->glName);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, m_pDepthImageTexture->realWidth, m_pDepthImageTexture->realHeight, 0, GL_RG, GL_FLOAT, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthImageInternalFormat, m_pDepthImageTexture->realWidth, m_pDepthImageTexture->realHeight, 0, fboFormats.depthImageFormat, fboFormats.depthImageType, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
@@ -215,7 +215,7 @@ void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer)
void DepthBuffer::bindDepthImageTexture()
{
#ifdef GL_IMAGE_TEXTURES_SUPPORT
- glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F);
+ glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat);
#endif
}
@@ -332,13 +332,13 @@ void DepthBufferList::clearBuffer(u32 _uly, u32 _lry)
if (m_pCurrent->m_FBO == 0 || !video().getRender().isImageTexturesSupported() || config.frameBufferEmulation.N64DepthCompare == 0)
return;
float color[4] = {1.0f, 1.0f, 0.0f, 1.0f};
- glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F);
+ glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_pCurrent->m_FBO);
const u32 cycleType = gDP.otherMode.cycleType;
gDP.otherMode.cycleType = G_CYC_FILL;
video().getRender().drawRect(0,0,VI.width, VI.height, color);
gDP.otherMode.cycleType = cycleType;
- glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RG32F);
+ glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().getCurrent()->m_FBO);
#endif // GL_IMAGE_TEXTURES_SUPPORT
}
@@ -34,8 +34,11 @@ class FrameBufferToRDRAM
private:
void _copyWhite(FrameBuffer * _pBuffer);
- struct RGBA {
- u8 r, g, b, a;
+ union RGBA {
+ struct {
+ u8 r, g, b, a;
+ };
+ u32 raw;
};
GLuint m_FBO;
@@ -47,7 +50,7 @@ class DepthBufferToRDRAM
{
public:
DepthBufferToRDRAM() :
- m_FBO(0), m_PBO(0), m_pColorTexture(NULL), m_pDepthTexture(NULL), m_lastDList(0)
+ m_FBO(0), m_PBO(0), m_pColorTexture(NULL), m_pDepthTexture(NULL)
{}
void Init();
@@ -60,7 +63,6 @@ class DepthBufferToRDRAM
GLuint m_PBO;
CachedTexture * m_pColorTexture;
CachedTexture * m_pDepthTexture;
- u32 m_lastDList;
};
#endif // GLES2
@@ -959,9 +961,7 @@ void FrameBufferToRDRAM::CopyToRDRAM(u32 _address)
#ifndef GLES2
PBOBinder binder(GL_PIXEL_PACK_BUFFER, m_PBO);
glReadPixels(0, 0, VI.width, VI.height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
- isGLError();
GLubyte* pixelData = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, VI.width * VI.height * 4, GL_MAP_READ_BIT);
- isGLError();
if(pixelData == NULL)
return;
#else
@@ -986,11 +986,12 @@ void FrameBufferToRDRAM::CopyToRDRAM(u32 _address)
}
} else {
u16 *ptr_dst = (u16*)(RDRAM + _address);
- RGBA * ptr_src = (RGBA*)pixelData;
+ u32 * ptr_src = (u32*)pixelData;
+ RGBA c;
for (u32 y = 0; y < height; ++y) {
for (u32 x = 0; x < VI.width; ++x) {
- const RGBA & c = ptr_src[x + (height - y - 1)*VI.width];
+ c.raw = ptr_src[x + (height - y - 1)*VI.width];
ptr_dst[(x + y*VI.width)^1] = ((c.r>>3)<<11) | ((c.g>>3)<<6) | ((c.b>>3)<<1) | (c.a == 0 ? 0 : 1);
}
}
@@ -1096,13 +1097,10 @@ void DepthBufferToRDRAM::Destroy() {
bool DepthBufferToRDRAM::CopyToRDRAM( u32 _address) {
if (VI.width == 0) // H width is zero. Don't copy
return false;
- if (m_lastDList == RSP.DList) // Already read;
- return true;
FrameBuffer *pBuffer = frameBufferList().findBuffer(_address);
if (pBuffer == NULL || pBuffer->m_width < VI.width || pBuffer->m_pDepthBuffer == NULL || !pBuffer->m_pDepthBuffer->m_cleared)
return false;
- m_lastDList = RSP.DList;
DepthBuffer * pDepthBuffer = pBuffer->m_pDepthBuffer;
const u32 address = pDepthBuffer->m_address;
if (address + VI.width*VI.height*2 > RDRAMSize)
@@ -243,7 +243,7 @@ void GBIInfo::loadMicrocode(u32 uc_start, u32 uc_dstart, u16 uc_dsize)
// See if we can identify it by text
char uc_data[2048];
- UnswapCopy( &RDRAM[uc_dstart & 0x1FFFFFFF], uc_data, 2048 );
+ UnswapCopyWrap(RDRAM, uc_dstart & 0x1FFFFFFF, (u8*)uc_data, 0, 0x7FF, 2048);
char uc_str[256];
strcpy(uc_str, "Not Found");
@@ -263,7 +263,6 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uFogUsage);
LocateUniform(uAlphaCompareMode);
LocateUniform(uGammaCorrectionEnabled);
- LocateUniform(uEnableLod);
LocateUniform(uEnableAlphaTest);
LocateUniform(uEnableDepth);
LocateUniform(uEnableDepthCompare)
@@ -279,7 +278,6 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uFogAlpha);
LocateUniform(uPrimitiveLod);
- LocateUniform(uMinLod);
LocateUniform(uDeltaZ);
LocateUniform(uAlphaTestValue);
@@ -429,11 +427,9 @@ void ShaderCombiner::updateLOD(bool _bForce)
{
if (usesLOD()) {
int uCalcLOD = (gDP.otherMode.textureLOD == G_TL_LOD) ? 1 : 0;
- m_uniforms.uEnableLod.set(uCalcLOD, _bForce);
if (uCalcLOD) {
m_uniforms.uScreenScale.set(video().getScaleX(), video().getScaleY(), _bForce);
m_uniforms.uPrimitiveLod.set(gDP.primColor.l, _bForce);
- m_uniforms.uMinLod.set(gDP.primColor.m, _bForce);
m_uniforms.uMaxTile.set(gSP.texture.level, _bForce);
}
}
@@ -283,23 +283,13 @@ static const char* fragment_shader_end =
;
static const char* fragment_shader_mipmap =
-"#if (__VERSION__ < 120) \n"
-"#define texture texture2D \n"
-"#endif // __VERSION \n"
"uniform lowp float uPrimitiveLod; \n"
-"uniform lowp int uEnableLod; \n"
-"uniform mediump float uMinLod; \n"
"uniform lowp int uMaxTile; \n"
" \n"
"mediump float mipmap(out lowp vec4 readtex0, out lowp vec4 readtex1) { \n"
-" readtex0 = texture(uTex0, vTexCoord0); \n"
-" readtex1 = texture(uTex1, vTexCoord1); \n"
-" if (uEnableLod == 0) \n"
-" return uPrimitiveLod; \n"
-" if (uMaxTile == 0) { \n"
-" readtex1 = readtex0; \n"
-" return uMinLod; \n"
-" } \n"
+" readtex0 = texture2D(uTex0, vTexCoord0); \n"
+" readtex1 = texture2D(uTex1, vTexCoord1); \n"
+" if (uMaxTile == 0) return 1.0; \n"
" return uPrimitiveLod; \n"
"} \n"
;
@@ -40,4 +40,20 @@ inline void LOG( u16 type, const char * format, ... ) {
#endif
+#ifdef OS_WINDOWS
+#include "windows/GLideN64_Windows.h"
+#include <stdio.h>
+
+inline void debugPrint(const char * format, ...) {
+ char text[256];
+ wchar_t wtext[256];
+ va_list va;
+ va_start(va, format);
+ vsprintf(text, format, va);
+ mbstowcs(wtext, text, 256);
+ OutputDebugString(wtext);
+ va_end(va);
+}
+#endif
+
#endif
@@ -3,7 +3,7 @@
u8 *HEADER;
u8 *DMEM;
u8 *IMEM;
-u64 TMEM[TMEM_SIZE];
+u64 TMEM[512];
u8 *RDRAM;
u32 RDRAMSize;
@@ -5,12 +5,6 @@
#define MI_INTR_DP 0x20 // Bit 5: DP intr
-// Actual TMEM size is 512 QWORDS. However, some load operations load more data that TMEM can take.
-// We can either cut the surplus data, or increase the buffer and load everything.
-// The second option is more simple and safe. Actual texture load will use correct TMEM size.
-#define TMEM_SIZE 1024
-#define TMEM_SIZE_BYTES 8192
-
struct N64Regs
{
u32 *MI_INTR;
@@ -45,7 +39,7 @@ extern u8 *HEADER;
extern u8 *DMEM;
extern u8 *IMEM;
extern u8 *RDRAM;
-extern u64 TMEM[TMEM_SIZE];
+extern u64 TMEM[512];
extern u32 RDRAMSize;
extern bool ConfigOpen;
@@ -1,6 +1,7 @@
#include <assert.h>
#include <stdio.h>
#include <string>
+#include <vector>
#include "../N64.h"
#include "../OpenGL.h"
@@ -35,12 +36,6 @@ GLuint g_tlut_tex = 0;
static u32 g_paletteCRC256 = 0;
#endif // GL_IMAGE_TEXTURES_SUPPORT
-#ifndef GLESX
-#define GL_RED16 GL_R16
-#else
-#define GL_RED16 GL_R16UI
-#endif
-
static std::string strFragmentShader;
class NoiseTexture
@@ -101,9 +96,7 @@ void NoiseTexture::update()
return;
PBOBinder binder(GL_PIXEL_UNPACK_BUFFER, m_PBO);
glBufferData(GL_PIXEL_UNPACK_BUFFER, dataSize, NULL, GL_DYNAMIC_DRAW);
- isGLError();
GLubyte* ptr = (GLubyte*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, dataSize, GL_MAP_WRITE_BIT);
- isGLError();
if (ptr == NULL)
return;
for (u32 y = 0; y < VI.height; ++y) {
@@ -126,25 +119,33 @@ void InitZlutTexture()
if (!video().getRender().isImageTexturesSupported())
return;
+#ifdef GLESX
+ std::vector<u32> vecZLUT(0x40000);
+ const u16 * const zLUT16 = depthBufferList().getZLUT();
+ for (u32 i = 0; i < 0x40000; ++i)
+ vecZLUT[i] = zLUT16[i];
+ const u32 * zLUT = vecZLUT.data();
+#else
const u16 * const zLUT = depthBufferList().getZLUT();
+#endif
glGenTextures(1, &g_zlut_tex);
glBindTexture(GL_TEXTURE_2D, g_zlut_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RED16,
- 512, 512, 0, GL_RED, GL_UNSIGNED_SHORT,
+ glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.lutInternalFormat,
+ 512, 512, 0, fboFormats.lutFormat, fboFormats.lutType,
zLUT);
- glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
+ glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
}
static
void DestroyZlutTexture()
{
if (!video().getRender().isImageTexturesSupported())
return;
- glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
+ glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
if (g_zlut_tex > 0) {
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(1, &g_zlut_tex);
@@ -164,7 +165,7 @@ void InitShadowMapShader()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RED16, 256, 1, 0, GL_RED, GL_UNSIGNED_SHORT, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.lutInternalFormat, 256, 1, 0, fboFormats.lutFormat, fboFormats.lutType, NULL);
g_draw_shadow_map_program = createShaderProgram(default_vertex_shader, shadow_map_fragment_shader_float);
}
@@ -175,7 +176,7 @@ void DestroyShadowMapShader()
if (!video().getRender().isImageTexturesSupported())
return;
- glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
+ glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
if (g_tlut_tex > 0) {
glBindTexture(GL_TEXTURE_2D, 0);
@@ -450,7 +451,6 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uSpecialBlendMode);
LocateUniform(uFogAlpha);
- LocateUniform(uPrimitiveLod);
LocateUniform(uMinLod);
LocateUniform(uDeltaZ);
LocateUniform(uAlphaTestValue);
@@ -625,9 +625,8 @@ void ShaderCombiner::updateLOD(bool _bForce)
m_uniforms.uEnableLod.set(uCalcLOD, _bForce);
if (uCalcLOD) {
m_uniforms.uScreenScale.set(video().getScaleX(), video().getScaleY(), _bForce);
- m_uniforms.uPrimitiveLod.set(gDP.primColor.l, _bForce);
m_uniforms.uMinLod.set(gDP.primColor.m, _bForce);
- m_uniforms.uMaxTile.set(gSP.texture.level, _bForce);
+ m_uniforms.uMaxTile.set(gSP.texture.level - gSP.texture.tile, _bForce);
m_uniforms.uTextureDetail.set(gDP.otherMode.textureDetail, _bForce);
}
}
@@ -730,15 +729,20 @@ void SetDepthFogCombiner()
if (g_paletteCRC256 != gDP.paletteCRC256) {
g_paletteCRC256 = gDP.paletteCRC256;
+
+#ifdef GLESX
+ u32 palette[256];
+#else
u16 palette[256];
+#endif
u16 *src = (u16*)&TMEM[256];
for (int i = 0; i < 256; ++i)
palette[i] = swapword(src[i*4]);
- glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
+ glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
glBindTexture(GL_TEXTURE_2D, g_tlut_tex);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 1, GL_RED, GL_UNSIGNED_SHORT, palette);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 1, fboFormats.lutFormat, fboFormats.lutType, palette);
glBindTexture(GL_TEXTURE_2D, 0);
- glBindImageTexture(TlutImageUnit, g_tlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
+ glBindImageTexture(TlutImageUnit, g_tlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
}
glUseProgram(g_draw_shadow_map_program);
Oops, something went wrong.

0 comments on commit a077a17

Please sign in to comment.