summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBret Curtis <psi29a@gmail.com>2022-08-09 21:49:28 +0200
committerBret Curtis <psi29a@gmail.com>2022-08-09 21:49:28 +0200
commit1ebc6fa13e9801eb9901e79ca238fc1fdb5776d8 (patch)
treead2e5e1c12ccdd4bbf1a0c21cdfca4933ff6aec2
parent3fd87a219d76fded51ea0a61ce13667c1613047b (diff)
go from softwareDecompress to decompresscleanup
-rw-r--r--components/sdlutil/sdlcursormanager.cpp151
1 files changed, 46 insertions, 105 deletions
diff --git a/components/sdlutil/sdlcursormanager.cpp b/components/sdlutil/sdlcursormanager.cpp
index dc8a6dbeda..6a67119ad8 100644
--- a/components/sdlutil/sdlcursormanager.cpp
+++ b/components/sdlutil/sdlcursormanager.cpp
@@ -24,110 +24,6 @@
USE_GRAPHICSWINDOW()
#endif
-namespace CursorDecompression
-{
- class MyGraphicsContext {
- public:
- MyGraphicsContext(int w, int h)
- {
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- traits->x = 0;
- traits->y = 0;
- traits->width = w;
- traits->height = h;
- traits->red = 8;
- traits->green = 8;
- traits->blue = 8;
- traits->alpha = 8;
- traits->windowDecoration = false;
- traits->doubleBuffer = false;
- traits->sharedContext = nullptr;
- traits->pbuffer = true;
-
- osg::GraphicsContext::ScreenIdentifier si;
- si.readDISPLAY();
- if (si.displayNum<0) si.displayNum = 0;
- traits->displayNum = si.displayNum;
- traits->screenNum = si.screenNum;
- traits->hostName = si.hostName;
-
- _gc = osg::GraphicsContext::createGraphicsContext(traits.get());
-
- if (!_gc)
- {
- Log(Debug::Warning) << "Failed to create pbuffer, failing back to normal graphics window.";
-
- traits->pbuffer = false;
- _gc = osg::GraphicsContext::createGraphicsContext(traits.get());
- if (!_gc)
- throw std::runtime_error("Failed to create graphics context for image decompression");
- }
-
- if (_gc.valid())
- {
- _gc->realize();
- _gc->makeCurrent();
- }
- }
-
- osg::ref_ptr<osg::GraphicsContext> getContext()
- {
- return _gc;
- }
-
- bool valid() const { return _gc.valid() && _gc->isRealized(); }
-
- private:
- osg::ref_ptr<osg::GraphicsContext> _gc;
- };
-
- SDLUtil::SurfaceUniquePtr softwareDecompress (osg::ref_ptr<osg::Image> source, float rotDegrees)
- {
- int width = source->s();
- int height = source->t();
- bool useAlpha = source->isImageTranslucent();
-
- osg::ref_ptr<osg::Image> decompressedImage = new osg::Image;
- decompressedImage->setFileName(source->getFileName());
- decompressedImage->allocateImage(width, height, 1, useAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE);
- for (int s=0; s<width; ++s)
- for (int t=0; t<height; ++t)
- decompressedImage->setColor(source->getColor(s,t,0), s,t,0);
-
- Uint32 redMask = 0x000000ff;
- Uint32 greenMask = 0x0000ff00;
- Uint32 blueMask = 0x00ff0000;
- Uint32 alphaMask = useAlpha ? 0xff000000 : 0;
-
- SDL_Surface *cursorSurface = SDL_CreateRGBSurfaceFrom(decompressedImage->data(),
- width,
- height,
- decompressedImage->getPixelSizeInBits(),
- decompressedImage->getRowSizeInBytes(),
- redMask,
- greenMask,
- blueMask,
- alphaMask);
-
- SDL_Surface *targetSurface = SDL_CreateRGBSurface(0, width, height, 32, redMask, greenMask, blueMask, alphaMask);
- SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(targetSurface);
-
- SDL_RenderClear(renderer);
-
- SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
- SDL_Texture *cursorTexture = SDL_CreateTextureFromSurface(renderer, cursorSurface);
-
- SDL_RenderCopyEx(renderer, cursorTexture, nullptr, nullptr, -rotDegrees, nullptr, SDL_FLIP_VERTICAL);
-
- SDL_DestroyTexture(cursorTexture);
- SDL_FreeSurface(cursorSurface);
- SDL_DestroyRenderer(renderer);
-
- return SDLUtil::SurfaceUniquePtr(targetSurface, SDL_FreeSurface);
- }
-
-}
-
namespace SDLUtil
{
@@ -190,13 +86,58 @@ namespace SDLUtil
#endif
}
+ SDLUtil::SurfaceUniquePtr decompress(osg::ref_ptr<osg::Image> source, float rotDegrees)
+ {
+ int width = source->s();
+ int height = source->t();
+ bool useAlpha = source->isImageTranslucent();
+
+ osg::ref_ptr<osg::Image> decompressedImage = new osg::Image;
+ decompressedImage->setFileName(source->getFileName());
+ decompressedImage->allocateImage(width, height, 1, useAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE);
+ for (int s=0; s<width; ++s)
+ for (int t=0; t<height; ++t)
+ decompressedImage->setColor(source->getColor(s,t,0), s,t,0);
+
+ Uint32 redMask = 0x000000ff;
+ Uint32 greenMask = 0x0000ff00;
+ Uint32 blueMask = 0x00ff0000;
+ Uint32 alphaMask = useAlpha ? 0xff000000 : 0;
+
+ SDL_Surface *cursorSurface = SDL_CreateRGBSurfaceFrom(decompressedImage->data(),
+ width,
+ height,
+ decompressedImage->getPixelSizeInBits(),
+ decompressedImage->getRowSizeInBytes(),
+ redMask,
+ greenMask,
+ blueMask,
+ alphaMask);
+
+ SDL_Surface *targetSurface = SDL_CreateRGBSurface(0, width, height, 32, redMask, greenMask, blueMask, alphaMask);
+ SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(targetSurface);
+
+ SDL_RenderClear(renderer);
+
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
+ SDL_Texture *cursorTexture = SDL_CreateTextureFromSurface(renderer, cursorSurface);
+
+ SDL_RenderCopyEx(renderer, cursorTexture, nullptr, nullptr, -rotDegrees, nullptr, SDL_FLIP_VERTICAL);
+
+ SDL_DestroyTexture(cursorTexture);
+ SDL_FreeSurface(cursorSurface);
+ SDL_DestroyRenderer(renderer);
+
+ return SDLUtil::SurfaceUniquePtr(targetSurface, SDL_FreeSurface);
+ }
+
void SDLCursorManager::_createCursorFromResource(const std::string& name, int rotDegrees, osg::Image* image, Uint8 hotspot_x, Uint8 hotspot_y)
{
if (mCursorMap.find(name) != mCursorMap.end())
return;
try {
- auto surface = CursorDecompression::softwareDecompress(image, static_cast<float>(rotDegrees));
+ auto surface = decompress(image, static_cast<float>(rotDegrees));
//set the cursor and store it for later
SDL_Cursor* curs = SDL_CreateColorCursor(surface.get(), hotspot_x, hotspot_y);