Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfRenderTarget.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include "glfRenderTarget.hh"
26 #include "glfException.hh"
27 
28 using namespace BIAS;
29 using namespace std;
30 
31 void glfRenderTarget::ClearColorBuffer(float red, float green, float blue, float alpha)
32 {
33  Bind();
34  glClearColor(red, green, blue, alpha);
35  // cout<<"Clear with :"<<red<<","<<green<<","<<blue<<","<<alpha<<endl<<flush;
36  glClear(GL_COLOR_BUFFER_BIT);
37 
38  GLF_THROW_ON_OPENGL_ERROR;
39 }
40 
42 {
43  Bind();
44  glClearDepth(depth);
45  glClear(GL_DEPTH_BUFFER_BIT);
46 
47  GLF_THROW_ON_OPENGL_ERROR;
48 }
49 
50 void glfRenderTarget::ClearAccumBuffer(float red, float green, float blue, float alpha)
51 {
52  Bind();
53  glClearAccum(red, green, blue, alpha);
54  glClear(GL_ACCUM_BUFFER_BIT);
55 
56  GLF_THROW_ON_OPENGL_ERROR;
57 }
58 
60 {
61  Bind();
62  glClearStencil(s);
63  glClear(GL_STENCIL_BUFFER_BIT);
64 
65  GLF_THROW_ON_OPENGL_ERROR;
66 }
67 
68 void glfRenderTarget::ReadBuffer(ImageBase& image, BufferType bufferType, int x, int y, int width, int height)
69 {
70  Bind();
71 
72  // choose format for glReadPixels and numChannels for image.
73  GLenum format;
74  int numChannels;
75  switch (bufferType) {
76  case BUFFER_COLOR:
77  format = GL_RGB;
78  numChannels = 3;
79  break;
80  case BUFFER_DEPTH:
81  format = GL_DEPTH_COMPONENT;
82  numChannels = 1;
83  break;
84  case BUFFER_STENCIL:
85  format = GL_STENCIL_INDEX;
86  numChannels = 1;
87  break;
88  default:
89  GLF_THROW_EXCEPTION("Invalid grab source");
90  break;
91  };
92 
93  // get pixel type
94  GLenum type;
95  ImageBase::EStorageType storageType = image.GetStorageType();
96  switch (storageType) {
98  type = GL_UNSIGNED_BYTE;
99  break;
100  case ImageBase::ST_char:
101  type = GL_BYTE;
102  break;
104  type = GL_UNSIGNED_SHORT;
105  break;
107  type = GL_SHORT;
108  break;
110  type = GL_UNSIGNED_INT;
111  break;
112  case ImageBase::ST_int:
113  type = GL_INT;
114  break;
115  case ImageBase::ST_float:
116  type = GL_FLOAT;
117  break;
118  default:
119  GLF_THROW_EXCEPTION("Invalid storage type for ReadPixels");
120  break;
121  };
122 
123  // create image
124  if (!image.IsEmpty()) {
125  image.Release();
126  }
127  image.Init(width, height, numChannels, storageType);
128 
129  // copy data to image
130  glReadPixels(x, y, width, height, format, type, image.GetImageData());
131 }
(16bit) unsigned integer image storage type
Definition: ImageBase.hh:114
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
(8bit) signed char image storage type
Definition: ImageBase.hh:113
void ReadBuffer(BIAS::ImageBase &image, BufferType bufferType, int x, int y, int width, int height)
Copies the contents of a buffer to an image.
float image storage type
Definition: ImageBase.hh:118
(16bit) signed integer image storage type
Definition: ImageBase.hh:115
const void * GetImageData() const
Definition: ImageBase.hh:280
void ClearAccumBuffer(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=0.0f)
Clears the accumulation buffer of the render target with the given color.
void ClearDepthBuffer(float depth=1.0f)
Clears the depth buffer of the render target with the given value.
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
Definition: ImageBase.cpp:350
(32bit) signed integer image storage type
Definition: ImageBase.hh:117
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Definition: ImageBase.cpp:229
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
void ClearStencilBuffer(int s=0)
Clears the stencil buffer of the render target with the given value.
void ClearColorBuffer(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=0.0f)
Clears the color buffer of the render target with the given color.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
(32bit) unsigned integer image storage type
Definition: ImageBase.hh:116