diff options
Diffstat (limited to 'src/engine/client/graphics.cpp')
| -rw-r--r-- | src/engine/client/graphics.cpp | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 99f5e095..641f9dfb 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -50,7 +50,7 @@ static CVideoMode g_aFakeModes[] = { {1800,1440,8,8,8}, {1856,1392,8,8,8}, {1920,1080,8,8,8}, {1920,1200,8,8,8}, {1920,1440,8,8,8}, {1920,2400,8,8,8}, {2048,1536,8,8,8}, - + {320,240,5,6,5}, {400,300,5,6,5}, {640,480,5,6,5}, {720,400,5,6,5}, {768,576,5,6,5}, {800,600,5,6,5}, {1024,600,5,6,5}, {1024,768,5,6,5}, {1152,864,5,6,5}, @@ -67,7 +67,7 @@ void CGraphics_OpenGL::Flush() { if(m_NumVertices == 0) return; - + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -83,7 +83,7 @@ void CGraphics_OpenGL::Flush() glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - + if(m_RenderEnable) { if(m_Drawing == DRAWING_QUADS) @@ -91,7 +91,7 @@ void CGraphics_OpenGL::Flush() else if(m_Drawing == DRAWING_LINES) glDrawArrays(GL_LINES, 0, m_NumVertices); } - + // Reset pointer m_NumVertices = 0; } @@ -125,26 +125,26 @@ unsigned char CGraphics_OpenGL::Sample(int w, int h, const unsigned char *pData, pData[(v*w+u+1)*4+Offset]+ pData[((v+1)*w+u)*4+Offset]+ pData[((v+1)*w+u+1)*4+Offset])/4; -} +} CGraphics_OpenGL::CGraphics_OpenGL() { m_NumVertices = 0; - + m_ScreenX0 = 0; m_ScreenY0 = 0; m_ScreenX1 = 0; m_ScreenY1 = 0; - + m_ScreenWidth = -1; m_ScreenHeight = -1; - + m_Rotation = 0; m_Drawing = 0; m_InvalidTexture = 0; - + m_TextureMemoryUsage = 0; - + m_RenderEnable = true; m_DoScreenshot = false; } @@ -161,7 +161,7 @@ void CGraphics_OpenGL::ClipDisable() //if(no_gfx) return; glDisable(GL_SCISSOR_TEST); } - + void CGraphics_OpenGL::BlendNone() { glDisable(GL_BLEND); @@ -180,10 +180,10 @@ void CGraphics_OpenGL::BlendAdditive() } int CGraphics_OpenGL::MemoryUsage() const -{ +{ return m_TextureMemoryUsage; -} - +} + void CGraphics_OpenGL::MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY) { m_ScreenX0 = TopLeftX; @@ -220,7 +220,7 @@ void CGraphics_OpenGL::LinesEnd() void CGraphics_OpenGL::LinesDraw(const CLineItem *pArray, int Num) { dbg_assert(m_Drawing == DRAWING_LINES, "called draw without begin"); - + for(int i = 0; i < Num; ++i) { m_aVertices[m_NumVertices + 2*i].m_Pos.x = pArray[i].m_X0; @@ -241,10 +241,10 @@ int CGraphics_OpenGL::UnloadTexture(int Index) { if(Index == m_InvalidTexture) return 0; - + if(Index < 0) return 0; - + glDeleteTextures(1, &m_aTextures[Index].m_Tex); m_aTextures[Index].m_Next = m_FirstFreeTexture; m_TextureMemoryUsage -= m_aTextures[Index].m_MemSize; @@ -261,16 +261,16 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo int Oglformat = 0; int StoreOglformat = 0; int Tex = 0; - + // don't waste memory on texture if we are stress testing if(g_Config.m_DbgStress) return m_InvalidTexture; - + // grab texture Tex = m_FirstFreeTexture; m_FirstFreeTexture = m_aTextures[Tex].m_Next; m_aTextures[Tex].m_Next = -1; - + // resample if needed if(!(Flags&TEXLOAD_NORESAMPLE) && g_Config.m_GfxTextureQuality==0) { @@ -296,13 +296,13 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo pTexData = pTmpData; } } - + Oglformat = GL_RGBA; if(Format == CImageInfo::FORMAT_RGB) Oglformat = GL_RGB; else if(Format == CImageInfo::FORMAT_ALPHA) Oglformat = GL_ALPHA; - + // upload texture if(g_Config.m_GfxTextureCompression) { @@ -320,13 +320,13 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo else if(StoreFormat == CImageInfo::FORMAT_ALPHA) StoreOglformat = GL_ALPHA; } - + glGenTextures(1, &m_aTextures[Tex].m_Tex); glBindTexture(GL_TEXTURE_2D, m_aTextures[Tex].m_Tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pTexData); - + // calculate memory usage { int PixelSize = 4; @@ -346,7 +346,7 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo } } } - + m_TextureMemoryUsage += m_aTextures[Tex].m_MemSize; mem_free(pTmpData); return Tex; @@ -358,7 +358,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int St int l = str_length(pFilename); int ID; CImageInfo Img; - + if(l < 3) return -1; if(LoadPNG(&Img, pFilename, StorageType)) @@ -370,7 +370,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int St mem_free(Img.m_pData); return ID; } - + return m_InvalidTexture; } @@ -379,7 +379,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora char aCompleteFilename[512]; unsigned char *pBuffer; png_t Png; // ignore_convention - + // open file for reading png_init(0,0); // ignore_convention @@ -391,7 +391,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora dbg_msg("game/png", "failed to open file. filename='%s'", pFilename); return 0; } - + int Error = png_open_file(&Png, aCompleteFilename); // ignore_convention if(Error != PNG_NO_ERROR) { @@ -400,18 +400,18 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora png_close_file(&Png); // ignore_convention return 0; } - + if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA)) // ignore_convention { dbg_msg("game/png", "invalid format. filename='%s'", aCompleteFilename); png_close_file(&Png); // ignore_convention return 0; } - + pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp, 1); // ignore_convention png_get_data(&Png, pBuffer); // ignore_convention png_close_file(&Png); // ignore_convention - + pImg->m_Width = Png.width; // ignore_convention pImg->m_Height = Png.height; // ignore_convention if(Png.color_type == PNG_TRUECOLOR) // ignore_convention @@ -435,7 +435,7 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename) glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0,0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData); glPixelStorei(GL_PACK_ALIGNMENT, Alignment); - + // flip the pixel because opengl works from bottom left corner for(y = 0; y < h/2; y++) { @@ -443,16 +443,16 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename) mem_copy(pPixelData+y*w*3, pPixelData+(h-y-1)*w*3, w*3); mem_copy(pPixelData+(h-y-1)*w*3, pTempRow,w*3); } - + // find filename { char aWholePath[1024]; png_t Png; // ignore_convention - IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath)); + IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath)); if(File) io_close(File); - + // save png char aBuf[256]; str_format(aBuf, sizeof(aBuf), "saved screenshot to '%s'", aWholePath); @@ -490,7 +490,7 @@ void CGraphics_OpenGL::QuadsBegin() { dbg_assert(m_Drawing == 0, "called quads_begin twice"); m_Drawing = DRAWING_QUADS; - + QuadsSetSubset(0,0,1,1); QuadsSetRotation(0); SetColor(1,1,1,1); @@ -609,7 +609,7 @@ void CGraphics_OpenGL::QuadsDrawTL(const CQuadItem *pArray, int Num) void CGraphics_OpenGL::QuadsDrawFreeform(const CFreeformItem *pArray, int Num) { dbg_assert(m_Drawing == DRAWING_QUADS, "called quads_draw_freeform without begin"); - + for(int i = 0; i < Num; ++i) { m_aVertices[m_NumVertices + 4*i].m_Pos.x = pArray[i].m_X0; @@ -632,7 +632,7 @@ void CGraphics_OpenGL::QuadsDrawFreeform(const CFreeformItem *pArray, int Num) m_aVertices[m_NumVertices + 4*i + 3].m_Tex = m_aTexture[2]; m_aVertices[m_NumVertices + 4*i + 3].m_Color = m_aColor[2]; } - + AddVertices(4*Num); } @@ -647,7 +647,7 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, { char c = *pText; pText++; - + if(c == '\n') { x = StartX; @@ -660,13 +660,13 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, (c/16)/16.0f, (c%16)/16.0f+1.0f/16.0f, (c/16)/16.0f+1.0f/16.0f); - + CQuadItem QuadItem(x, y, Size, Size); QuadsDrawTL(&QuadItem, 1); x += Size/2; } } - + QuadsEnd(); } @@ -674,7 +674,7 @@ bool CGraphics_OpenGL::Init() { m_pStorage = Kernel()->RequestInterface<IStorage>(); m_pConsole = Kernel()->RequestInterface<IConsole>(); - + // Set all z to -5.0f for(int i = 0; i < MAX_VERTICES; i++) m_aVertices[i].m_Pos.z = -5.0f; @@ -691,21 +691,21 @@ bool CGraphics_OpenGL::Init() glDisable(GL_DEPTH_TEST); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - + glAlphaFunc(GL_GREATER, 0); glEnable(GL_ALPHA_TEST); glDepthMask(0); // create null texture, will get id=0 static const unsigned char aNullTextureData[] = { - 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, - 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, - 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, - 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, + 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, + 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, + 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, + 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, }; - + m_InvalidTexture = LoadTextureRaw(4,4,CImageInfo::FORMAT_RGBA,aNullTextureData,CImageInfo::FORMAT_RGBA,TEXLOAD_NORESAMPLE); - + return true; } @@ -713,7 +713,7 @@ int CGraphics_SDL::TryInit() { const SDL_VideoInfo *pInfo; int Flags = SDL_OPENGL; - + m_ScreenWidth = g_Config.m_GfxScreenWidth; m_ScreenHeight = g_Config.m_GfxScreenHeight; @@ -721,7 +721,7 @@ int CGraphics_SDL::TryInit() SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // set flags - Flags = SDL_OPENGL; + Flags = SDL_OPENGL; Flags |= SDL_GL_DOUBLEBUFFER; Flags |= SDL_HWPALETTE; if(g_Config.m_DbgResizable) @@ -755,7 +755,7 @@ int CGraphics_SDL::TryInit() // set caption SDL_WM_SetCaption("Teeworlds", "Teeworlds"); - + // create window m_pScreenSurface = SDL_SetVideoMode(m_ScreenWidth, m_ScreenHeight, 0, Flags); if(m_pScreenSurface == NULL) @@ -763,7 +763,7 @@ int CGraphics_SDL::TryInit() dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError()); return -1; } - + return 0; } @@ -772,12 +772,12 @@ int CGraphics_SDL::InitWindow() { if(TryInit() == 0) return 0; - + // try disabling fsaa while(g_Config.m_GfxFsaaSamples) { g_Config.m_GfxFsaaSamples--; - + if(g_Config.m_GfxFsaaSamples) dbg_msg("gfx", "lowering FSAA to %d and trying again", g_Config.m_GfxFsaaSamples); else @@ -799,8 +799,8 @@ int CGraphics_SDL::InitWindow() } dbg_msg("gfx", "out of ideas. failed to init graphics"); - - return -1; + + return -1; } @@ -813,34 +813,34 @@ bool CGraphics_SDL::Init() { { int Systems = SDL_INIT_VIDEO; - + if(g_Config.m_SndEnable) Systems |= SDL_INIT_AUDIO; if(g_Config.m_ClEventthread) Systems |= SDL_INIT_EVENTTHREAD; - + if(SDL_Init(Systems) < 0) { dbg_msg("gfx", "unable to init SDL: %s", SDL_GetError()); return true; } } - + atexit(SDL_Quit); // ignore_convention #ifdef CONF_FAMILY_WINDOWS if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) // ignore_convention putenv("SDL_VIDEO_WINDOW_POS=8,27"); // ignore_convention #endif - + if(InitWindow() != 0) return true; SDL_ShowCursor(0); - + CGraphics_OpenGL::Init(); - + MapScreen(0,0,g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight); return false; } @@ -887,11 +887,11 @@ void CGraphics_SDL::Swap() ScreenshotDirect(m_aScreenshotName); m_DoScreenshot = false; } - + SDL_GL_SwapBuffers(); - + if(g_Config.m_GfxFinish) - glFinish(); + glFinish(); } @@ -908,9 +908,9 @@ int CGraphics_SDL::GetVideoModes(CVideoMode *pModes, int MaxModes) Count = MaxModes; return Count; } - + // TODO: fix this code on osx or windows - + ppModes = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN); if(ppModes == NULL) { @@ -936,7 +936,7 @@ int CGraphics_SDL::GetVideoModes(CVideoMode *pModes, int MaxModes) NumModes++; } } - + return NumModes; } |