예제 #1
0
void JMesh::assertAttributeLocations(GLuint programID){

    GLint activeAttribs, activeShaders;
    glGetProgramiv(programID, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttribs);
   // assert(activeAttribs>8);
    glGetProgramiv(programID, GL_ACTIVE_ATTRIBUTES, &activeAttribs);

    glGetProgramiv(programID, GL_ATTACHED_SHADERS, &activeShaders);
    assert(activeShaders == 2);
    GLint toDelete;
    glGetProgramiv(programID, GL_DELETE_STATUS, &toDelete); // If the program is about to be deleted
    assert(toDelete == GL_FALSE);//                            it will be flagged as gl_true we dont want that
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);
    
    GLuint locs[3];
    GLuint posLocation = glGetAttribLocation(programID, "position");
    GLuint normalLocation = glGetAttribLocation(programID, "normal");
    GLuint texLocation = glGetAttribLocation(programID, "texCoord");
    
    char * name1 = new char[1000];
    char * name2 = new char[1000];
    char * name3 = new char[1000];
    int actual[3];
    int sizeOfVar[3];
    GLenum typeOfVar[3];
    // Might not actually be the same
    glGetActiveAttrib(programID, posLocation, 1000, &actual[0], &sizeOfVar[0], &typeOfVar[0], name1);
    glGetActiveAttrib(programID, normalLocation, 1000, &actual[1], &sizeOfVar[1], &typeOfVar[1], name2);
    glGetActiveAttrib(programID, texLocation, 1000, &actual[2], &sizeOfVar[2], &typeOfVar[2], name3);
    std::string pos = "position";
    std::string nor = "normal";
    
    std::string tex = "texCoord";
    
   //// assert(typeOfVar[0] == GL_FLOAT_VEC3);
   // assert(typeOfVar[1] == GL_FLOAT_VEC2);
   // assert(typeOfVar[2] == GL_FLOAT_VEC3);

   
//    assert(pos.compare(name1)==0);
  //  assert(nor.compare(name2)==0);
    //assert(tex.compare(name3)==0);
    
    
    
    delete name1;
    delete name2;
    delete name3;
}
예제 #2
0
 /*************************************************************//**
 *
 *  @brief  アクティブな属性を出力する
 *  @param  なし
 *  @return なし
 *
 ****************************************************************/
void C_BaseShader::PrintActiveAttributes()
{
    // 属性の数と属性の名前の長さ
    GLint attributeNumber = 0, attributeNameLength = 0;

    // 属性の数と属性の名前の長さを取得
    glGetProgramiv(programObjectHandle_, GL_ACTIVE_ATTRIBUTES, &attributeNumber);
    glGetProgramiv(programObjectHandle_, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attributeNameLength);

    // 属性の名前のメモリ領域を確保
    auto pAttiributeName = std::make_unique<GLchar[]>(attributeNameLength);

    std::cout << "[ C_BaseShader::PrintActiveAttributes ] : 頂点シェーダーの属性の情報" << std::endl;
    std::cout << " Location | Name" << std::endl;
    std::cout << "------------------------------------------------" << std::endl;

    for(int32_t i = 0; i < attributeNumber; ++i)
    {
        // 書き込まれた数
        GLsizei writtenNumber = 0;

        // サイズ
        GLint size = 0;

        // タイプ
        GLenum type;

        // 属性についての情報を取得
        glGetActiveAttrib(programObjectHandle_, i, attributeNameLength, &writtenNumber, &size, &type, pAttiributeName.get());
        GLint location = glGetAttribLocation(programObjectHandle_, pAttiributeName.get());

        // 属性についての情報を出力
        printf(" %-8d | %s\n", location, pAttiributeName.get());
    }
}
예제 #3
0
/**
 * Show detailed information for all attribs of this program
 */
void SciIllLib::CGLShaderProgram::showAttribInformation()
{
    std::cout << "Getting ShaderProgram attributes information:" << std::endl;
    int count = 0;
    glGetProgramiv(m_hndProgram, GL_ACTIVE_ATTRIBUTES, &count);
    if (count == 0)
    {
        std::cout << "--> No attributes defined!" << std::endl;
        return;
    }
    
    GLsizei bufSize = 256;
    GLint size;
    GLsizei length;
    GLenum type;
    char* name = new char[bufSize];
    
    for (int idx=0; idx < count; idx++)
    {
        glGetActiveAttrib(m_hndProgram, idx, bufSize, &length, &size, &type, name);
        std::cout << "- " << idx << ":" << name << ", ";
		printTypeInfo(type);
		std::cout << std::endl;
    }
}
예제 #4
0
void CShaderObject::HashAttributes()
{
	glUseProgram(m_shaderObject);

	int nAttributes = 0;
	glGetProgramiv(m_shaderObject, GL_ACTIVE_ATTRIBUTES, &nAttributes);

	GLint* size = (GLint*)malloc(nAttributes * sizeof(GLint));
	GLenum* type = (GLenum*)malloc(nAttributes * sizeof(GLenum));
	GLsizei* len = (GLsizei*)malloc(nAttributes * sizeof(GLsizei));
	GLchar** name = (GLchar**)malloc(nAttributes * sizeof(GLchar**));

	for(int i = 0; i < nAttributes; ++i)
	{
		name[i] = (GLchar*)malloc(MAX_UNIFORM_LEN * sizeof(GLchar));
		glGetActiveAttrib(m_shaderObject, i, MAX_UNIFORM_LEN, &len[i], &size[i], &type[i], name[i]);
		m_attributeHash.Add(name[i], glGetAttribLocation(m_shaderObject, name[i]));
	}

	free(size);
	free(type);
	free(len);
	free(name);

	glUseProgram(0);
}
예제 #5
0
파일: Program.cpp 프로젝트: roxlu/rifty
void ShaderProgram::RetrieveAttributes()
{
    // Just for ease of use
    GLint attributeMaxLength = 0;
    glGetProgramiv( id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attributeMaxLength );
    GLchar* attributeName = new GLchar[ attributeMaxLength ];
    memset( attributeName, 0, attributeMaxLength );
    
    for( int i=0; i<numAttributes; ++i )
    {
        GLsizei length;
        GLint size;
        GLenum type;
        
        glGetActiveAttrib( id, i, attributeMaxLength, &length, &size, &type, attributeName );
        int locId = glGetAttribLocation( id, attributeName );
        ShaderAttribute* p = new ShaderAttribute();
        p->name = attributeName;
        p->location = locId;
        attrMap[ p->name ] = p;
        attrArray[ i ] = p;
    }
    
    delete [] attributeName;
}
예제 #6
0
void ShaderProgram::retrieveLocations()
{
  GLint		n, maxLen;
  GLint		size, location;
  GLsizei	written;
  GLenum	type;
  GLchar*	name;

  glGetProgramiv(_handle, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLen);
  glGetProgramiv(_handle, GL_ACTIVE_ATTRIBUTES, &n);
  name = new GLchar[maxLen];
  for (int i = 0; i < n; ++i)
  {
    glGetActiveAttrib(_handle, i, maxLen, &written, &size, &type, name);
    location = glGetAttribLocation(_handle, name);
    _attribs[name] = location;
  }
  delete[] name;
  glGetProgramiv(_handle, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLen);
  glGetProgramiv(_handle, GL_ACTIVE_UNIFORMS, &n);
  name = new GLchar[maxLen];
  for (int i = 0; i < n; ++i)
  {
    glGetActiveUniform(_handle, i, maxLen, &written, &size, &type, name);
    location = glGetUniformLocation(_handle, name);
    _uniforms[name] = location;
  }
  delete[] name;
}
/* void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name ) */
static jstring
android_glGetActiveAttrib2
  (JNIEnv *_env, jobject _this, jint program, jint index, jobject size_buf, jobject type_buf) {
    jarray _sizeArray = (jarray) 0;
    jint _sizeBufferOffset = (jint) 0;
    jarray _typeArray = (jarray) 0;
    jint _typeBufferOffset = (jint) 0;
    jint _lengthRemaining;
    GLsizei *length = (GLsizei *) 0;
    jint _sizeRemaining;
    GLint *size = (GLint *) 0;
    jint _typeRemaining;
    GLenum *type = (GLenum *) 0;

    jstring result = 0;

    GLint len = 0;
    glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len);
    if (!len) {
        return _env->NewStringUTF("");
    }
    char* buf = (char*) malloc(len);

    if (buf == NULL) {
        jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory");
        return NULL;
    }

    size = (GLint *)getPointer(_env, size_buf, &_sizeArray, &_sizeRemaining, &_sizeBufferOffset);
    type = (GLenum *)getPointer(_env, type_buf, &_typeArray, &_typeRemaining, &_typeBufferOffset);
    if (size == NULL) {
        char * _sizeBase = (char *)_env->GetPrimitiveArrayCritical(_sizeArray, (jboolean *) 0);
        size = (GLint *) (_sizeBase + _sizeBufferOffset);
    }
    if (type == NULL) {
        char * _typeBase = (char *)_env->GetPrimitiveArrayCritical(_typeArray, (jboolean *) 0);
        type = (GLenum *) (_typeBase + _typeBufferOffset);
    }
    glGetActiveAttrib(
        (GLuint)program,
        (GLuint)index,
        (GLsizei)len,
        NULL,
        (GLint *)size,
        (GLenum *)type,
        (char *)buf
    );

    if (_typeArray) {
        releasePointer(_env, _typeArray, type, JNI_TRUE);
    }
    if (_sizeArray) {
        releasePointer(_env, _sizeArray, size, JNI_TRUE);
    }
    result = _env->NewStringUTF(buf);
    if (buf) {
        free(buf);
    }
    return result;
}
예제 #8
0
파일: shader.cpp 프로젝트: BWStearns/riftty
void Shader::buildVarMaps()
{
    const int MAX_STRING_SIZE = 1024;
    char tempStr[MAX_STRING_SIZE];
    int numUniforms = 0;
    int numAttribs = 0;
    Var v;

    glGetProgramiv(m_program, GL_ACTIVE_UNIFORMS, &numUniforms);
    for (int i = 0; i < numUniforms; ++i)
    {
        GLsizei strLen;
        glGetActiveUniform(m_program, i, MAX_STRING_SIZE, &strLen, &v.size, &v.type, tempStr);
        v.loc = glGetUniformLocation(m_program, tempStr);
        m_uniformVarMap[std::string(tempStr)] = v;
    }

    m_attribLocMask = 0;
    glGetProgramiv(m_program, GL_ACTIVE_ATTRIBUTES, &numAttribs);
    for (int i = 0; i < numAttribs; ++i)
    {
        GLsizei strLen;
        glGetActiveAttrib(m_program, i, MAX_STRING_SIZE, &strLen, &v.size, &v.type, tempStr);
        v.loc = glGetAttribLocation(m_program, tempStr);
        m_attribVarMap[std::string(tempStr)] = v;
        m_attribLocMask |= ((uint32_t)1 << v.loc);
        assert(v.loc < 32);
    }

    dump();
}
예제 #9
0
static void CopyShaderState_Attributes(GLuint newProgID, GLuint oldProgID)
{
	GLsizei numAttributes, maxNameLength;
	glGetProgramiv(oldProgID, GL_ACTIVE_ATTRIBUTES, &numAttributes);
	glGetProgramiv(oldProgID, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameLength);

	if (maxNameLength <= 0)
		return;

	std::string name(maxNameLength, 0);
	for (int i = 0; i < numAttributes; ++i) {
		GLsizei nameLength = 0;
		GLint size = 0;
		GLenum type = 0;
		glGetActiveAttrib(oldProgID, i, maxNameLength, &nameLength, &size, &type, &name[0]);
		name[maxNameLength - 1] = 0;

		if (nameLength == 0)
			continue;

		GLint oldLoc = glGetAttribLocation(oldProgID, &name[0]);

		if (oldLoc < 0)
			continue;

		glBindAttribLocation(newProgID, oldLoc, &name[0]);
	}
}
예제 #10
0
void ShaderProgram::printActiveAttributes() const
{
  GLint nAttribs;

  glGetProgramiv(m_programID, GL_ACTIVE_ATTRIBUTES, &nAttribs);
  GLint size; GLenum type;
  GLsizei l;
  char name[256];
  for (int i=0; i < nAttribs; ++i)
  {
    glGetActiveAttrib(m_programID, i, 256, &l, &size, &type, name);
    std::cerr << "Attribute"<<i<<":\""<<name<<"\" Size:"<<size<<" Type:";
    switch(type)
    {
    case GL_FLOAT: std::cerr << "GL_FLOAT\n"; break;
    case GL_FLOAT_VEC2: std::cerr << "GL_FLOAT_VEC2\n"; break;
    case GL_FLOAT_VEC3: std::cerr << "GL_FLOAT_VEC3\n"; break;
    case GL_FLOAT_VEC4: std::cerr << "GL_FLOAT_VEC4\n"; break;
    case GL_FLOAT_MAT2: std::cerr << "GL_FLOAT_MAT2\n"; break;
    case GL_FLOAT_MAT3: std::cerr << "GL_FLOAT_MAT3\n"; break;
    case GL_FLOAT_MAT4: std::cerr << "GL_FLOAT_MAT4\n"; break;
    default: std::cerr << "UNKNOWN\n";
    }
  }
}
예제 #11
0
파일: glescustom.cpp 프로젝트: Qard/jsgame
Handle<Value> GLESglGetActiveAttribCallback(const Arguments& args) {
	if (args.Length() != 2)
		return v8::Undefined();

	unsigned program = args[0]->Uint32Value();
	unsigned index = args[1]->Uint32Value();

	char name[256];
	int length = 0;
	int size = 0;
	unsigned type = 0;

	glGetActiveAttrib((GLuint)program,
		(GLuint)index,
		(GLsizei)sizeof(name),
		(GLsizei*)&length,
		(GLint*)&size,
		(GLenum*)&type,
		(GLchar*)name);

	Handle<Object> ans = Object::New();
	ans->Set(String::New("type"), Uint32::New(type));
	ans->Set(String::New("size"), Integer::New(size));
	ans->Set(String::New("name"), String::New(name, length));

	return ans;
}
예제 #12
0
/*
 * Find the given attribute size then, check if the passed expected size
 * is equal to the actual size.
 */
