Example #1
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   #ifdef OPENCL_API
     auto queue_plain = queue();
     auto event = cl_event{};
     auto status = Col2im<T>(args.kernel_mode,
                             args.channels, args.height, args.width,
                             args.kernel_h, args.kernel_w,
                             args.pad_h, args.pad_w,
                             args.stride_h, args.stride_w,
                             args.dilation_h, args.dilation_w,
                             buffers.b_mat(), args.b_offset, // col
                             buffers.a_mat(), args.a_offset, // im
                             &queue_plain, &event);
     if (status == StatusCode::kSuccess) { clWaitForEvents(1, &event); clReleaseEvent(event); }
   #elif CUDA_API
     auto status = Col2im<T>(args.kernel_mode,
                             args.channels, args.height, args.width,
                             args.kernel_h, args.kernel_w,
                             args.pad_h, args.pad_w,
                             args.stride_h, args.stride_w,
                             args.dilation_h, args.dilation_w,
                             buffers.b_mat(), args.b_offset, // col
                             buffers.a_mat(), args.a_offset, // im
                             queue.GetContext()(), queue.GetDevice()());
     cuStreamSynchronize(queue());
   #endif
   return status;
 }
TEST(HashTableBufferManager, GetBuffersDump) {
    HashTableBufferManager manager;
    manager.initBuffers(3, 5);
    const QList<SignalValueVector> &data = {
        {{1.0, 0}, {1.5, 0}, {2.5, 1}},
        {{2.0, 0}, {2.5, 0}, {0.5, 1}},
        {{3.0, 0}, {1.5, 0}, {2.4, 1}},
        {{4.0, 0}, {2.5, 0}, {2.2, 0}},
        {{5.0, 0}, {1.5, 0}, {2.1, 1}},
    };

    manager.pushSignalValues(data.at(0), 0);
    manager.pushSignalValues(data.at(1), 1);
    manager.pushSignalValues(data.at(2), 2);
    manager.pushSignalValues(data.at(3), 3);
    manager.pushSignalValues(data.at(4), 4);

    const QList<SignalValueVector> &transposedData = {
        {{1.0, 0}, {2.0, 0}, {3.0, 0}, {4.0, 0}, {5.0, 0}},
        {{1.5, 0}, {2.5, 0}, {1.5, 0}, {2.5, 0}, {1.5, 0}},
        {{2.5, 1}, {0.5, 1}, {2.4, 1} ,{2.2, 0} ,{2.1, 1}}
    };
    Buffers buffers;
    buffers.insert(0, transposedData.at(0));
    buffers.insert(2, transposedData.at(1));
    buffers.insert(4, transposedData.at(2));

    EXPECT_EQ(buffers, manager.getBuffers());
}
Example #3
0
/*---------------------------------------------------------------------------
   Class specific setup function for the effects assets.
  ---------------------------------------------------------------------------*/
void FilterNMap::Assets(Buffers &Buffer)
   {
   if (!Ready()) {return;}

   Depth.Create(Buffer.GetDepthResolution(), Buffer.GetDepthDataType());
   Depth.ClearData();
   Depth.Buffer(false);

   Model.Plane(1, Mesh::ModeSolid);
   Model.Buffer(false);

   File::Text Text;
   std::string CodeVert, CodeFrag;
   Text.Load(CodeVert, File::Path::Shader(File::FilterNMapVert));
   Text.Load(CodeFrag, File::Path::Shader(File::FilterNMapFrag));
   Program.Attach(CodeVert, Shader::ShaderVert);
   Program.Attach(CodeFrag, Shader::ShaderFrag);
   Program.Buffer(false);

   Program.Bind();
   glUniform1i(glGetUniformLocation(Program.ID(), "Texture"), 0);   //Texture unit 0
   Program.Unbind();

   GLenum Error = glGetError();
   if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   }
