Commit 7f27b3be authored by Robert Menzel's avatar Robert Menzel

moved setResourceName for compatibility and added ArrayBufferCreator

parent 4e4f7f56
/***********************************************************************
* Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#pragma once
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class ArrayBufferCreator
{
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
public:
struct AttributeDefine
{
std::string name;
GLenum type;
GLint dimension;
GLboolean normalized;
GLboolean isInteger;
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector< AttributeDefine > AttributeDefineVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ArrayBufferCreator(void)
: mUsage(GL_STATIC_DRAW),
mElements(0),
mpData(NULL),
mAttributeDefines()
{}
virtual ~ArrayBufferCreator() {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline ArrayBufferCreator& usage (GLenum _usage) { mUsage = _usage; return *this; }
inline ArrayBufferCreator& data (const GLvoid* _pData, GLsizei _elements)
{
mpData = _pData;
mElements = _elements;
return *this;
}
inline ArrayBufferCreator& attribute (const std::string& _name, GLenum _type, GLint _dimension, GLboolean _normalized = GL_FALSE)
{
AttributeDefine a = {_name, _type, _dimension, _normalized, GL_FALSE};
mAttributeDefines.push_back(a);
return *this;
}
inline ArrayBufferCreator& integerAttribute (const std::string& _name, GLenum _type, GLint _dimension)
{
AttributeDefine a = {_name, _type, _dimension, GL_FALSE, GL_TRUE};
mAttributeDefines.push_back(a);
return *this;
}
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
SharedArrayBuffer create();
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
GLenum mUsage;
GLsizei mElements;
const GLvoid* mpData;
AttributeDefineVec mAttributeDefines;
};
} // OpenGL
} // ACGL
......@@ -42,6 +42,8 @@ public:
public:
inline ShaderCreator& type (GLenum _type) { mType = _type; return *this; }
ShaderCreator& setResourceName(const std::string &_resourceName) { mResourceName = _resourceName; return *this; }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
......
......@@ -66,6 +66,8 @@ public:
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
ShaderProgramCreator& setResourceName(const std::string &_resourceName) { mResourceName = _resourceName; return *this; }
//
// Adding files:
//
......
......@@ -22,6 +22,8 @@ public:
: Resource::SingleFileBasedCreator<Texture2D>(_filename, Base::Settings::the()->getFullTexturePath() ) {}
virtual ~Texture2DCreator() {}
Texture2DCreator& setResourceName(const std::string &_resourceName) { mResourceName = _resourceName; return *this; }
//! try to create a 2D mip-mapped texture
virtual SharedTexture2D create();
......
......@@ -34,6 +34,8 @@ public:
VertexArrayObjectCreator(const std::string& _filename);
VertexArrayObjectCreator(const char* _filename);
VertexArrayObjectCreator& setResourceName(const std::string &_resourceName) { mResourceName = _resourceName; return *this; }
template<typename CONTROLLER>
VertexArrayObjectCreator(const CONTROLLER& _fileController)
: Resource::SingleFileBasedCreator<VertexArrayObject>(_fileController.getFilename(), Base::Settings::the()->getFullGeometryPath()),
......
......@@ -63,11 +63,6 @@ public:
return mResourceName;
}
//
// Modifying the resource name:
//
MultiFileBasedCreator& setResourceName(const std::string &_resourceName) { mResourceName = _resourceName; return *this; }
//! this should create and return the resource
virtual ptr::shared_ptr<RESOURCE> create() = 0;
......
......@@ -44,11 +44,6 @@ public:
const std::string& getFilename(void) const { return mFilename; }
const std::string& getFullFilePath(void) const { return mFullFilePath; }
//
// Modifying the resource name:
//
SingleFileBasedCreator& setResourceName(const std::string &_resourceName) { mResourceName = _resourceName; return *this; }
//! this should create and return the resource
virtual ptr::shared_ptr<RESOURCE> create() = 0;
......
/***********************************************************************
* Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#include <ACGL/OpenGL/Creator/ArrayBufferCreator.hh>
using namespace ACGL::OpenGL;
SharedArrayBuffer ArrayBufferCreator::create()
{
SharedArrayBuffer arrayBuffer( new ArrayBuffer() );
for(AttributeDefineVec::size_type i = 0; i < mAttributeDefines.size(); i++)
{
if(mAttributeDefines[i].isInteger)
{
arrayBuffer->defineIntegerAttribute(mAttributeDefines[i].name,
mAttributeDefines[i].type,
mAttributeDefines[i].dimension);
}
else
{
arrayBuffer->defineAttribute(mAttributeDefines[i].name,
mAttributeDefines[i].type,
mAttributeDefines[i].dimension,
mAttributeDefines[i].normalized);
}
}
if (mpData != NULL)
{
arrayBuffer->bind();
arrayBuffer->setDataElements(mElements, mpData, mUsage);
}
return arrayBuffer;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment