Sign in to follow this  
andy1984

template problem

Recommended Posts

andy1984    154
Umm I'm having trouble making this template class that uses OpenGL stuf from glext.h. The error message says that "there are no arguments to 'glGenBuffersARB' that depend on a template parameter... bla". It treats all the functions from glext.h the same.

I only get this when I try to make the class as a template and implement stuff in the header file rather than the cpp file.

I'm just not too sure why this happens.


// Apparently this has to go right at the top
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>

#ifndef VBO_H
#define VBO_H

#include <vector>

...

template <typename T>
class Buffer
{
protected:
unsigned int m_id;
unsigned int m_type;
BufferNode m_node;
unsigned int m_usage;

static int s_supported;
// Check if VBOs are supported
static void checkSupported()
{
// Get Extensions String
std::string extensions = ((char const *)(glGetString(GL_EXTENSIONS)));
// Search The Extensions String For An Exact Copy
size_t found = extensions.find("GL_ARB_vertex_buffer_object");
if (found != std::string::npos)
s_supported = 1;
s_supported = -1;
};

public:
// Get the value of s_supported
static bool isSupported()
{
if (!s_supported)
checkSupported();
return s_supported == 1;
};
Buffer(unsigned int type, unsigned int size, unsigned int usage) :
m_id(0), m_type(type), m_node(0, size - 1), m_usage(usage)
{
// Make the buffer
glGenBuffersARB(1, &m_id);
bind();
glBufferDataARB(m_type, sizeof(T) * getSize(), 0, m_usage);
unbind();
};
~Buffer()
{
if (m_id)
glDeleteBuffersARB(1, &m_id);
};
unsigned int getId()
{
return m_id;
};
BufferNode* getNode()
{
return &m_node;
};
unsigned int getSize()
{
return m_node.getSize();
};
unsigned int getUsage()
{
return m_usage;
};
void bind()
{
glBindBufferARB(m_type, m_id);
};
void unbind()
{
glBindBufferARB(m_type, 0);
};
bool subData(BufferNode* node, unsigned int size, T* data)
{
if (!node || node->getSize() < size)
return false;
bind();
glBufferSubDataARB(m_id, node->getFirst(), size, data);
unbind();
return true;
};
};







Hope someone can clear this up for me.

Thanks,
Andy

Share this post


Link to post
Share on other sites
andy1984    154
I haven't instantiated it, it just shows that error when I try to compile it. Its not really necessary that it be a template, I think I can change things around a little so all the opengl extension calls can go in a non-template class. I am still curious why it wont compile though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this