Example #4
0
/*---------------------------------------------------------------------------
   Tests the selected input texture and changes configuration if the 
   resolutions do not match. The function does nothing for identical 
   configurations.
  ---------------------------------------------------------------------------*/
void Filter::Change(Buffers &Buffer)
   {
   vector2u Res[2];
   Texture::TexType Type[2];

   switch (Select)
      {
      case Filter::SelectVideo : 
         Res[0] = Buffer.GetVideoResolution();
         Res[1] = Video.Resolution();
         Type[0] = Buffer.GetVideoDataType();
         Type[1] = Video.DataType();
         break;

      case Filter::SelectDepth : 
         Res[0] = Buffer.GetDepthResolution();
         Res[1] = Depth.Resolution();
         Type[0] = Buffer.GetDepthDataType();
         Type[1] = Depth.DataType();
         break;

      default : throw dexception("Invalid Select enumeration.");
      }

   if (Res[0].U < 1 || Res[0].V < 1) {return;}
   
   if (Res[0].U != Res[1].U || Res[0].V != Res[1].V || Type[0] != Type[1])
      {
      Setup(Buffer);
      Assets(Buffer);
      }
   }
Example #5
0
bool MemoryFileImpl::Rewind()
{
    mActBufferId = 0;
    for( Buffers::iterator i = mBuffers.begin(), e = mBuffers.end(); i != e; ++i )
    {
        i->pos = 0;
    }
    return true;
}
Example #6
0
void dump_buffers(Buffers const & buffers)
{
    std::cout << "dump_buffers:" << std::endl;
    typedef typename Buffers::const_iterator const_iterator;
    for (const_iterator iter = buffers.begin(); iter != buffers.end(); ++iter) {
        boost::asio::const_buffer buffer(*iter);
        std::cout << buffer_cast<char const *>(buffer) - buf << ":" << buffer_size(buffer) << std::endl;
    }
};
Example #7
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   auto queue_plain = queue();
   auto event = cl_event{};
   auto status = Asum<T>(args.n,
                         buffers.scalar(), args.asum_offset,
                         buffers.x_vec(), args.x_offset, args.x_inc,
                         &queue_plain, &event);
   clWaitForEvents(1, &event);
   return status;
 }
Example #8
0
 static bool all_empty(const Buffers& buffer_sequence)
 {
   typename Buffers::const_iterator iter = buffer_sequence.begin();
   typename Buffers::const_iterator end = buffer_sequence.end();
   std::size_t i = 0;
   for (; iter != end && i < max_buffers; ++iter, ++i)
     if (riakboost::asio::buffer_size(Buffer(*iter)) > 0)
       return false;
   return true;
 }
Example #9
0
 static void validate(const Buffers& buffer_sequence)
 {
   typename Buffers::const_iterator iter = buffer_sequence.begin();
   typename Buffers::const_iterator end = buffer_sequence.end();
   for (; iter != end; ++iter)
   {
     Buffer buffer(*iter);
     riakboost::asio::buffer_cast<const void*>(buffer);
   }
 }
Example #10
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   auto queue_plain = queue();
   auto event = cl_event{};
   auto status = Axpy(args.n, args.alpha,
                      buffers.x_vec(), args.x_offset, args.x_inc,
                      buffers.y_vec(), args.y_offset, args.y_inc,
                      &queue_plain, &event);
   if (status == StatusCode::kSuccess) { clWaitForEvents(1, &event); clReleaseEvent(event); }
   return status;
 }
Example #11
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   auto queue_plain = queue();
   auto event = cl_event{};
   auto status = Trmv<T>(args.layout, args.triangle, args.a_transpose, args.diagonal,
                         args.n,
                         buffers.a_mat(), args.a_offset, args.a_ld,
                         buffers.x_vec(), args.x_offset, args.x_inc,
                         &queue_plain, &event);
   if (status == StatusCode::kSuccess) { clWaitForEvents(1, &event); clReleaseEvent(event); }
   return status;
 }
Example #12
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   auto queue_plain = queue();
   auto event = cl_event{};
   auto status = Omatcopy<T>(args.layout, args.a_transpose,
                             args.m, args.n, args.alpha,
                             buffers.a_mat(), args.a_offset, args.a_ld,
                             buffers.b_mat(), args.b_offset, args.b_ld,
                             &queue_plain, &event);
   if (status == StatusCode::kSuccess) { clWaitForEvents(1, &event); clReleaseEvent(event); }
   return status;
 }
Example #13
0
File: xhpr.hpp Project: gcp/CLBlast
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<U> &args, Buffers<T> &buffers, Queue &queue) {
   auto queue_plain = queue();
   auto event = cl_event{};
   auto status = Hpr(args.layout, args.triangle,
                     args.n, args.alpha,
                     buffers.x_vec(), args.x_offset, args.x_inc,
                     buffers.ap_mat(), args.ap_offset,
                     &queue_plain, &event);
   clWaitForEvents(1, &event);
   return status;
 }
Example #14
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   auto queue_plain = queue();
   auto event = cl_event{};
   auto status = Hemm(args.layout, args.side, args.triangle,
                      args.m, args.n, args.alpha,
                      buffers.a_mat(), args.a_offset, args.a_ld,
                      buffers.b_mat(), args.b_offset, args.b_ld, args.beta,
                      buffers.c_mat(), args.c_offset, args.c_ld,
                      &queue_plain, &event);
   clWaitForEvents(1, &event);
   return status;
 }
Example #15
0
 static Buffer first(const Buffers& buffer_sequence)
 {
   typename Buffers::const_iterator iter = buffer_sequence.begin();
   typename Buffers::const_iterator end = buffer_sequence.end();
   for (; iter != end; ++iter)
   {
     Buffer buffer(*iter);
     if (riakboost::asio::buffer_size(buffer) != 0)
       return buffer;
   }
   return Buffer();
 }
Example #16
0
 explicit buffer_sequence_adapter(const Buffers& buffer_sequence)
   : count_(0), total_buffer_size_(0)
 {
   typename Buffers::const_iterator iter = buffer_sequence.begin();
   typename Buffers::const_iterator end = buffer_sequence.end();
   for (; iter != end && count_ < max_buffers; ++iter, ++count_)
   {
     Buffer buffer(*iter);
     init_native_buffer(buffers_[count_], buffer);
     total_buffer_size_ += riakboost::asio::buffer_size(buffer);
   }
 }
Example #17
0
bool MemoryFileImpl::CopyTo( File& Other )
{
    for( Buffers::const_iterator i = mBuffers.begin(), e = mBuffers.end(); i != e; ++i )
    {
        if( !i->size )
        {
            break;
        }
        std::string Data( i->data, i->size );
        if( !Other.Write( Data ) )
        {
            return false;
        }
    }
    return true;
}
Example #18
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   #ifdef OPENCL_API
     auto queue_plain = queue();
     auto event = cl_event{};
     auto status = Scal(args.n, args.alpha,
                        buffers.x_vec(), args.x_offset, args.x_inc,
                        &queue_plain, &event);
     if (status == StatusCode::kSuccess) { clWaitForEvents(1, &event); clReleaseEvent(event); }
   #elif CUDA_API
     auto status = Scal(args.n, args.alpha,
                        buffers.x_vec(), args.x_offset, args.x_inc,
                        queue.GetContext()(), queue.GetDevice()());
     cuStreamSynchronize(queue());
   #endif
   return status;
 }
Example #19
0
/*---------------------------------------------------------------------------
   This function will update either the video texture, or depth texture, or
   both (if applicable). It may also recofigure the filter if the selected
   input has a different resolution. Returns true if either of the textures
   were updated.
  ---------------------------------------------------------------------------*/
bool Filter::Update(Buffers &Buffer)
   {
   if (!Ready()) {return false;}

   //Test for resolution change, if applicable
   Change(Buffer);
   
   bool Updated = false;

   if (Buffer.VideoUpdated(VideoUpdateID) && EnableVideo)
      {
      Texture &VideoFront = Buffer.GetVideo();
      MutexControl Mutex(VideoFront.GetMutexHandle());
      if (Mutex.LockRequest())
         {
         Video.Bind(0);
         Video.Update(VideoFront);
         Video.Unbind(0);
         Mutex.Unlock();
         Updated |= true;
         }
      }

   if (Buffer.DepthUpdated(DepthUpdateID) && EnableDepth)
      {
      Texture &DepthFront = Buffer.GetDepth();
      MutexControl Mutex(DepthFront.GetMutexHandle());
      if (Mutex.LockRequest())
         {
         Depth.Bind(0);
         Depth.Update(DepthFront);
         Depth.Unbind(0);
         Mutex.Unlock();
         Updated |= true;
         }
      }

   #if defined (DEBUG)
      GLenum Error = glGetError();
      if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   #endif

   return Updated;
   }
Example #20
0
bool MemoryFileImpl::Write( void const* Src, size_t Size )
{
    mSize += Size;
    char const* p = ( char const* )Src;
    while( Size )
    {
        if( mActBufferId >= mBuffers.size() )
        {
            mBuffers.push_back( Buffer_t() );
        }
        const size_t W = mBuffers[mActBufferId].write( p, Size );
        Size -= W;
        p += W;
        if( Size )
        {
            mActBufferId++;
        }
    }
    return true;
}
Example #21
0
/*---------------------------------------------------------------------------
   Class specific setup function for the effects assets.
  ---------------------------------------------------------------------------*/
void Filter::Assets(Buffers &Buffer)
   {
   if (!Ready()) {return;}

   Video.Create(Buffer.GetVideoResolution(), Buffer.GetVideoDataType());
   Video.ClearData();
   Video.Buffer(false);

   Model.Plane(1, Mesh::ModeSolid);
   Model.Buffer(false);

   File::Text Text;
   std::string CodeVert, CodeFrag;
   Text.Load(CodeVert, File::Path::Shader(File::FilterVert));
   Text.Load(CodeFrag, File::Path::Shader(File::FilterFrag));
   Program.Attach(CodeVert, Shader::ShaderVert);
   Program.Attach(CodeFrag, Shader::ShaderFrag);
   Program.Buffer(false);

   GLenum Error = glGetError();
   if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   }
Example #22
0
/*---------------------------------------------------------------------------
   Class specific setup function for the effects assets.
  ---------------------------------------------------------------------------*/
void FilterPalette::Assets(Buffers &Buffer)
   {
   if (!Ready()) {return;}

   Depth.Create(Buffer.GetDepthResolution(), Buffer.GetDepthDataType());
   Depth.ClearData();
   Depth.Buffer(false);

   Model.Plane(1, Mesh::ModeSolid);
   Model.Buffer(false);

   File::PNG PNG;
   PNG.Load(Palette, File::Path::Shader(File::TexturePalette));
   Palette.SetMinFilter(Texture::MinNearest); //Disable filtering for palette texture in order to prevent bleeding into adjacent tables
   Palette.SetMagFilter(Texture::MagNearest);
   Palette.Buffer(false);

   File::Text Text;
   std::string CodeVert, CodeFrag;
   Text.Load(CodeVert, File::Path::Shader(File::FilterPaletteVert));
   Text.Load(CodeFrag, File::Path::Shader(File::FilterPaletteFrag));
   Program.Attach(CodeVert, Shader::ShaderVert);
   Program.Attach(CodeFrag, Shader::ShaderFrag);
   Program.Buffer(false);

   //Convert table selector to normalised texture coordinates
   float Select = (float)(Palette.Resolution().V - 1);
   if (Select > Math::feps) {Select = (float)Type / Select;}

   Program.Bind();
   glUniform1f(glGetUniformLocation(Program.ID(), "Select"), Select); 
   glUniform1i(glGetUniformLocation(Program.ID(), "Texture"), 0);   //Texture unit 0
   glUniform1i(glGetUniformLocation(Program.ID(), "Palette"), 1);   //Texture unit 1
   Program.Unbind();

   GLenum Error = glGetError();
   if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   }