bool
getAttribLocTest(GLint program, int active_attribs, int max_name_length,
		char *attrib_name, int expected_size)
{
	bool pass = true;
	int size = -1;
	GLenum type = GL_NONE;
	char *name = malloc(max_name_length-1);

	int i;
	for(i = 0; i < active_attribs; i++) {
		glGetActiveAttrib(program, i, max_name_length,
				  NULL, &size, &type, name);

		if(strcmp(attrib_name, name) == 0) {
			break;
		}
	}

	/* Check if no attrib was found */
	if(i == active_attribs) {
		pass = false;
		printf("Attribute '%s' not found\n", attrib_name);
	}

	/* Check for non-matching sizes */
	if(size != expected_size) {
		pass = false;
		printf("Attribute '%s': size %d; expected %d\n",
			name, size, expected_size);
	}

	return pass;
}
예제 #13
0
void
ShaderAPITest::test_attrib_size_type1(const char *glslType, GLenum glType, const char *el)
{
	char buffer[1024];
	GLuint program;
	GLint active, i;

	//printf("  Running subtest %s\n", glslType);
	//fflush(stdout);
	sprintf(buffer, "#version 120\nattribute %s m;\nvoid main() { gl_Position[0] = m%s; }\n",
			glslType, el);

	program = make_program(buffer, NULL);
	glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active);
	assert_no_error();
	for (i = 0; i < active; i++) {
		GLint size = -1;
		GLenum type = 0;
		glGetActiveAttrib(program, i, sizeof(buffer), NULL,
							   &size, &type, buffer);
		assert_no_error();
		assert(type == glType);
		assert(size == 1);
		if (strncmp(buffer, "m", 1) == 0)
			break;
	}
	assert(i < active); /* Otherwise the compiler optimised it out */
}
예제 #14
0
bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info)
{
    if (!program) {
        synthesizeGLError(INVALID_VALUE);
        return false;
    }

    makeContextCurrent();

    GLint maxLength = 0;
    glGetProgramiv(program, GraphicsContext3D::ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength);

    GLchar* name = (GLchar*) fastMalloc(maxLength);
    GLsizei nameLength = 0;
    GLint size = 0;
    GLenum type = 0;

    glGetActiveAttrib(program, index, maxLength, &nameLength, &size, &type, name);

    if (!nameLength) {
        fastFree(name);
        return false;
    }

    info.name = String(name, nameLength);
    info.type = type;
    info.size = size;

    fastFree(name);
    return true;
}
예제 #15
0
파일: Program.cpp 프로젝트: dcbishop/dglw
AttributeList Program::getActiveAttributes() const {
   AttributeList al;

   // Get the number of active attributes
   GLint num_attributes;
   getProgram(Program::ActiveAttributes, &num_attributes);

   // The the maximum size of the attribe names
   GLsizei max_name_length;
   getProgram(Program::ActiveAttributeMaxLength, &max_name_length);

   GLsizei length;
   std::vector<GLchar> name(max_name_length);

   for(int index = 0; index < num_attributes; index++) {
      AttributeInfo ai;

      // Retrive atribute data and store it in the info struct
      ai.index = index;
      glGetActiveAttrib(getProgramId(),
         index,
         name.size(),
         &length,
         &ai.size,
         &ai.type,
         &name[0]);
      ai.name = std::string(&name[0], length);

      al.push_back(ai);
   }
   return al;
}
예제 #16
0
/** Get list of attribs used in the program */
GLuint
GetAttribs(GLuint program, struct attrib_info attribs[])
{
    GLint n, max, i;

    glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &n);
    glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max);

    for (i = 0; i < n; i++) {
        GLint size, len;
        GLenum type;
        char name[100];

        glGetActiveAttrib(program, i, 100, &len, &size, &type, name);

        attribs[i].name = strdup(name);
        attribs[i].size = size;
        attribs[i].type = type;
        attribs[i].location = glGetAttribLocation(program, name);
    }

    attribs[i].name = NULL; /* end of list */

    return n;
}
void CL_OpenGLProgramObjectProvider::fetch_attributes() const
{
    if (!cached_attribs.empty())
        return;

    CL_OpenGL::set_active();

    GLint count = 0;
    glGetProgramiv(handle, GL_ACTIVE_ATTRIBUTES, &count);
    GLint name_size = 0;
    glGetProgramiv(handle, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_size);
    GLchar *name = new GLchar[name_size+1];
    name[name_size] = 0;
    for (int i=0; i<count; i++)
    {
        GLsizei length = 0;
        GLint size = 0;
        GLenum type = 0;
        name[0] = 0;
        glGetActiveAttrib(handle, i, name_size, &length, &size, &type, name);
        CL_String attrib_name = CL_StringHelp::local8_to_text(CL_StringRef8(name, length, false));

        int loc = glGetAttribLocation(handle, CL_StringHelp::text_to_local8(name).c_str());
        CL_ProgramAttribute attribute(attrib_name, size, type, loc);
        cached_attribs.push_back(attribute);
    }
    delete [] name;
}
예제 #18
0
void Shader::ShaderProgram::addActiveAttributesFromProgram() {
    // Length of the longest variable name
    GLint maxLength;

    // Number of uniform variables
    GLint attributeCount;

    // Get the number of uniforms, and the length of the longest name.
    glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength);
    glGetProgramiv(glShaderProgramObject(), GL_ACTIVE_ATTRIBUTES, &attributeCount);

    GLchar* name = (GLchar *) System::malloc(maxLength * sizeof(GLchar));
    
    // Get the sizes, types and names
    if (maxLength > 0) { // If the names are blank, don't try to get them.
        // Loop over glGetActiveAttribute and store the results away.
        for (GLuint i = 0; i < (GLuint)attributeCount; ++i) {   
            AttributeDeclaration d;
            glGetActiveAttrib(glShaderProgramObject(), i, maxLength, NULL, &d.elementNum, &d.type, name); 
            d.location = glGetAttribLocation(glShaderProgramObject(), name);

            const String n(name);
            // Ignore empty and incorrect variables, which are occasionally returned by the driver.
            const bool bogus = ((d.location == -1) && n.empty()) ||
                beginsWith(n, "_main") || beginsWith(n, "_noset_");
            if (! bogus) {
                d.name = n;
                debugAssert(!attributeDeclarationTable.containsKey(n));
                attributeDeclarationTable.set(name, d);
            }
        }
    }
    System::free(name);
    name = NULL;
}
예제 #19
0
GLvoid Shader::fetchAttributes()
{
	GLint   iParams    = 0;
	GLsizei iMaxLength = 0;
	GLint   iSize      = 0;
	GLint   iWritten   = 0;
	GLenum  eType      = 0;
	GLchar* cpName     = NULL;
	//GLint   iLocation  = 0;

	glGetProgramiv(uiProgramID, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &iMaxLength);
	glGetProgramiv(uiProgramID, GL_ACTIVE_ATTRIBUTES, &iParams);
	iAttributeSize = iParams;
	cpName = new GLchar[iMaxLength];
	pAttributeNames = new std::string[iParams];
	pAttributeLocation = new GLint[iParams];
	for(GLint i = 0; i < iParams; ++i)
	{
		glGetActiveAttrib(uiProgramID, i, iMaxLength, &iWritten, &iSize,
			&eType, cpName);
		pAttributeLocation[i] = glGetAttribLocation(uiProgramID, cpName);
		pAttributeNames[i] = cpName;
		mapAttribute[pAttributeNames[i]] = pAttributeLocation[i];
		/*iLocation = glGetAttribLocation(uiProgramID, cpName);
		mapAttribute [iLocation] = cpName;*/
	}
}
예제 #20
0
파일: ogl_shader.cpp 프로젝트: Kingwl/ray
void
OGLShaderObject::_initActiveAttribute() noexcept
{
	GLint numAttribute = 0;
	GLint maxAttribute = 0;

	glGetProgramiv(_program, GL_ACTIVE_ATTRIBUTES, &numAttribute);
	glGetProgramiv(_program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribute);

	if (numAttribute)
	{
		auto nameAttribute = std::make_unique<GLchar[]>(maxAttribute + 1);
		nameAttribute[maxAttribute] = 0;

		for (GLint i = 0; i < numAttribute; ++i)
		{
			GLint size;
			GLenum type;

			glGetActiveAttrib(_program, (GLuint)i, maxAttribute, GL_NONE, &size, &type, nameAttribute.get());
			GLint location = glGetAttribLocation(_program, nameAttribute.get());

			auto attrib = std::make_shared<ShaderAttribute>();
			attrib->setName(nameAttribute.get());
			attrib->setLocation(location);

			_activeAttributes.push_back(attrib);
		}
	}
}
예제 #21
0
//  interface WebGLActiveInfo {
//      readonly attribute GLint size;
//      readonly attribute GLenum type;
//      readonly attribute DOMString name;
// WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index);
JSBool JSB_glGetActiveAttrib(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2( argc == 2, cx, JS_FALSE, "Invalid number of arguments" );
    jsval *argvp = JS_ARGV(cx,vp);
    JSBool ok = JS_TRUE;
    uint32_t arg0, arg1;

    ok &= jsval_to_uint( cx, *argvp++, &arg0 );
    ok &= jsval_to_uint( cx, *argvp++, &arg1 );
    JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");

    GLsizei length;
    glGetProgramiv(arg0, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &length);
    GLchar* buffer = new GLchar[length];
    GLint size = -1;
    GLenum type = -1;

    glGetActiveAttrib(arg0, arg1, length, NULL, &size, &type, buffer);

    jsval retval = JSVAL_VOID;

    JSObject *object = JS_NewObject(cx, NULL, NULL, NULL );
    JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error creating JS Object");

    if (!JS_DefineProperty(cx, object, "size", INT_TO_JSVAL(size), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ||
        !JS_DefineProperty(cx, object, "type", INT_TO_JSVAL(type), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ||
        !JS_DefineProperty(cx, object, "name", charptr_to_jsval(cx, buffer), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) )
        return JS_FALSE;

    retval = OBJECT_TO_JSVAL(object);

    JS_SET_RVAL(cx, vp, retval);
    CC_SAFE_DELETE_ARRAY(buffer);
    return JS_TRUE;
}
bool WebGraphicsContext3DDefaultImpl::getActiveAttrib(WebGLId program, unsigned long index, ActiveInfo& info)
{
    if (!program) {
        synthesizeGLError(GL_INVALID_VALUE);
        return false;
    }
    GLint maxNameLength = -1;
    glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameLength);
    if (maxNameLength < 0)
        return false;
    GLchar* name = 0;
    if (!tryFastMalloc(maxNameLength * sizeof(GLchar)).getValue(name)) {
        synthesizeGLError(GL_OUT_OF_MEMORY);
        return false;
    }
    GLsizei length = 0;
    GLint size = -1;
    GLenum type = 0;
    glGetActiveAttrib(program, index, maxNameLength,
                      &length, &size, &type, name);
    if (size < 0) {
        fastFree(name);
        return false;
    }
    info.name = WebString::fromUTF8(name, length);
    info.type = type;
    info.size = size;
    fastFree(name);
    return true;
}
예제 #23
0
//--------------------------------------------------------------
void ofShader::printActiveAttributes()  const{
	GLint numAttributes = 0;
	glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &numAttributes);
	ofLogNotice("ofShader") << numAttributes << " attributes";
	
	GLint attributeMaxLength = 0;
	glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attributeMaxLength);
	
	GLint count = -1;
	GLenum type = 0;
	GLchar* attributeName = new GLchar[attributeMaxLength];
	stringstream line;
	for(GLint i = 0; i < numAttributes; i++) {
		GLsizei length;
		glGetActiveAttrib(program, i, attributeMaxLength, &length, &count, &type, attributeName);
		line << " [" << i << "] ";
		for(int j = 0; j < length; j++) {
			line << attributeName[j];
		}
		line << " @ index " << getAttributeLocation(attributeName);
		ofLogNotice("ofShader") << line.str();
		line.str("");
	}
	delete [] attributeName;
}
예제 #24
0
std::vector<ShaderVariableInfo> ShaderFactory::get_attribute_infos(const unsigned int program)
{
	std::vector<ShaderVariableInfo> attribute_infos;
	std::vector<char> name_buffer;

	int active_attributes = 0;
	glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);
	attribute_infos.reserve(active_attributes);
	
	int max_attribute_name_length = 0;
	glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_attribute_name_length);
	name_buffer.assign(max_attribute_name_length+1, '\0');

	for (int i = 0; i < active_attributes; ++i)
	{
		int name_length = 0;
		int size = 0;
		GLenum type = 0;
		
		glGetActiveAttrib(program, i, name_buffer.size(), &name_length, &size, &type, name_buffer.data());

		std::string name(name_buffer.begin(), name_buffer.begin() + name_length);

		//if (name.compare(0, 3, "gl_") != 0)
		{
			// We do not add uniform values that can not be modified by glUniform* og glProgramUniform*

			attribute_infos.emplace_back(name, type, size, glGetAttribLocation(program, name.c_str()));
		}
	}

	return attribute_infos;
}
예제 #25
0
void OGLShader::getActiveAttributeList() {
    const i32 numAtttibs( getActiveParam( m_shaderprog, GL_ACTIVE_ATTRIBUTES ) );
    if ( numAtttibs < 1 ) {
        return;
    }
    
    for ( i32 i = 0; i < numAtttibs; i++ ) {
        GLint actual_length( 0 ), size( 0 );
        GLenum type;
        c8 name[ MaxLen ];
        glGetActiveAttrib( m_shaderprog, i, MaxLen, &actual_length, &size, &type, name );
        if ( size > 1 ) {
            for ( i32 attribIdx = 0; attribIdx < size; attribIdx++ ) {
                ActiveParameter *attribParam = new ActiveParameter;
                std::stringstream stream;
                stream << name << attribIdx;
                strncpy( attribParam->m_name, stream.str().c_str(), stream.str().size() );
                attribParam->m_location = glGetAttribLocation( m_shaderprog, attribParam->m_name );
                m_attribParams.add( attribParam );
            }
        } else {
            ActiveParameter *attribParam = new ActiveParameter;
            strncpy( attribParam->m_name, name, strlen( name ) );
            attribParam->m_location = glGetAttribLocation( m_shaderprog, attribParam->m_name );
            m_attribParams.add( attribParam );
        }
    }
}
예제 #26
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL20_nglGetActiveAttrib(JNIEnv *env, jclass clazz, jint program, jint index, jint maxLength, jlong length, jlong size, jlong type, jlong name, jlong function_pointer) {
	GLsizei *length_address = (GLsizei *)(intptr_t)length;
	GLint *size_address = (GLint *)(intptr_t)size;
	GLenum *type_address = (GLenum *)(intptr_t)type;
	GLchar *name_address = (GLchar *)(intptr_t)name;
	glGetActiveAttribPROC glGetActiveAttrib = (glGetActiveAttribPROC)((intptr_t)function_pointer);
	glGetActiveAttrib(program, index, maxLength, length_address, size_address, type_address, name_address);
}
예제 #27
0
파일: shader.cpp 프로젝트: bqqbarbhg/cold
std::string Shader::get_uniform_name(int index) const {
	char buffer[64];
	int len;
	GLint di;
	GLenum de;
	glGetActiveAttrib(gl_program, index, sizeof(buffer), &len, &di, &de, buffer);
	return std::string(buffer, len);
}
예제 #28
0
void CausticsRender::InitGeometry(){
	stringstream vertex_shader_name;
	vertex_shader_name << "./" << PROJECT_NAME << "/refract.vert";
	stringstream fragment_shader_name;
	fragment_shader_name << "./" << PROJECT_NAME << "/refract.frag";
	string vt= vertex_shader_name.str();
	string fg = fragment_shader_name.str();
	mProgram = CreateShaderFromFile(vt, fg);
	glUseProgram(mProgram);

	int total = -1;
	glGetProgramiv(mProgram, GL_ACTIVE_ATTRIBUTES, &total);
	for (int i = 0; i<total; ++i) {
		int name_len = -1, num = -1;
		GLenum type = GL_ZERO;
		char name[100];
		glGetActiveAttrib(mProgram, GLuint(i), sizeof(name) - 1, &name_len, &num, &type, name);
		name[name_len] = 0;
		cout << "name:" << name << endl;
	}
	int vploc = glGetAttribLocation(mProgram, "vPosition");
	int nloc = glGetAttribLocation(mProgram, "normal");

	mMatrixLocation = glGetUniformLocation(mProgram, "uModelViewProj");
	mCubeSampUniform = glGetUniformLocation(mProgram, "cubemap");
	glUniform1i(mCubeSampUniform, 0);


	mModel.LoadPlyData(mFileName.c_str());
	glGenVertexArrays(1, &mPlayerVao);//新しいvaoが作られ、名前が割り振られる。
	glBindVertexArray(mPlayerVao);//vaoがアクティブになる
	
	

	GLuint ebo = 0;
	glGenBuffers(1, &ebo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)*mModel.mTriangleNum * 3, mModel.m_Indices, GL_STATIC_DRAW);

	GLuint vbo[2];
	glGenBuffers(2, vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vec3<float>)*mModel.mVertNum, mModel.m_Verts, GL_STATIC_DRAW);

	
	
	glVertexAttribPointer(vploc, 3, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(vploc);
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
	
	glBufferData(GL_ARRAY_BUFFER, sizeof(vec3<float>)*mModel.mVertNum, mModel.m_Normals, GL_STATIC_DRAW);
	glVertexAttribPointer(nloc, 3, GL_FLOAT, GL_TRUE, 0, NULL);
	glEnableVertexAttribArray(nloc);
	
	miffy::GetGLError("InitGeometry");
	
}
예제 #29
0
Attribute::Attribute(GLuint program_id,GLuint index) {
	char * buffer = new char[128];
	GLsizei length = 0;
	glGetActiveAttrib(program_id,index,128,&length,&size,&type,buffer);
	name = std::string(buffer,length);
	this->index = glGetAttribLocation(program_id,name.c_str());
	delete[] buffer;

}
예제 #30
0
		void Context::linkProgram( ProgramObj *p ) const
		{
			glLinkProgram( p->mHandle );

			GLint linked;
			glGetProgramiv( p->mHandle, GL_LINK_STATUS, &linked );

			p->mIsLinked = ( linked == 1 );

			GLint logSize;
			glGetProgramiv( p->mHandle, GL_INFO_LOG_LENGTH, &logSize );
			if ( logSize > 0 )
			{
				char *buffer = new char[ logSize ];
				glGetProgramInfoLog( p->mHandle, logSize, nullptr, buffer );
				p->mInfoLog = buffer;
				delete [] buffer;
			}

			std::cout << p->mInfoLog << std::endl;

			GLint numAttribs, maxAttribLength, attribLocation, numUniforms, maxUniformLength, uniformLocation, size;
			GLenum type;
			std::string attribName, uniformName;

			glGetProgramiv( p->mHandle, GL_ACTIVE_ATTRIBUTES, &numAttribs );
			glGetProgramiv( p->mHandle, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribLength );
			glGetProgramiv( p->mHandle, GL_ACTIVE_UNIFORMS, &numUniforms );
			glGetProgramiv( p->mHandle, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLength );

			char * buffer = new char[ max( maxAttribLength, maxUniformLength ) ];

			for ( int i=0; i<numAttribs; ++i )
			{
				glGetActiveAttrib( p->mHandle, i, maxAttribLength, nullptr, &size, &type, buffer );
				attribName = buffer;
				attribLocation = glGetAttribLocation( p->mHandle, buffer );
				//std::cout << "ATTRIBUTE " << attribName << " " << attribLocation << std::endl;

				p->mActiveAttributes[ attribName ] = ProgramObj::ActiveInput( attribLocation, size, type );
			}

			for ( int i=0; i<numUniforms; ++i )
			{
				glGetActiveUniform( p->mHandle, i, maxUniformLength, nullptr, &size, &type, buffer );
				uniformName = buffer;
				uniformLocation = glGetUniformLocation( p->mHandle, buffer );
				//std::cout << "UNIFORM: " << uniformName << " " << uniformLocation << " " << size << " " << type << std::endl;

				p->mActiveUniforms[ uniformName ] = ProgramObj::ActiveInput( uniformLocation, size, type );
			}

			delete [] buffer;
		}