Пример #1
0
static void initShader_phong ()
{
  /*if (! glutExtensionSupported("GL_ARB_vertex_program"))
    Fail("GL_ARB_vertex_program not available on this machine");
  if (! glutExtensionSupported("GL_ARB_fragment_program"))
    Fail("GL_ARB_fragment_program not available on this machine");*/

  glEnable(GL_VERTEX_PROGRAM_ARB);
  glEnable(GL_FRAGMENT_PROGRAM_ARB);

  glGenProgramsARB(3, Shader);

  glBindProgramARB(GL_VERTEX_PROGRAM_ARB, Shader[0]);
  glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(ShaderSrc[0]), ShaderSrc[0]);
  checkShader(0);

  glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, Shader[1]);
  glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(ShaderSrc[1]), ShaderSrc[1]);
  checkShader(1);

  /*glBindProgramARB(GL_VERTEX_PROGRAM_ARB, Shader[2]);
  glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(ShaderSrc[2]), ShaderSrc[2]);
  checkShader(2);*/

  glDisable(GL_VERTEX_PROGRAM_ARB);
  glDisable(GL_FRAGMENT_PROGRAM_ARB);
}
static void R_InitConverter( void )
{
	const GLubyte *pError;

	glGenProgramsARB( 1, &conv.vp );
	glBindProgramARB( GL_VERTEX_PROGRAM_ARB, conv.vp );
	glProgramStringARB( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		strlen( convVpCode ), convVpCode );

	pError = glGetString( GL_PROGRAM_ERROR_STRING_ARB );
	if( pError && pError[0] )
		__debugbreak();

	glBindProgramARB( GL_VERTEX_PROGRAM_ARB, 0 );

	glGenProgramsARB( 1, &conv.fp );
	glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, conv.fp );
	glProgramStringARB( GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		strlen( convFpCode ), convFpCode );

	pError = glGetString( GL_PROGRAM_ERROR_STRING_ARB );
	if( pError && pError[0] )
		__debugbreak();

	glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, 0 );
}
Пример #3
0
static void create_sphere_programs() {
    GLint errpos ;

    glGenProgramsARB(1, &sphere_vertex_program_id) ;
    glBindProgramARB(GL_VERTEX_PROGRAM_ARB,sphere_vertex_program_id) ;
    glProgramStringARB(
        GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
        (GLsizei)strlen(sphere_vertex_program_source), sphere_vertex_program_source
    ) ;
    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errpos) ;
    if(errpos != -1) {
        const char* s = (const char*)(glGetString(GL_PROGRAM_ERROR_STRING_ARB)) ;
        std::cerr << "vertex program ARB error" << ":" << errpos << ": " << s << std::endl ;
    }

    glGenProgramsARB(1, &sphere_fragment_program_id) ;
    glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB,sphere_fragment_program_id) ;
    glProgramStringARB(
        GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
        (GLsizei)strlen(sphere_fragment_program_source), sphere_fragment_program_source
    ) ;
    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errpos) ;
    if(errpos != -1) {
        const char* s = (const char*)(glGetString(GL_PROGRAM_ERROR_STRING_ARB)) ;
        std::cerr << "fragment program ARB error" << ":" << errpos << ": " << s << std::endl ;
    }

}
Пример #4
0
void PaletteRenderer::DataItem::updateTextureCache(const VolumeRenderer* renderer,int majorAxis)
	{
	/* Call the base class method: */
	VolumeRenderer::DataItem::updateTextureCache(renderer,majorAxis);
	
	if(renderingPath==FragmentProgram)
		{
		if(setParameters)
			{
			/* Upload the appropriate fragment program: */
			if(has3DTextures&&renderer->getRenderingMode()==VIEW_PERPENDICULAR)
				{
				if(renderer->getTextureFunction()==REPLACE)
					glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,strlen(fp3),fp3);
				else
					glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,strlen(fp4),fp4);
				}
			else
				{
				if(renderer->getTextureFunction()==REPLACE)
					glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,strlen(fp1),fp1);
				else
					glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,strlen(fp2),fp2);
				}
			if(glGetError()==GL_INVALID_OPERATION)
				{
				GLint errorPos;
				glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB,&errorPos);
				const GLubyte* error=glGetString(GL_PROGRAM_ERROR_STRING_ARB);
				Misc::throwStdErr("Fragment program error \"%s\" at position %d",error,errorPos);
				}
			}
		}
	else if(renderingPath==PalettedTexture)
		{
		/* Check if the color map needs to be uploaded: */
		const PaletteRenderer* paletteRenderer=static_cast<const PaletteRenderer*>(renderer);
		
		/*************************************************************************
		Another bug in SGI's OpenGL implementation: Though color maps are treated
		as a texture object resource, they are not always installed when a texture
		object is bound. Thus, we have to upload them manually everytime we bind;
		painful and sloow.
		*************************************************************************/
		
		uploadColorMap=false;
		#ifndef __SGI_IRIX__
		if(uploadData||cachedColorMapVersion!=paletteRenderer->colorMapVersion)
		#endif
			{
			cachedColorMapVersion=paletteRenderer->colorMapVersion;
			textureCacheValid=false;
			uploadColorMap=!paletteRenderer->sharePalette;
			}
		}
	}
