mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Fixed crash when decompressing DDS texture.
This commit is contained in:
parent
1e458f4332
commit
d30a5240d7
2 changed files with 25 additions and 29 deletions
|
@ -10,12 +10,6 @@
|
|||
# include <Cocoa/Cocoa.h>
|
||||
# include <bx/os.h>
|
||||
|
||||
static void* NSGLGetProcAddress (const char* name) {
|
||||
static void* dylib =
|
||||
bx::dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
|
||||
return dylib ? bx::dlsym(dylib, name) : NULL;
|
||||
}
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
|
||||
|
@ -23,8 +17,13 @@ namespace bgfx
|
|||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
|
||||
static void* s_opengl = NULL;
|
||||
|
||||
void GlContext::create(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
s_opengl = bx::dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
|
||||
BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!");
|
||||
|
||||
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
|
||||
|
||||
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
|
||||
|
@ -33,28 +32,21 @@ namespace bgfx
|
|||
NSOpenGLPFAAlphaSize, 8,
|
||||
NSOpenGLPFADepthSize, 24,
|
||||
NSOpenGLPFAStencilSize, 8,
|
||||
NSOpenGLPFADoubleBuffer ,
|
||||
NSOpenGLPFAAccelerated ,
|
||||
NSOpenGLPFANoRecovery ,
|
||||
0
|
||||
NSOpenGLPFADoubleBuffer, true,
|
||||
NSOpenGLPFAAccelerated, true,
|
||||
NSOpenGLPFANoRecovery, true,
|
||||
0, 0,
|
||||
};
|
||||
|
||||
NSOpenGLPixelFormat* pixelFormat =
|
||||
[[NSOpenGLPixelFormat alloc]
|
||||
initWithAttributes:pixelFormatAttributes];
|
||||
|
||||
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
|
||||
NSRect glViewRect = [[nsWindow contentView] bounds];
|
||||
|
||||
NSOpenGLView* glView =
|
||||
[[NSOpenGLView alloc]
|
||||
initWithFrame:glViewRect
|
||||
pixelFormat:pixelFormat];
|
||||
NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat];
|
||||
|
||||
[pixelFormat release];
|
||||
|
||||
[nsWindow setContentView:glView];
|
||||
|
||||
NSOpenGLContext* glContext = [glView openGLContext];
|
||||
|
||||
[glContext makeCurrentContext];
|
||||
|
||||
m_view = glView;
|
||||
|
@ -69,6 +61,8 @@ namespace bgfx
|
|||
m_view = 0;
|
||||
m_context = 0;
|
||||
[glView release];
|
||||
|
||||
bx::dlclose(s_opengl);
|
||||
}
|
||||
|
||||
void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync)
|
||||
|
@ -86,7 +80,7 @@ namespace bgfx
|
|||
{
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)NSGLGetProcAddress(#_func); \
|
||||
_func = (_proto)bx::dlsym(s_opengl, #_func); \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. NSGLGetProcAddress(\"%s\")", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
|
|
|
@ -1380,6 +1380,7 @@ namespace bgfx
|
|||
{
|
||||
uint8_t textureFormat = dds.m_type;
|
||||
bool decompress = TextureFormat::Unknown > textureFormat;
|
||||
uint32_t bpp = tfi.m_bpp;
|
||||
|
||||
if (decompress)
|
||||
{
|
||||
|
@ -1388,6 +1389,7 @@ namespace bgfx
|
|||
internalFmt = tfi.m_internalFmt;
|
||||
m_fmt = tfi.m_fmt;
|
||||
m_type = tfi.m_type;
|
||||
bpp = tfi.m_bpp;
|
||||
}
|
||||
|
||||
bool swizzle = GL_RGBA == m_fmt;
|
||||
|
@ -1402,7 +1404,7 @@ namespace bgfx
|
|||
}
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||
|
||||
uint8_t* bits = (uint8_t*)g_realloc(NULL, dds.m_width*dds.m_height*tfi.m_bpp/8);
|
||||
uint8_t* bits = (uint8_t*)g_realloc(NULL, dds.m_width*dds.m_height*bpp/8);
|
||||
|
||||
for (uint8_t side = 0, numSides = dds.m_cubeMap ? 6 : 1; side < numSides; ++side)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue