2013-07-01 05:15:43 +02:00
|
|
|
// Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
|
2009-10-05 06:22:28 +02:00
|
|
|
//
|
2013-07-01 05:15:43 +02:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2009-10-05 06:22:28 +02:00
|
|
|
//
|
2013-07-01 05:15:43 +02:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2009-10-05 06:22:28 +02:00
|
|
|
//
|
|
|
|
// 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>
|
|
|
|
|
2013-07-01 05:15:43 +02:00
|
|
|
struct VideoFrame;
|
2009-10-05 06:22:28 +02:00
|
|
|
|
|
|
|
/// @class VideoOutGL
|
|
|
|
/// @brief OpenGL based video renderer
|
|
|
|
class VideoOutGL {
|
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
|
2013-12-12 01:29:48 +01:00
|
|
|
int maxTextureSize = 0;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// Whether rectangular textures are supported by the user's graphics card
|
2013-12-12 01:29:48 +01:00
|
|
|
bool supportsRectangularTextures = false;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The internalformat to use
|
2013-12-12 01:29:48 +01:00
|
|
|
int internalFormat = 0;
|
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
|
2013-12-12 01:29:48 +01:00
|
|
|
int frameWidth = 0;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The frame width which the texture grid has been set up for
|
2013-12-12 01:29:48 +01:00
|
|
|
int frameHeight = 0;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The frame format which the texture grid has been set up for
|
2013-12-12 01:29:48 +01:00
|
|
|
GLenum frameFormat = 0;
|
2009-10-27 21:59:27 +01:00
|
|
|
/// Whether the grid is set up for flipped video
|
2013-12-12 01:29:48 +01:00
|
|
|
bool frameFlipped = false;
|
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
|
2013-12-12 01:29:48 +01:00
|
|
|
GLuint dl = 0;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The total texture count
|
2013-12-12 01:29:48 +01:00
|
|
|
int textureCount = 0;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The number of rows of textures
|
2013-12-12 01:29:48 +01:00
|
|
|
int textureRows = 0;
|
2009-10-05 06:22:28 +02:00
|
|
|
/// The number of columns of textures
|
2013-12-12 01:29:48 +01:00
|
|
|
int textureCols = 0;
|
2009-10-05 06:22:28 +02:00
|
|
|
|
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
|
|
|
|
2013-12-12 01:29:48 +01:00
|
|
|
VideoOutGL(const VideoOutGL &) = delete;
|
|
|
|
VideoOutGL& operator=(const VideoOutGL&) = delete;
|
2009-10-05 06:22:28 +02:00
|
|
|
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
|
2013-07-01 05:15:43 +02:00
|
|
|
void UploadFrameData(VideoFrame const& 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
|
2013-01-04 16:01:50 +01:00
|
|
|
/// @brief An OpenGL error occurred while uploading or displaying a frame
|
2009-12-01 01:32:43 +01:00
|
|
|
class VideoOutRenderException : public VideoOutException {
|
|
|
|
public:
|
2010-05-21 03:13:36 +02:00
|
|
|
VideoOutRenderException(const char *func, int err)
|
2013-01-04 16:01:50 +01:00
|
|
|
: VideoOutException(std::string(func) + " failed with error code " + std::to_string(err))
|
2009-12-01 01:32:43 +01:00
|
|
|
{ }
|
2013-11-21 18:13:36 +01:00
|
|
|
const char * GetName() const override { return "videoout/opengl/render"; }
|
|
|
|
Exception * Copy() const override { return new VideoOutRenderException(*this); }
|
2009-12-01 01:32:43 +01:00
|
|
|
};
|
2009-10-05 06:22:28 +02:00
|
|
|
/// @class VideoOutOpenGLException
|
|
|
|
/// @extends VideoOutException
|
2013-01-04 16:01:50 +01:00
|
|
|
/// @brief An OpenGL error occurred while setting up the video display
|
2009-12-01 01:32:43 +01:00
|
|
|
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)
|
2013-01-04 16:01:50 +01:00
|
|
|
: VideoOutException(std::string(func) + " failed with error code " + std::to_string(err))
|
2009-10-05 06:22:28 +02:00
|
|
|
{ }
|
2010-05-21 03:13:36 +02:00
|
|
|
VideoOutInitException(const char *err) : VideoOutException(err) { }
|
2013-11-21 18:13:36 +01:00
|
|
|
const char * GetName() const override { return "videoout/opengl/init"; }
|
|
|
|
Exception * Copy() const override { return new VideoOutInitException(*this); }
|
2009-10-05 06:22:28 +02:00
|
|
|
};
|