Пример #5
0
static void Init( void )
{
   /* scale of 10.0 gives me a visible result on nv hardware.
    */
   static const char *modulate2D =
      "!!ARBfp1.0\n"
      "TEMP R0;\n"
      "MUL R0, fragment.position.z, {10.0}.x;\n"
      "MOV result.color, R0; \n"
      "END"
      ;
   GLuint modulateProg;

   if (!GLEW_ARB_fragment_program) {
      printf("Error: GL_ARB_fragment_program not supported!\n");
      exit(1);
   }
   printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));

   /* Setup the fragment program */
   glGenProgramsARB(1, &modulateProg);
   glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
   glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(modulate2D), (const GLubyte *)modulate2D);

   printf("glGetError = 0x%x\n", (int) glGetError());
   printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
          (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));

   glEnable(GL_FRAGMENT_PROGRAM_ARB);

   glClearColor(.3, .3, .3, 0);
}
Пример #6
0
static GLuint
_arb_program_from_string(GLenum kind, int shader_flags, char const * source, size_t source_length, char * * out_error_message)
{
    GLuint program;
    glGenProgramsARB(1, &program);
    glBindProgramARB(kind, program);
    glProgramStringARB(kind, GL_PROGRAM_FORMAT_ASCII_ARB, source_length, source);

    GLint error_position;
    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_position);
    if(error_position >= 0) {
        const GLubyte * error_string = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
        asprintf(out_error_message, "Error in program at position %d: %s", error_position, error_string);
        goto error;
    }

    glBindProgramARB(kind, 0);

    return program;

error:
    glBindProgramARB(kind, 0);
    glDeleteProgramsARB(1, &program);
    return 0;
}
Пример #7
0
/**
 * The GL_ARB_fragment_shader spec, issue 23 says:
 *   (23) What is the result of a sample from an incomplete texture? 
 *   The definition of texture completeness can be found in section 3.8.9 
 *   of the core GL spec. 
 *
 *   RESOLVED: The result of a sample from an incomplete texture is the 
 *   constant vector (0,0,0,1).
 *
 * In this test we swizzle RGBA->ABGR so we don't need to worry if the
 * framebuffer has an alpha channel.
 */
GLboolean
test_arb_fp(void)
{
	static const char *fragProgramText =
		"!!ARBfp1.0\n"
		"TEMP t1;\n"
		"TEX t1, fragment.texcoord[0], texture[0], 2D;\n"
		"MOV result.color, t1.abgr;\n"
		"END\n";
	static const GLfloat expected[4] = { 1.0, 0.0, 0.0, 0.0 };
	int pos = 1;
	GLboolean p;
	GLuint prog;

	glGenProgramsARB(1, &prog);
	glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
	glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,
			   GL_PROGRAM_FORMAT_ASCII_ARB,
			   strlen(fragProgramText),
			   (const GLubyte *) fragProgramText);

	glEnable(GL_FRAGMENT_PROGRAM_ARB);

	glColor3f(0, 1, 0);
	draw_rect(1);

	glDisable(GL_FRAGMENT_PROGRAM_ARB);
	glDeleteProgramsARB(1, &prog);

	p = probe_pos(pos, expected);
	if (!p)
		printf("  Testing ARB fragment program\n");
	return p;
}
Пример #8
0
static void Init( void )
{
   GLint errno;
   GLuint prognum;
   
   static const char *prog1 =
      "!!ARBvp1.0\n"
      "MOV  result.color, vertex.color;\n"
      "MOV  result.position, vertex.position;\n"
      "END\n";

   glGenProgramsARB(1, &prognum);
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		      strlen(prog1), (const GLubyte *) prog1);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }


   glEnableClientState( GL_VERTEX_ARRAY );
   glEnableClientState( GL_COLOR_ARRAY );
   glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
   glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );

}
static void Init( void )
{
   GLint errno;
   GLuint prognum;
   
   static const char *prog1 =
      "!!ARBvp1.0\n"
      "MOV  result.color, vertex.color;\n"
/*       "MOV  result.color, {0,0,0,1};\n"  */
      "MOV  result.position, vertex.position;\n"
      "END\n";


   glGenProgramsARB(1, &prognum);

   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		      strlen(prog1), (const GLubyte *) prog1);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      GLint errorpos;

      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   }
}
static void Init( void )
{
   static const char *modulate2D =
      "!!ARBfp1.0\n"
      "TEMP R0;\n"
      "DP4 result.color, fragment.color.xxxx, fragment.color; \n"
      "END"
      ;
   GLuint modulateProg;

   if (!glutExtensionSupported("GL_ARB_fragment_program")) {
      printf("Error: GL_ARB_fragment_program not supported!\n");
      exit(1);
   }
   printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));

   /* Setup the fragment program */
   glGenProgramsARB(1, &modulateProg);
   glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
   glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(modulate2D), (const GLubyte *)modulate2D);

   printf("glGetError = 0x%x\n", (int) glGetError());
   printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
          (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));

   glEnable(GL_FRAGMENT_PROGRAM_ARB);

   glClearColor(.3, .3, .3, 0);
}
Пример #11
0
		FragmentProgram::FragmentProgram(istream &is)
		{
			if (!GL_ARB_fragment_program_initialized) {
				console::print(1, 0, 0, "Error(FragmentProgram): GL_ARB_fragment_program not initialized");
				return;
			}

			string program;

			char ch;
			while (is.get(ch)) program += ch;

			glGetError();
			glGenProgramsARB(1, &id);
			if (glGetError()) {
				console::print(1.0, 0.0, 0.0, "Could not generate FragmentProgram id!");
				return;
			}
			glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, id);
			glGetError();
			glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)program.size(), program.c_str());
			if (glGetError()) {
				console::print(1.0f, 0.0f, 0.0f, (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
			}

			// TODO: throw exception on error
		}
Пример #12
0
GLuint HCoreLoadFragmentProgramOpenGL_ASM(const char *filename)
{
	char filename_fullpath[256];
	sprintf(filename_fullpath, "%s%s", HCoreGetShaderPath(), filename);

	unsigned int size = 0;

	unsigned char *buffer = (unsigned char *) HCoreLoadBinaryStream(filename_fullpath, &size);
	if ( buffer==NULL )
	{
		return 0;
	}

	GLuint shader_id = 0;

	glGenProgramsARB(1, &shader_id);
    glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader_id );
	glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, size, buffer);
	if ( GL_INVALID_OPERATION == glGetError() )
	{
		GLint errPos;
		glGetIntegerv( GL_PROGRAM_ERROR_POSITION_ARB, &errPos );

		GLubyte *errString = (GLubyte *) glGetString(GL_PROGRAM_ERROR_STRING_ARB);
		fprintf( stderr, "error at position: %d\n%s\n", errPos, errString );
		glDeleteProgramsARB(1, &shader_id);
		shader_id = 0;
	}

	HCoreReleaseBinaryStream(buffer);

	return shader_id;
}
Пример #13
0
static void load_program(const char *prog, GLuint prognum)
{
   int a;	
   GLint errorpos, errno;
   
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(prog), (const GLubyte *) prog);

   assert(glIsProgramARB(prognum));
   errno = glGetError();
   printf("glGetError = %d\n", errno);
   if (errno != GL_NO_ERROR)
   {
      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
      printf("errorpos: %d\n", errorpos);
      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));

      for (a=-10; a<10; a++)
      {
         if ((errorpos+a < 0) || (errorpos+a >= strlen(prog))) continue;	      
         printf("%c", prog[errorpos+a]);
      }	  
      printf("\n");      
      exit(1);
   }
}
Пример #14
0
void
piglit_init(int argc, char **argv)
{
	static const char * program =
		"!!ARBvp1.0\n"
		"MOV result.color, vertex.color;\n"
		"MOV result.position, vertex.position;\n"
		"END\n";
	GLuint program_no;

	piglit_require_extension("GL_ARB_draw_elements_base_vertex");
	piglit_require_extension("GL_ARB_vertex_program");
	glGenProgramsARB(1, &program_no);
	glBindProgramARB(GL_VERTEX_PROGRAM_ARB, program_no);
	glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
			strlen(program), program);
	assert(glIsProgramARB(program_no));

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(vertices[0]), vertices);
	glEnableClientState(GL_COLOR_ARRAY);
	glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
}
Пример #15
0
bool CVertexProgram::Load(const char* pCodeString)
{
    m_uiProgram = 0;
    m_bLoaded = false;

    // load vertex programs
    if (extgl_Extensions.ARB_vertex_program)
    {
        glGenProgramsARB(1, &m_uiProgram);
        glBindProgramARB(GL_VERTEX_PROGRAM_ARB, m_uiProgram);
        glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(pCodeString), pCodeString);

        const GLubyte* pError = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
        if (strlen((char*) pError) > 0)
        {
            fprintf(stderr, "Failed to compile vertex shader (%s)\n", pError);
            m_uiProgram = 0;
        }
        else
        {
            fprintf(stderr, "successfully loaded vertex program\n");
            m_bLoaded = true;
        }
    }
    else
    {
        fprintf(stderr, "ARB_vertex_program extension not found (hardware or driver doesn't support hardware vertex shaders)\n");
        m_uiProgram = 0;
    }

    return m_bLoaded;
}
Пример #16
0
static unsigned int LoadProgram(GLenum target, const char* filename, const char* program_type)
{
	GLuint ret = 0;

	if (!GLEW_ARB_vertex_program) {
		return ret;
	}
	if (target == GL_FRAGMENT_PROGRAM_ARB && !GLEW_ARB_fragment_program) {
		return ret;
	}

	CFileHandler file(std::string("shaders/") + filename);
	if (!file.FileExists ()) {
		char c[512];
		SNPRINTF(c, 512, "[myGL::LoadProgram] Cannot find %s-program file '%s'", program_type, filename);
		throw content_error(c);
	}

	int fSize = file.FileSize();
	char* fbuf = new char[fSize + 1];
	file.Read(fbuf, fSize);
	fbuf[fSize] = '\0';

	glGenProgramsARB(1, &ret);
	glBindProgramARB(target, ret);
	glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, fSize, fbuf);

	if (CheckParseErrors(target, filename, fbuf)) {
		ret = 0;
	}

	delete[] fbuf;
	return ret;
}
Пример #17
0
uint LoadFragmentProgram(string fn)
{
	int len;
	char* buf=LoadTextFile (fn, len);
	if(!buf) return 0;

	uint ret;
	glGenProgramsARB( 1, &ret );
	glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB,ret);

	glProgramStringARB( GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,len,buf);

	if ( GL_INVALID_OPERATION == glGetError() )
	{
		// Find the error position
		GLint errPos;
		glGetIntegerv( GL_PROGRAM_ERROR_POSITION_ARB,&errPos );
		// Print implementation-dependent program
		// errors and warnings string.
		const GLubyte *errString=glGetString( GL_PROGRAM_ERROR_STRING_ARB);
		fltk::message("Error at position %d when loading fragment program file %s:\n%s",errPos,fn.c_str(),errString);
		return 0;
	}
	return ret;
}
Пример #18
0
static void initShaders ()
{
  int err;	
  char* FragSrc = textFileRead(FragLoc);
  if (FragSrc == NULL){
	  printf("ERROR:Src Prog is %s\n",FragSrc);
   }
  if (! glutExtensionSupported("GL_ARB_vertex_program"))
    Fail("GL_ARB_vertex_program not available on this machine");
  if (! glutExtensionSupported("GL_ARB_fragment_program"))
    Fail("GL_ARB_fragment_program not available on this machine");
  
  
  /* Fragment shader */
  glEnable(GL_FRAGMENT_PROGRAM_ARB);
  glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, &FragShader);


  glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  			strlen(FragSrc), FragSrc);
  glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err);
  if (err >= 0)
    printf("Error in fragment shader %s\n",
    		glGetString(GL_PROGRAM_ERROR_STRING_ARB));

  free(FragSrc);
}
Пример #19
0
bool Viewer::loadVertexProgram()
{
	glGenProgramsARB( 1, &m_vertexProgramId );
	
	glBindProgramARB( GL_VERTEX_PROGRAM_ARB, m_vertexProgramId );
	
	glProgramStringARB( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
		strlen(vertexProgramStr), vertexProgramStr );
	
	if ( GL_INVALID_OPERATION == glGetError() )
	{
		// Find the error position
		GLint errPos;
		glGetIntegerv( GL_PROGRAM_ERROR_POSITION_ARB,
			&errPos );
		// Print implementation-dependent program
		// errors and warnings string.
		const unsigned char *errString = glGetString( GL_PROGRAM_ERROR_STRING_ARB);
		fprintf( stderr, "error at position: %d\n%s\n",
			errPos, errString );
		return false;
	}
	
	
	glBindProgramARB( GL_VERTEX_PROGRAM_ARB, 0 );

	return true;
	
	
}
Пример #20
0
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{
	// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
	GLenum err = GL_REPORT_ERROR();
	if (err != GL_NO_ERROR)
	{
		ERROR_LOG(VIDEO, "glError %08x before VS!", err);
	}

#if defined HAVE_CG && HAVE_CG
	char stropt[64];
	sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions);
	const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
	CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", opts);
	if (!cgIsProgram(tempprog)) {
        if (s_displayCompileAlert) {
            PanicAlert("Failed to create vertex shader");
            s_displayCompileAlert = false;
        }
        cgDestroyProgram(tempprog);
		ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
		ERROR_LOG(VIDEO, "%s", pstrprogram);
		return false;
	}

	if (cgGetError() != CG_NO_ERROR)
	{
		WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
		WARN_LOG(VIDEO, "%s", pstrprogram);
	}

	// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
	// It SHOULD not have any nasty side effects though - but you never know...
	char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
	char *plocal = strstr(pcompiledprog, "program.local");
	while (plocal != NULL) {
		const char* penv = "  program.env";
		memcpy(plocal, penv, 13);
		plocal = strstr(plocal + 13, "program.local");
	}
	glGenProgramsARB(1, &vs.glprogid);
	SetCurrentShader(vs.glprogid);

	glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);	
	err = GL_REPORT_ERROR();
	if (err != GL_NO_ERROR) {
		ERROR_LOG(VIDEO, "%s", pstrprogram);
		ERROR_LOG(VIDEO, "%s", pcompiledprog);
	}

	cgDestroyProgram(tempprog);
#endif

#if defined(_DEBUG) || defined(DEBUGFAST) 
	vs.strprog = pstrprogram;
#endif

	return true;
}
Пример #21
0
enum piglit_result
piglit_display(void)
{
	static const char *fp_source =
		"!!ARBfp1.0\n"
		"TEX result.color, fragment.texcoord[0], texture[1], 2D;\n"
		"END\n";
	bool pass = true;
	GLuint tex;
	GLuint prog;

	texrect_w = piglit_width / 4 / 2;
	texrect_h = piglit_height / 2;

	glGenProgramsARB(1, &prog);
	glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
	glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,
			   GL_PROGRAM_FORMAT_ASCII_ARB,
			   strlen(fp_source),
			   (const GLubyte *) fp_source);

	glEnable(GL_FRAGMENT_PROGRAM_ARB);

	glActiveTexture(GL_TEXTURE1);
	tex = piglit_rgbw_texture(GL_RGBA, 2, 2, false, false,
				  GL_UNSIGNED_NORMALIZED);

	/* Given that the failure mode we had that led to this test
	 * being written was that the sampler state read was
	 * pseudo-random, go through several statechanges on the
	 * sampler to make sure we're reliably getting our sampler
	 * state.
	 */
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	piglit_draw_rect_tex(-1, -1, 0.5, 2,
			     0, 0, 1, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	piglit_draw_rect_tex(-0.5, -1, 0.5, 2,
			     0, 0, 1, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	piglit_draw_rect_tex(0, -1, 0.5, 2,
			     0, 0, 1, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	piglit_draw_rect_tex(0.5, -1, 0.5, 2,
			     0, 0, 1, 1);

	pass = pass && test_nearest(piglit_width * 0 / 4);
	pass = pass && test_linear(piglit_width * 1 / 4);
	pass = pass && test_nearest(piglit_width * 2 / 4);
	pass = pass && test_linear(piglit_width * 3 / 4);

	piglit_present_results();

	glDeleteTextures(1, &tex);
	glDisable(GL_FRAGMENT_PROGRAM_ARB);
	glDeleteProgramsARB(1, &prog);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Пример #22
0
void ATITShader::resurrect()
{
   glEnable(GL_VERTEX_PROGRAM_ARB);
   glEnable(GL_TEXT_FRAGMENT_SHADER_ATI);
   
   glGenProgramsARB(1, &mVertexProgram);
   glGenProgramsARB(1, &mFragmentProgram);
   
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, mVertexProgram);
   glBindProgramARB(GL_TEXT_FRAGMENT_SHADER_ATI, mFragmentProgram);
   
   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, mVertexSourceStringLength, mVertexSourceString);
   glProgramStringARB(GL_TEXT_FRAGMENT_SHADER_ATI, GL_PROGRAM_FORMAT_ASCII_ARB, mPixelSourceStringLength, mPixelSourceString);
   
   glDisable(GL_VERTEX_PROGRAM_ARB);
   glDisable(GL_TEXT_FRAGMENT_SHADER_ATI);
}
Пример #23
0
int buildprog(const char *prog,bool vtxorfrg)
   {
   GLuint progid=0;

#if defined(GL_ARB_vertex_program) && defined(GL_ARB_fragment_program)
   GLint errorPos,isNative;

   glGenProgramsARB(1,&progid);

   if (vtxorfrg)
      {
      glBindProgramARB(GL_VERTEX_PROGRAM_ARB,progid);
      glProgramStringARB(GL_VERTEX_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,strlen(prog),prog);
      }
   else
      {
      glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB,progid);
      glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_FORMAT_ASCII_ARB,strlen(prog),prog);
      }

   glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB,&errorPos);
   glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB,&isNative);

   if (errorPos==0)
      {
      WARNMSG("shader programs unavailable");
      WARNMSG((char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
      ERRORMSG();
      }
   else
      {
      if (errorPos!=-1)
         {
         WARNMSG((char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
         ERRORMSG();
         }
      if (isNative!=1) WARNMSG("shader program non-native");
      }
#endif

   return(progid);
   }
Пример #24
0
bool CgUtil::MakeHaloShader(int pow) {

    char fp[10096];

    sprintf(fp,"\
!!ARBfp1.0\n\
\n\
ATTRIB data   = fragment.texcoord;  \n\
  \n\
TEMP tmp,tmp2,tmp3, t,t0,t1,t2,nor,n,nabs,nsign,disp,res,depth,pos,\n\
     lighting;  \n\
\n\
MOV nor, data;  \n\
MUL tmp, data, data;  \n\
ADD tmp2.x, tmp.x, tmp.y;\n\
ADD tmp2.z, -tmp2.x, 1;\n\
KIL tmp2.z;\n\
\n\
MAD tmp2.x, -data.z, tmp2.x, data.z;\n\
\n\
#TEST!\n\
#ADD tmp2.x, tmp2.x, %10.8f;\n\
#CMP result.color, tmp2.x, {1,0,0,1}, {0,0,1,1};\n\
\n\
MUL tmp, fragment.position, {%14.12f, %14.12f, 0, 0};\n\
#MAD tmp, fragment.position, {0.5, 0.5, 0, 0}, {0.5, 0.5, 0, 0};\n\
TEX tmp.z, tmp, texture[1], 2D; # tmp.z = old depth \n\
ADD tmp.z, tmp.z, -fragment.position.z; \n\
MUL_SAT tmp.z, tmp.z, program.env[0].x; \n\
MUL tmp.z, tmp.z, tmp2.x; \n\
MUL tmp.z, tmp.z, tmp2.x;  # again for smoother edges\n\
", +P_halo_str-1,  1.0f/(1<<pow), 1.0f/(1<<pow) );

    if (P_halo_str<1.0) {
        sprintf(fp,"%sMUL tmp.z , tmp.z, %10.8f;\n",fp, P_halo_str );
    }
    if (!doingAlphaSnapshot)
        sprintf(fp,"%sMAD result.color, {0,0,0,1}, tmp.z, {%5.4f,%5.4f,%5.4f,0.0} ;\n",fp,P_halo_col,P_halo_col,P_halo_col);
    else {
        if (P_halo_col==1.0)  // white halo
            sprintf(fp,"%sMOV result.color, tmp.z;\n",fp);
        else
            sprintf(fp,"%sMUL result.color, {0,0,0,1}, tmp.z;\n",fp);
    }
    sprintf(fp,"%sEND\n",fp);




    glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(fp), fp);
//  printf("\n-------<fp HALO>--------\n%s",fp);
    if(!checkProgramError(fp)) return false;
    return true;
}
Пример #25
0
void CgUtil::LoadVertexHaloShader() {
    char vp[10096];

    sprintf(vp,"\
!!ARBvp1.0\n\
\n\
ATTRIB pos = vertex.position;\n\
ATTRIB dataA = vertex.texcoord[0];\n\
ATTRIB dataB = vertex.texcoord[1];\n\
\n\
");


    sprintf(vp,"%s\
\n\
PARAM  mat[4] = { state.matrix.mvp };\n\
PARAM  matP[4] = { state.matrix.projection };\n\
\n\
TEMP p,po, disp, dataout, tmp;\n\
\n\
# Transform by concatenation of the\n\
# MODELVIEW and PROJECTION matrices.\n\
DP4 p.x, mat[0], pos;\n\
DP4 p.y, mat[1], pos;\n\
DP4 p.z, mat[2], pos;\n\
DP4 p.w, mat[3], pos;\n\
#MOV p.w, 1; \n\
 \n\
MOV dataout, dataA;\n\
MOV dataout.z, dataB.y;\n\
", vp);

    sprintf(vp,"%s\
\n\
MUL disp, dataA, dataB.x; \n\
MUL disp, disp, program.env[0].x; \n\
#MUL disp.x, disp.x, matP[0].x;\n\
#MUL disp.y, disp.y, matP[1].y;\n\
MAD p, {1,1,0,0},  disp, p;\n\
", vp);


    sprintf(vp,"%sMOV result.position, p;\n",vp);

    sprintf(vp,"%sMOV result.texcoord, dataout;\n",vp);

    sprintf(vp,"%s\nEND\n", vp);

    glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(vp), vp);

    //printf("\n--------<vp ball>---------\n%s",vp);
    //if(!checkProgramError(vp)) return -1;
    //return true;
}
Пример #26
0
void GPUProgram::loadProgram(const std::string& code) const {
    switch (extension) {
    case NVIDIA:
        glLoadProgramNV(unit, glProgram, code.size(), (const unsigned char*)code.c_str());
        break;

    case ARB:
        glProgramStringARB(unit, GL_PROGRAM_FORMAT_ASCII_ARB, code.size(), code.c_str());
        break;
    }
}
Пример #27
0
//-------------------------------------------------------------
// ARBProgram::loadShader() load shader
//-------------------------------------------------------------    
bool ARBProgram::loadShader(char *source, CGLShader *shader){
    shader->setActive();
    shader->bind();
    glProgramStringARB (shader->getProgramType(), GL_PROGRAM_FORMAT_ASCII_ARB,
            strlen(source), source);
    
    if (glGetError () == GL_INVALID_OPERATION ){
        //String errorString = gl.glGetString ( GL.GL_PROGRAM_ERROR_STRING_ARB );
       // System.out.println("GPU shader error >> " + errorString);
        return false;
    }
    return true;
}
Пример #28
0
void
setup_arb_program()
{
	char vert[] =
		"!!ARBvp1.0\n"
		"OPTION ARB_position_invariant;\n"
		"MOV result.color, { 1.0, 1.0, 1.0, 1.0 };"
		"END";
	GLuint vert_prog;

	glGenProgramsARB(1, &vert_prog);
	glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vert_prog);
	glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
			   strlen(vert), vert);
	glEnable(GL_VERTEX_PROGRAM_ARB);
}
Пример #29
0
GLuint compileASMShader(GLenum program_type, const char *code)
{
    GLuint program_id;
    glGenProgramsARB(1, &program_id);
    glBindProgramARB(program_type, program_id);
    glProgramStringARB(program_type, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei) strlen(code), (GLubyte *) code);

    GLint error_pos;
    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
    if (error_pos != -1) {
        const GLubyte *error_string;
        error_string = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
        shrLog("Program error at position: %d\n%s\n", (int)error_pos, error_string);
        return 0;
    }
    return program_id;
}
Пример #30
0
static void Init( void )
{
   static const char *modulate2D =
      "!!ARBfp1.0\n"
      "TEMP R0;\n"
      "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"
      "MUL result.color, R0, fragment.color; \n"
      "END"
      ;
   GLuint modulateProg;
   GLuint Texture;

   if (!glutExtensionSupported("GL_ARB_fragment_program")) {
      printf("Error: GL_ARB_fragment_program not supported!\n");
      exit(1);
   }
   printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));

   /* Setup the fragment program */
   glGenProgramsARB(1, &modulateProg);
   glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
   glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(modulate2D), (const GLubyte *)modulate2D);

   printf("glGetError = 0x%x\n", (int) glGetError());
   printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
          (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
   assert(glIsProgramARB(modulateProg));

   glEnable(GL_FRAGMENT_PROGRAM_ARB);

   /* Load texture */
   glGenTextures(1, &Texture);
   glBindTexture(GL_TEXTURE_2D, Texture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
      printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
      exit(1);
   }
   /* XXX this enable shouldn't really be needed!!! */
   glEnable(GL_TEXTURE_2D);

   glClearColor(.3, .3, .3, 0);
}