annotate trunk/src/Modules/Output/Graphics/Devices/GraphicsOutputDevice.h @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents b6d5c0cc1849
children
rev   line source
tomwalters@411 1 // Copyright 2006-2010, Willem van Engen, Thomas Walters
tomwalters@397 2 //
tomwalters@397 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@397 4 // http://www.acousticscale.org/AIMC
tomwalters@397 5 //
tomwalters@397 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@397 7 // you may not use this file except in compliance with the License.
tomwalters@397 8 // You may obtain a copy of the License at
tomwalters@397 9 //
tomwalters@397 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@397 11 //
tomwalters@397 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@397 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@397 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@397 15 // See the License for the specific language governing permissions and
tomwalters@397 16 // limitations under the License.
tomwalters@397 17
tomwalters@397 18 #ifndef __GRAPHICS_OUTPUT_DEVICE_H__
tomwalters@397 19 #define __GRAPHICS_OUTPUT_DEVICE_H__
tomwalters@397 20
tomwalters@397 21 #include "Support/Parameters.h"
tomwalters@397 22
tom@399 23 namespace aimc {
tom@399 24
tomwalters@397 25 /*!
tomwalters@397 26 * \class GraphicsOutputDevice "Output/GraphicsOutputDevice.h"
tomwalters@397 27 * \brief General output device class
tomwalters@397 28 *
tomwalters@397 29 * This class provides basic drawing primitives in a device-independent manner.
tomwalters@397 30 * It is structured like the OpenGL interface. Following is an example drawing
tomwalters@397 31 * five horizontal lines, with the colour changing between red and blue over
tomwalters@397 32 * time.
tomwalters@397 33 * \code
tomwalters@397 34 * GraphicsOutputDevice oOutput = static_cast<GraphicsOutputDevice>(new GraphicsOutputDeviceSomething());
tomwalters@397 35 * unsigned int a=0;
tomwalters@397 36 * ...
tomwalters@397 37 * oOutput->Start();
tomwalters@397 38 * while ( bIsRunning ) {
tomwalters@398 39 * // Start a drawing operation
tomwalters@398 40 * oOutput->gGrab();
tomwalters@398 41 * // Draw five horizontal lines
tomwalters@398 42 * for (int y=0; y<5; y++) {
tomwalters@398 43 * // Start a new line
tomwalters@398 44 * oOutput->gBegin();
tomwalters@398 45 * // Give each line it's own colour
tomwalters@398 46 * oOutput->gColor3f( (a%255)/255, 0, 1-(a%255)/255 );
tomwalters@398 47 * // Draw the line
tomwalters@398 48 * oOutput->gVertex2f(0, y);
tomwalters@398 49 * oOutput->gVertex2f(1, y);
tomwalters@398 50 * // End the line
tomwalters@398 51 * oOutput->gEnd();
tomwalters@398 52 * }
tomwalters@398 53 * oOutput->gRelease();
tomwalters@398 54 * Sleep(1);
tomwalters@398 55 * a++;
tomwalters@397 56 * }
tomwalters@397 57 * oOutput->Stop();
tomwalters@397 58 * \endcode
tomwalters@397 59 *
tomwalters@397 60 * This class includes some basic overloading definitions to ease the
tomwalters@397 61 * children's implementation. Note that the basic operations that need
tomwalters@397 62 * implementation are glVertex3f(x,y,z) and glColor(r,g,b).
tomwalters@397 63 */
tomwalters@397 64 class GraphicsOutputDevice {
tomwalters@397 65 public:
tom@399 66 GraphicsOutputDevice(Parameters *pParam);
tomwalters@398 67 virtual ~GraphicsOutputDevice() { };
tomwalters@397 68
tomwalters@398 69 /*! \brief Initialize the module, sets up everything to Start().
tomwalters@398 70 * \return true on success, false on error
tomwalters@398 71 *
tomwalters@398 72 * Initialize() needs to be called before any other function.
tomwalters@398 73 *
tomwalters@398 74 * This method is called in it's form as displayed here by the GraphicsView,
tomwalters@398 75 * but you may want to setup your own Initialize(...) function with
tomwalters@398 76 * different arguments and call it yourself.
tomwalters@398 77 *
tomwalters@398 78 * Thus make sure you do all memory allocations here. They can be cleaned
tomwalters@398 79 * up by the destructor. Because Initialize() may fail, it's not put in
tomwalters@398 80 * the constructor, so it can return a value.
tomwalters@398 81 *
tomwalters@398 82 * \sa Module::Initialize()
tomwalters@398 83 */
tomwalters@411 84
tomwalters@398 85 /*! \overload
tomwalters@398 86 * This function reloads the parameters; make sure to have at least the
tomwalters@398 87 * function with maximum parameters called once.
tomwalters@398 88 */
tomwalters@411 89 virtual bool Initialize(Parameters *global_parameters) {
tomwalters@411 90 global_parameters_ = global_parameters;
tomwalters@411 91 return true;
tomwalters@411 92 };
tomwalters@397 93
tomwalters@398 94 /*! \brief Create a new drawing
tomwalters@398 95 * Run this before any other drawing command.
tomwalters@398 96 * \sa glRelease()
tomwalters@398 97 */
tomwalters@398 98 virtual void gGrab() = 0;
tomwalters@397 99
tomwalters@398 100 //! \brief Start a new vertex group for drawing a line strip
tomwalters@397 101 virtual void gBeginLineStrip() = 0;
tomwalters@397 102 //! \brief Start a new vertex group for drawing a quad strip
tomwalters@397 103 virtual void gBeginQuadStrip() = 0;
tomwalters@397 104
tomwalters@398 105 /*! \brief Specify a vertex to draw
tomwalters@398 106 * \param[in] x X-coordinate of the vertex
tomwalters@398 107 * \param[in] y Y-coordinate of the vertex
tomwalters@398 108 * \param[in] z Z-coordinate of the vertex
tomwalters@398 109 * \param[in] r Red component of colour
tomwalters@398 110 * \param[in] g Green component of colour
tomwalters@398 111 * \param[in] b Blue component of colour
tomwalters@398 112 *
tomwalters@398 113 * Currently, only lines are implemented.
tomwalters@398 114 */
tomwalters@397 115 virtual void gVertex3f(float x, float y, float z, float r, float g, float b);
tomwalters@397 116
tomwalters@398 117 /*! \overload
tomwalters@398 118 * This will add a vertex with the last specified colour.
tomwalters@398 119 */
tomwalters@397 120
tomwalters@398 121 virtual void gVertex3f(float x, float y, float z) = 0;
tomwalters@398 122 /*! \overload
tomwalters@398 123 * This will add a vertex in the 2d-plane with z=0.
tomwalters@398 124 */
tomwalters@397 125
tomwalters@398 126 virtual void gVertex2f(float x, float y, float r, float g, float b);
tomwalters@397 127
tomwalters@398 128 /*! \overload
tomwalters@398 129 * This will add a vertex in the 2d-plane with z=0 with the last
tomwalters@397 130 * specified colour.
tomwalters@398 131 */
tomwalters@398 132 virtual void gVertex2f(float x, float y);
tomwalters@397 133
tomwalters@398 134 /*! \brief Sets the current colour
tomwalters@398 135 * \param[in] r Red component
tomwalters@398 136 * \param[in] g Green component
tomwalters@398 137 * \param[in] b Blue component
tomwalters@398 138 */
tomwalters@398 139 virtual void gColor3f(float r, float g, float b) = 0;
tomwalters@397 140
tomwalters@398 141 //! \brief End a vertex group
tomwalters@397 142 virtual void gEnd() = 0;
tomwalters@397 143
tomwalters@398 144 /*! \brief Render a text string
tomwalters@398 145 * \param[in] x X-coordinate of the text's alignment point
tomwalters@398 146 * \param[in] y Y-coordinate of the text's alignment point
tomwalters@398 147 * \param[in] z Z-coordinate of the text's alignment point
tomwalters@398 148 * \param[in] sStr Text to render
tomwalters@398 149 * \param[in] bRotated \c true for vertically rotated text
tomwalters@398 150 *
tomwalters@398 151 * Current alignment is horizontal:left and vertical:bottom
tomwalters@398 152 * \todo Allow multiple alignment points
tomwalters@398 153 */
tomwalters@398 154 virtual void gText3f(float x,
tomwalters@397 155 float y,
tomwalters@397 156 float z,
tomwalters@397 157 const char *sStr,
tomwalters@397 158 bool bRotated = false) = 0;
tomwalters@397 159
tomwalters@398 160 /*! \overload
tomwalters@398 161 * This will render a text string in the 2d-plane with z=0.
tomwalters@398 162 */
tomwalters@398 163 virtual void gText2f(float x,
tomwalters@397 164 float y,
tomwalters@397 165 const char *sStr,
tomwalters@397 166 bool bRight = false);
tomwalters@397 167
tomwalters@398 168 /*! \brief Finish drawing
tomwalters@398 169 * Call this when a drawing is finished. It also makes sure that the
tomwalters@398 170 * rendering is actually done.
tomwalters@398 171 * \sa glGrab()
tomwalters@398 172 */
tomwalters@398 173 virtual void gRelease() = 0;
tomwalters@397 174
tomwalters@398 175 /*! \brief Called when animation starts
tomwalters@398 176 *
tomwalters@398 177 * You may wonder what Start() and Stop() do here. Some implementations
tomwalters@398 178 * may want to behave differently with respect to updating, if an
tomwalters@398 179 * animation is running or not (e.g. updating).
tomwalters@398 180 */
tomwalters@398 181 virtual void Start() { m_bRunning = true; }
tomwalters@397 182
tomwalters@398 183 //! \brief Called when animation stops
tomwalters@398 184 virtual void Stop() { m_bRunning = false; }
tomwalters@418 185
tomwalters@418 186 virtual void Reset(Parameters* global_parameters) = 0;
tomwalters@418 187
tomwalters@397 188
tomwalters@397 189 protected:
tomwalters@398 190 //! \brief True when animation is running
tomwalters@398 191 bool m_bRunning;
tomwalters@398 192 //! \brief Parameter store
tomwalters@411 193 Parameters *parameters_;
tomwalters@411 194 Parameters *global_parameters_;
tomwalters@397 195
tomwalters@398 196 //! \brief Pixel Formats
tomwalters@398 197 enum PixelFormat {AIM_PIX_FMT_RGB24_32, AIM_PIX_FMT_RGB24_24};
tomwalters@397 198 };
tom@399 199 } // namespace aimc
tomwalters@397 200 #endif /* __GRAPHICS_OUTPUT_DEVICE__ */