1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <sal/config.h>
12 #include <vcl/opengl/OpenGLContext.hxx>
13 #include <vcl/opengl/OpenGLHelper.hxx>
15 #include "opengl/framebuffer.hxx"
16 #include "opengl/texture.hxx"
18 #include "opengl/FixedTextureAtlas.hxx"
20 FixedTextureAtlasManager::FixedTextureAtlasManager(int nWidthFactor
, int nHeightFactor
, int nSubTextureSize
)
21 : mWidthFactor(nWidthFactor
)
22 , mHeightFactor(nHeightFactor
)
23 , mSubTextureSize(nSubTextureSize
)
27 void FixedTextureAtlasManager::CreateNewTexture()
29 int nTextureWidth
= mWidthFactor
* mSubTextureSize
;
30 int nTextureHeight
= mHeightFactor
* mSubTextureSize
;
31 mpTextures
.push_back(std::move(std::unique_ptr
<ImplOpenGLTexture
>(new ImplOpenGLTexture(nTextureWidth
, nTextureHeight
, true))));
32 mpTextures
.back()->InitializeSlots(mWidthFactor
* mHeightFactor
);
35 OpenGLTexture
FixedTextureAtlasManager::InsertBuffer(int nWidth
, int nHeight
, int nFormat
, int nType
, sal_uInt8
* pData
)
37 ImplOpenGLTexture
* pTexture
= nullptr;
39 auto funFreeSlot
= [] (std::unique_ptr
<ImplOpenGLTexture
>& mpTexture
)
41 return mpTexture
->mnFreeSlots
> 0;
44 auto aIterator
= std::find_if(mpTextures
.begin(), mpTextures
.end(), funFreeSlot
);
46 if (aIterator
!= mpTextures
.end())
48 pTexture
= (*aIterator
).get();
53 pTexture
= mpTextures
.back().get();
56 int nSlot
= pTexture
->FindFreeSlot();
58 // Calculate coordinates in texture
59 int nX
= (nSlot
% mWidthFactor
) * mSubTextureSize
;
60 int nY
= (nSlot
/ mWidthFactor
) * mSubTextureSize
;
62 Rectangle
aRectangle(Point(nX
, nY
), Size(nWidth
, nHeight
));
64 // If available, copy the image data to the texture
67 if (!pTexture
->InsertBuffer(nX
, nY
, nWidth
, nHeight
, nFormat
, nType
, pData
))
68 return OpenGLTexture();
71 return OpenGLTexture(pTexture
, aRectangle
, nSlot
);
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */