2009-10-05 06:22:28 +02:00
|
|
|
// Copyright (c) 2009, Thomas Goyne
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file video_out_gl.h
|
|
|
|
/// @brief OpenGL based video renderer
|
|
|
|
/// @ingroup video
|
|
|
|
///
|
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
#include <libaegisub/exception.h>
|
2009-10-05 06:22:28 +02:00
|
|
|
|
2009-10-17 05:41:12 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
|
|
|
|
2009-10-05 06:22:28 +02:00
|
|
|
class AegiVideoFrame;
|
|
|
|
|
|
|
|
/// @class VideoOutGL
|
|
|
|
/// @brief OpenGL based video renderer
|
|
|
|
class VideoOutGL {
|
|
|
|
private:
|
2009-12-13 20:27:45 +01:00
|
|
|
struct TextureInfo;
|
|
|
|
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The maximum texture size supported by the user's graphics card
|
|
|
|
int maxTextureSize;
|
|
|
|
/// Whether rectangular textures are supported by the user's graphics card
|
|
|
|
bool supportsRectangularTextures;
|
|
|
|
/// The internalformat to use
|
|
|
|
int internalFormat;
|
2009-10-19 03:11:02 +02:00
|
|
|
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The frame height which the texture grid has been set up for
|
|
|
|
int frameWidth;
|
|
|
|
/// The frame width which the texture grid has been set up for
|
|
|
|
int frameHeight;
|
|
|
|
/// The frame format which the texture grid has been set up for
|
|
|
|
GLenum frameFormat;
|
2009-10-27 21:59:27 +01:00
|
|
|
/// Whether the grid is set up for flipped video
|
|
|
|
bool frameFlipped;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// List of OpenGL texture ids used in the grid
|
2009-10-17 05:41:12 +02:00
|
|
|
std::vector<GLuint> textureIdList;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// List of precalculated texture display information
|
2009-10-17 05:41:12 +02:00
|
|
|
std::vector<TextureInfo> textureList;
|
2010-04-30 05:00:04 +02:00
|
|
|
/// OpenGL display list which draws the frames
|
|
|
|
GLuint dl;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The total texture count
|
|
|
|
int textureCount;
|
|
|
|
/// The number of rows of textures
|
|
|
|
int textureRows;
|
|
|
|
/// The number of columns of textures
|
|
|
|
int textureCols;
|
|
|
|
|
2009-10-19 03:11:02 +02:00
|
|
|
void DetectOpenGLCapabilities();
|
2009-10-27 15:27:39 +01:00
|
|
|
void InitTextures(int width, int height, GLenum format, int bpp, bool flipped);
|
2009-10-05 06:22:28 +02:00
|
|
|
|
|
|
|
VideoOutGL(const VideoOutGL &);
|
|
|
|
VideoOutGL& operator=(const VideoOutGL&);
|
|
|
|
public:
|
2009-10-27 15:27:39 +01:00
|
|
|
/// @brief Set the frame to be displayed when Render() is called
|
2009-10-05 06:22:28 +02:00
|
|
|
/// @param frame The frame to be displayed
|
2009-10-27 15:27:39 +01:00
|
|
|
void UploadFrameData(const AegiVideoFrame& frame);
|
2010-01-24 20:05:20 +01:00
|
|
|
|
2009-10-27 15:27:39 +01:00
|
|
|
/// @brief Render a frame
|
2010-05-16 08:39:11 +02:00
|
|
|
/// @param x Bottom left x coordinate
|
|
|
|
/// @param y Bottom left y coordinate
|
|
|
|
/// @param width Width in pixels of viewport
|
|
|
|
/// @param height Height in pixels of viewport
|
|
|
|
void Render(int x, int y, int width, int height);
|
2009-10-05 06:22:28 +02:00
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
VideoOutGL();
|
|
|
|
/// @brief Destructor
|
|
|
|
~VideoOutGL();
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @class VideoOutException
|
|
|
|
/// @extends Aegisub::Exception
|
|
|
|
/// @brief Base class for all exceptions thrown by VideoOutGL
|
2010-05-21 03:13:36 +02:00
|
|
|
DEFINE_BASE_EXCEPTION_NOINNER(VideoOutException, agi::Exception)
|
2009-10-05 06:22:28 +02:00
|
|
|
|
2009-12-01 01:32:43 +01:00
|
|
|
/// @class VideoOutRenderException
|
2009-10-05 06:22:28 +02:00
|
|
|
/// @extends VideoOutException
|
2009-12-01 01:32:43 +01:00
|
|
|
/// @brief An OpenGL error occured while uploading or displaying a frame
|
|
|
|
class VideoOutRenderException : public VideoOutException {
|
|
|
|
public:
|
2010-05-21 03:13:36 +02:00
|
|
|
VideoOutRenderException(const char *func, int err)
|
2012-12-23 00:18:38 +01:00
|
|
|
: VideoOutException(from_wx(wxString::Format("%s failed with error code %d", func, err)))
|
2009-12-01 01:32:43 +01:00
|
|
|
{ }
|
2010-05-21 03:13:36 +02:00
|
|
|
const char * GetName() const { return "videoout/opengl/render"; }
|
2009-12-01 01:32:43 +01:00
|
|
|
Exception * Copy() const { return new VideoOutRenderException(*this); }
|
|
|
|
};
|
2009-10-05 06:22:28 +02:00
|
|
|
/// @class VideoOutOpenGLException
|
|
|
|
/// @extends VideoOutException
|
2009-12-01 01:32:43 +01:00
|
|
|
/// @brief An OpenGL error occured while setting up the video display
|
|
|
|
class VideoOutInitException : public VideoOutException {
|
2009-10-05 06:22:28 +02:00
|
|
|
public:
|
2010-05-21 03:13:36 +02:00
|
|
|
VideoOutInitException(const char *func, int err)
|
2012-12-23 00:18:38 +01:00
|
|
|
: VideoOutException(from_wx(wxString::Format("%s failed with error code %d", func, err)))
|
2009-10-05 06:22:28 +02:00
|
|
|
{ }
|
2010-05-21 03:13:36 +02:00
|
|
|
VideoOutInitException(const char *err) : VideoOutException(err) { }
|
|
|
|
const char * GetName() const { return "videoout/opengl/init"; }
|
2009-12-01 01:32:43 +01:00
|
|
|
Exception * Copy() const { return new VideoOutInitException(*this); }
|
2009-10-05 06:22:28 +02:00
|
|
|
};
|