Example #23
0
/*---------------------------------------------------------------------------
   Class specific setup function for the effects assets.
  ---------------------------------------------------------------------------*/
void FilterLines::Assets(Buffers &Buffer)
   {
   if (!Ready()) {return;}

   GLint Count = 0;
   glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &Count);
   if (Count < 1) {throw dexception("Current OpenGL context does not support vertex texture image units.");}

   vector2u Res = Buffer.GetDepthResolution();
   Depth.Create(Res, Buffer.GetDepthDataType());
   Depth.ClearData();
   Depth.Buffer(false);

   Model.Plane(1, Mesh::ModeSolid);
   Model.Buffer(false);

   File::PNG PNG;
   PNG.Load(Lines, File::Path::Texture(File::TextureLines));
   Lines.SetWrap(true);
   Lines.Buffer(false);

   File::Text Text;
   std::string CodeVert, CodeFrag;
   Text.Load(CodeVert, File::Path::Shader(File::FilterLinesVert));
   Text.Load(CodeFrag, File::Path::Shader(File::FilterLinesFrag));
   Program.Attach(CodeVert, Shader::ShaderVert);
   Program.Attach(CodeFrag, Shader::ShaderFrag);
   Program.Buffer(false);

   Program.Bind();
   glUniform1i(glGetUniformLocation(Program.ID(), "Texture"), 0);   //Texture unit 0
   glUniform1i(glGetUniformLocation(Program.ID(), "Lines"), 1);   //Texture unit 1
   glUniform1f(glGetUniformLocation(Program.ID(), "Scale"), (float)Res.V / 12.0f); //Scale factor for the line texture sampler
   Program.Unbind();

   GLenum Error = glGetError();
   if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   }
Example #24
0
VAO::VAO(Buffers<Vertex> &vbo, Buffers<uint32_t> &ibo){
	glGenVertexArrays(1,&vao);
	
	glBindVertexArray(vao);
	ibo.bind();
	
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);	
	glEnableVertexAttribArray(2);
	
	vbo.bind();
	
	glVertexAttribPointer(0,3,GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*) offsetof(Vertex, position));
	glVertexAttribPointer(1,3,GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*) offsetof(Vertex, normal));
	glVertexAttribPointer(2,2,GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*) offsetof(Vertex, coordsTexture));
	
	vbo.unbind();
	ibo.unbind();
	glBindVertexArray(0);
	
	occurenceCounter[vao]++;
	
}
Example #25
0
bool MemoryFileImpl::CopyFrom( File& Other )
{
    size_t Size = Other.GetSize();
    mActBufferId = 0;
    mSize = Size;
    const size_t NumBuffers = Size / ONE_BUFFER_SIZE + ( Size % ONE_BUFFER_SIZE ) ? 1 : 0;
    mBuffers.clear();
    mBuffers.resize( NumBuffers );
    size_t Idx = 0;
    while( Size )
    {
        size_t ToRead = std::min<size_t>( Size, ONE_BUFFER_SIZE );
        std::string Buffer;
        if( !Other.Read( Buffer, ToRead ) )
        {
            mBuffers.clear();
            mSize = 0;
            return false;
        }
        memcpy( mBuffers[Idx++].data, Buffer.data(), ToRead );
        Size -= ToRead;
    }
    return true;
}
Example #26
0
	size_t bodyBuffers(bool chunked, list<string> &chunkLines, const iovec* vec, int c, Buffers& buffers) {
		size_t rsize = 0;
		for (int i = 0; i < c; ++i)
			rsize += vec[i].iov_len;

		if (rsize != 0) {
			if (chunked) {
				chunkLines.push_back(hexSize(rsize));
				buffers.push_back(toBuffer(chunkLines.back()));
				buffers.push_back(blanklineBuffer());
				buffers.insert(buffers.end(), vec, vec + c);
				buffers.push_back(blanklineBuffer());
			}
			else {
				buffers.insert(buffers.end(), vec, vec + c);
			}
		}

		return rsize;
	}
Example #27
0
bool MemoryFileImpl::Read( void* Data, size_t Size )
{
    if( Size > GetSize() - GetPosition() )
    {
        return false;
    }
    char* p = ( char* )Data;
    while( Size )
    {
        const size_t R = mBuffers[mActBufferId].read( p, Size );
        Size -= R;
        p += R;
        if( Size )
        {
            mActBufferId++;
        }
        if( mActBufferId >= mBuffers.size() )
        {
            return false;
        }
    }
    return true;
}
Example #28
0
/*---------------------------------------------------------------------------
   Class specific setup function for the effects assets.
  ---------------------------------------------------------------------------*/
void FilterSolids::Assets(Buffers &Buffer)
   {
   if (!Ready()) {return;}

   vector2u Res = Buffer.GetDepthResolution();
   Depth.Create(Res, Buffer.GetDepthDataType());
   Depth.ClearData();
   Depth.Buffer(false);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glPushMatrix();
   Light.SetPosition(vector4f(0.5f, -0.5f, Near + 1.0f, 0.0f));
   Light.Buffer(0);
   glPopMatrix();

   Grid = Res / GridDiv;
   Grid = Grid.Clamp(GridMin, GridMax);
   GridNorm = cast_vector2(float, Grid);
   GridNorm = GridNorm.Rcp();
   uint GridSmallest = Math::Min(Grid.U, Grid.V);

   Offset = cast_vector2(float, Grid);
   Offset = (Offset - 1.0f) * 0.5f;

   //Geometry subdivisions for curved solids
   uint PolyDiv = (Math::Min(Res.U, Res.V) / GridSmallest) / PolyDivPixels;
   PolyDiv = Math::Clamp(PolyDiv, PolyDivMin, PolyDivMax);

   File::Text Text;
   std::string CodeVert, CodeFrag;

   switch (Type)
      {
      case FilterSolids::Cubes :
         Model.Cube(1, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         Mat.SetShininess(0.0f);
         break;

      case FilterSolids::Spheres :
         Model.Sphere(PolyDiv, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         break;

      case FilterSolids::CubesTinted :
         Model.Cube(1, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsVideoVert));
         Video.Create(Buffer.GetVideoResolution(), Buffer.GetVideoDataType());
         Video.ClearData();
         Video.Buffer(false);
         EnableVideo = true;
         EnableDepth = true;
         EnableCal = true;
         Mat.SetShininess(0.0f);
         break;

      case FilterSolids::SpheresTinted :
         Model.Sphere(PolyDiv, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsVideoVert));
         Video.Create(Buffer.GetVideoResolution(), Buffer.GetVideoDataType());
         Video.ClearData();
         Video.Buffer(false);
         EnableVideo = true;
         EnableDepth = true;
         EnableCal = true;
         break;

      case FilterSolids::CubesFar :
         Model.Cube(1, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         Mat.SetShininess(0.0f);
         Far = -1000.0f;
         break;

      case FilterSolids::SpheresFar :
         Model.Sphere(PolyDiv, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         Far = -1000.0f;
         break;

      default : dexception("Unknown filter enumeration type.");
      }

   Range = Math::Abs(Far - Near);

   Model.Buffer(false);

   Text.Load(CodeFrag, File::Path::Shader(File::FilterSolidsFrag));
   Program.Attach(CodeVert, Shader::ShaderVert);
   Program.Attach(CodeFrag, Shader::ShaderFrag);
   Program.Buffer(false);

   Program.Bind();
   glUniform1f(glGetUniformLocation(Program.ID(), "Range"), Math::Abs(Range));
   glUniform1i(glGetUniformLocation(Program.ID(), "Depth"), 0);   //Texture unit 0
   glUniform1i(glGetUniformLocation(Program.ID(), "Video"), 1);   //Texture unit 1
   UID = glGetUniformLocation(Program.ID(), "TexCoord");
   glUniform2f(UID, 0.0f, 0.0f);
   Program.Unbind();

   //Projection matrix
   MP = MP.Identity();
   MP = MP.Frustum(-Ratio.X, Ratio.X, -Ratio.Y, Ratio.Y, Math::Abs(Near), Math::Abs(Far));

   //Modelview matrix
   float Scale = 1.0f / (float)GridSmallest;
   MV = MV.Identity();
   MV = MV.Scale(Scale, Scale, Scale);
   MV = MV.Translate(0.0f, 0.0f, (Near - Scale - 0.01f) / Scale);

   GLenum Error = glGetError();
   if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   }
Example #29
0
size_t MemoryFileImpl::GetPosition() const
{
    return mActBufferId * ONE_BUFFER_SIZE + ( ( mActBufferId < mBuffers.size() ) ? mBuffers[mActBufferId].pos : 0 );
}
Example #30
0
/*---------------------------------------------------------------------------
   Setup function that a intialises assets, matrices and other OpenGL
   related structure for rendering. NOTE: This must be called within a 
   valid OpenGL context.
  ---------------------------------------------------------------------------*/
void Filter::Setup(Buffers &Buffer)
   {
   Destroy();

   if (!GLEW_ARB_framebuffer_object)
      {throw dexception("Current OpenGL context does not support frame buffer objects.");}

   vector2u Res;
   
   switch (Select)
      {
      case Filter::SelectVideo : Res = Buffer.GetVideoResolution(); break;
      case Filter::SelectDepth : Res = Buffer.GetDepthResolution(); break;
      default : throw dexception("Invalid Select enumeration.");;
      }

   if (Res.X < 1 || Res.Y < 1) {return;}
   
   //Create a new frame buffer object
   glGenFramebuffers(1, &FBOID);
   glBindFramebuffer(GL_FRAMEBUFFER, FBOID);

   //Create a new depth buffer object, then associate a 
   // storage space for it, and attach it to the FBO
   glGenRenderbuffers(1, &DBOID);
   glBindRenderbuffer(GL_RENDERBUFFER, DBOID);
   glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, Res.X, Res.Y);
   glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DBOID);

   //Create a colour buffer in form of a texture and attach it to the FBO
   glGenTextures(1, &CBOID);
   glBindTexture(GL_TEXTURE_2D, CBOID);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, Res.X, Res.Y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
   glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CBOID, 0);

   //FBO texture scaling
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

   //Setup view port size
   ViewPort.Set4(0, 0, Res.X, Res.Y);

   //Compute frustum aspect ratio from viewport size
   Ratio.Set((float)ViewPort.C2, (float)ViewPort.C3);
   Ratio /= (float)Math::Min(ViewPort.C2, ViewPort.C3);

   //Default projection matrix
   MP = MP.Identity();
   MP = MP.Ortho(-Ratio.X, Ratio.X, -Ratio.Y, Ratio.Y, Near, Far);

   //Default model view matrix
   MV = MV.Identity();
   MV = MV.Scale(Ratio.X, Ratio.Y, 1.0f);

   //Default texture matrix
   MT = MT.Identity();
   //MT = MT.Scale(1.0f, -1.0f, 1.0f);
   //MT = MT.Translate(0.0f, -1.0f, 0.0f);

   MC = MC.Identity();

   //Error checking   
   GLenum Error = glCheckFramebufferStatus(GL_FRAMEBUFFER);
   if (Error != GL_FRAMEBUFFER_COMPLETE) {throw dexception("Failed to setup frame buffer object: %s.", Debug::StatusFBO(Error));}

   Error = glGetError();
   if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   }