void cGLState_ATISpot::InitData()
	{
		mlBind = glGenFragmentShadersATI(1);

		Log("Creating and binding ATI spot shader to %d\n",mlBind);
		glBindFragmentShaderATI(mlBind);

		glBeginFragmentShaderATI();

		glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
		glSampleMapATI(GL_REG_1_ATI, GL_TEXTURE1_ARB, GL_SWIZZLE_STR_DR_ATI);
		glSampleMapATI(GL_REG_2_ATI, GL_TEXTURE2_ARB, GL_SWIZZLE_STR_ATI);

		//Reg0 = Diffuse * Spot
		glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
			GL_REG_0_ATI, GL_NONE, GL_NONE,
			GL_REG_1_ATI, GL_NONE, GL_NONE);

		//Reg0 = NegRejection * Reg0
		glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
			GL_REG_0_ATI, GL_NONE, GL_NONE,
			GL_REG_2_ATI, GL_NONE, GL_NONE);

		//Reg0 = LightColor * Reg0
		glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
			GL_REG_0_ATI, GL_NONE, GL_NONE,
			GL_PRIMARY_COLOR_ARB, GL_NONE, GL_NONE);

		glEndFragmentShaderATI();
	}
	void cGLState_ATIDiffuse::InitData()
	{
		mlBind = glGenFragmentShadersATI(1);

		Log("Creating and binding ATI diffuse shader to %d\n",mlBind);
		glBindFragmentShaderATI(mlBind);

		glBeginFragmentShaderATI();

		glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
		glSampleMapATI(GL_REG_2_ATI, GL_TEXTURE2_ARB, GL_SWIZZLE_STR_ATI);
		
		//Reg0 = NormlizedVec dot3 Vector(0,0,1)
		float vConst[4] = {0,0,1,0};
		glSetFragmentShaderConstantATI( GL_CON_0_ATI,vConst);
		glColorFragmentOp2ATI(	GL_DOT3_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
								GL_REG_0_ATI, GL_NONE, GL_2X_BIT_ATI|GL_BIAS_BIT_ATI,
								GL_CON_0_ATI, GL_NONE, GL_NONE);
		glAlphaFragmentOp2ATI(	GL_DOT3_ATI, GL_REG_0_ATI, GL_NONE,
								GL_REG_0_ATI, GL_NONE, GL_2X_BIT_ATI|GL_BIAS_BIT_ATI,
								GL_CON_0_ATI, GL_NONE, GL_NONE);

		//Reg0 = Light * Attenuation
		glAlphaFragmentOp2ATI(	GL_MUL_ATI, GL_REG_0_ATI, GL_NONE,
								GL_REG_0_ATI, GL_NONE, GL_NONE,
								GL_REG_2_ATI, GL_NONE, GL_NONE);
		
		glEndFragmentShaderATI();
	}
Пример #3
0
void ToneMap::makeShadersPS14ATI() {

    // Really slow--appears to be implemented in software!
    gammaShaderPS14ATI = glGenFragmentShadersATI(1);
    glBindFragmentShaderATI(gammaShaderPS14ATI);
    glBeginFragmentShaderATI();

        // Pass 1

        // R0 = texture0[texcoord0]
        glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);  

        // Move the blue component of R0 into the red component of R3
        glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_3_ATI, GL_RED_BIT_ATI, GL_NONE, 
                              GL_REG_0_ATI, GL_BLUE, GL_NONE);
        // R1 = texture1[R0]
        // R2 = texture2[R3]
        glSampleMapATI(GL_REG_1_ATI, GL_REG_0_ATI, GL_SWIZZLE_STR_ATI);  
        glSampleMapATI(GL_REG_2_ATI, GL_REG_3_ATI, GL_SWIZZLE_STR_ATI);

        // At this point, R1 contains the gamma corrected red and green channels
        // and R2 contains the corrected blue channel.  Combine them:

        // R0 = R1 + R2
        glColorFragmentOp2ATI(GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, 
                              GL_REG_1_ATI, GL_NONE, GL_NONE,
                              GL_REG_2_ATI, GL_NONE, GL_NONE);
        
        // R0 = texcoord 0
        //glPassTexCoordATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
        // 
        //glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);

    glEndFragmentShaderATI();
}
	void cGLState_ATIBump::InitData()
	{
		mlBind = glGenFragmentShadersATI(1);

		Log("Creating and binding ATI bump shader to %d\n",mlBind);
		glBindFragmentShaderATI(mlBind);

		glBeginFragmentShaderATI();

		glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
		glSampleMapATI(GL_REG_1_ATI, GL_TEXTURE1_ARB, GL_SWIZZLE_STR_ATI);
		glSampleMapATI(GL_REG_2_ATI, GL_TEXTURE2_ARB, GL_SWIZZLE_STR_ATI);

		//Reg0 = NormlizedVec dot3 NormalMap
		glColorFragmentOp2ATI(	GL_DOT3_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
								GL_REG_1_ATI, GL_NONE, GL_2X_BIT_ATI|GL_BIAS_BIT_ATI,
								GL_REG_0_ATI, GL_NONE, GL_2X_BIT_ATI|GL_BIAS_BIT_ATI);
		glAlphaFragmentOp2ATI(	GL_DOT3_ATI, GL_REG_0_ATI, GL_NONE,
								GL_REG_1_ATI, GL_NONE, GL_2X_BIT_ATI|GL_BIAS_BIT_ATI,
								GL_REG_0_ATI, GL_NONE, GL_2X_BIT_ATI|GL_BIAS_BIT_ATI);

		//Reg0 = Light * Attenuation
		glAlphaFragmentOp2ATI(	GL_MUL_ATI, GL_REG_0_ATI, GL_NONE,
								GL_REG_0_ATI, GL_NONE, GL_NONE,
								GL_REG_2_ATI, GL_NONE, GL_NONE);
		
		glEndFragmentShaderATI();
	}
Пример #5
0
void pnTriangles::bindFragmentProgram()
//
// Description:
//
//	THIS IS JUST SAMPLE CODE, MORE NEEDS TO BE DONE TO ACTUALLY USE
//	INCORPORATE A FRAGMENT SHADER.
//
{
	// See if extension is supported
	//
	if (!fExtensionSupported[kFragmentShaderEXT])
		return;

	// Enable vertex shaders
	glEnable(GL_FRAGMENT_SHADER_ATI);

	// Generate a new fragment shader id, if none has been created.
	if (fFragmentShaderId != -1)
	{
		glBindFragmentShaderATI (fFragmentShaderId);
		return;
	}

	fFragmentShaderId = glGenFragmentShadersATI(1);

	glBindFragmentShaderATI (fFragmentShaderId);
	glBeginFragmentShaderATI();

	// Place sample fragment shader code here ....

	glEndFragmentShaderATI();
}
Пример #6
0
GLenum VDOpenGLBinding::InitTechniques(const VDOpenGLTechnique *techniques, int techniqueCount) {
    GLuint listBase = glGenLists(techniqueCount);

    for(int i=0; i<techniqueCount; ++i) {
        const VDOpenGLTechnique& tech = techniques[i];
        GLenum shader;

        switch(tech.mFragmentShaderMode) {
        case kVDOpenGLFragmentShaderModeNVRC2:
            if (!NV_register_combiners2)
                continue;
        // fall through
        case kVDOpenGLFragmentShaderModeNVRC:
            if (!NV_register_combiners)
                continue;
            break;
        case kVDOpenGLFragmentShaderModeATIFS:
            if (!ATI_fragment_shader)
                continue;
            break;
        }

        if (tech.mFragmentShaderMode == kVDOpenGLFragmentShaderModeATIFS) {
            shader = glGenFragmentShadersATI(1);
            glBindFragmentShaderATI(shader);
            CreateATIFragmentShader(*this, *(const VDOpenGLATIFragmentShaderConfig *)tech.mpFragmentShader);
            glBindFragmentShaderATI(0);
        }

        glNewList(listBase + i, GL_COMPILE);
        switch(tech.mFragmentShaderMode) {
        case kVDOpenGLFragmentShaderModeNVRC:
            glEnable(GL_REGISTER_COMBINERS_NV);
            glDisable(GL_PER_STAGE_CONSTANTS_NV);
            if (ATI_fragment_shader)
                glDisable(GL_FRAGMENT_SHADER_ATI);
            CreateNVRegisterCombinerSetup(*this, *(const VDOpenGLNVRegisterCombinerConfig *)tech.mpFragmentShader, false);
            break;
        case kVDOpenGLFragmentShaderModeNVRC2:
            glEnable(GL_REGISTER_COMBINERS_NV);
            glEnable(GL_PER_STAGE_CONSTANTS_NV);
            if (ATI_fragment_shader)
                glDisable(GL_FRAGMENT_SHADER_ATI);
            CreateNVRegisterCombinerSetup(*this, *(const VDOpenGLNVRegisterCombinerConfig *)tech.mpFragmentShader, true);
            break;
        case kVDOpenGLFragmentShaderModeATIFS:
            if (NV_register_combiners)
                glDisable(GL_REGISTER_COMBINERS_NV);
            glEnable(GL_FRAGMENT_SHADER_ATI);
            glBindFragmentShaderATI(shader);
            break;
        }
        glEndList();
    }

    return listBase;
}
Пример #7
0
void
piglit_init(int argc, char **argv)
{
	bool pass = true;

	piglit_require_extension("GL_ATI_fragment_shader");

	glBeginFragmentShaderATI();

	pass &= piglit_check_gl_error(GL_NO_ERROR);
	glGenFragmentShadersATI(1);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	glBindFragmentShaderATI(2);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	glDeleteFragmentShaderATI(3);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	glBeginFragmentShaderATI();
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_ATIFragmentShader_nglGenFragmentShadersATI(JNIEnv *env, jclass clazz, jint range, jlong function_pointer) {
	glGenFragmentShadersATIPROC glGenFragmentShadersATI = (glGenFragmentShadersATIPROC)((intptr_t)function_pointer);
	GLuint __result = glGenFragmentShadersATI(range);
	return __result;
}
Пример #9
0
static void Init( int argc, char *argv[] )
{
   GLuint texObj[8];
   GLint size, i;

   const char *exten = (const char *) glGetString(GL_EXTENSIONS);
   if (!strstr(exten, "GL_ATI_fragment_shader")) {
      printf("Sorry, GL_ATI_fragment_shader not supported by this renderer.\n");
      exit(1);
   }


   glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
   printf("%d x %d max texture size\n", size, size);

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   for (i = 0; i < NumUnits; i++) {
      if (i < 6)
         TexEnabled[i] = GL_TRUE;
      else
         TexEnabled[i] = GL_FALSE;
   }

   /* allocate two texture objects */
   glGenTextures(NumUnits, texObj);

   /* setup the texture objects */
   for (i = 0; i < NumUnits; i++) {

      glActiveTextureARB(GL_TEXTURE0_ARB + i);
      glBindTexture(GL_TEXTURE_2D, texObj[i]);

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

      if (i == 0) {
         if (!LoadRGBMipmaps(TEXTURE_1_FILE, GL_RGB)) {
            printf("Error: couldn't load texture image\n");
            exit(1);
         }
      }
      else if (i == 1) {
         if (!LoadRGBMipmaps(TEXTURE_2_FILE, GL_RGB)) {
            printf("Error: couldn't load texture image\n");
            exit(1);
         }
      }
      else {
         /* checker */
         GLubyte image[8][8][3];
         GLint i, j;
         for (i = 0; i < 8; i++) {
            for (j = 0; j < 8; j++) {
               if ((i + j) & 1) {
                  image[i][j][0] = 50;
                  image[i][j][1] = 50;
                  image[i][j][2] = 50;
               }
               else {
                  image[i][j][0] = 25;
                  image[i][j][1] = 25;
                  image[i][j][2] = 25;
               }
            }
         }
         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0,
                      GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *) image);
      }

      /* Bind texObj[i] to ith texture unit */
/*      if (i < 2)
         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      else
         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);*/

      if (TexEnabled[i])
         glEnable(GL_TEXTURE_2D);
   }

   boringshaderID = glGenFragmentShadersATI(1);
   boring2passID = glGenFragmentShadersATI(1);
   if (boring2passID == 0)
   {
      fprintf(stderr, "couldn't get frag shader id\n");
      exit(1);
   }
   glBindFragmentShaderATI(boringshaderID);
/* maybe not the most creative shader but at least I know how it should look like! */
   glBeginFragmentShaderATI();
   glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_1_ATI, GL_TEXTURE1_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_2_ATI, GL_TEXTURE2_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_3_ATI, GL_TEXTURE3_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_4_ATI, GL_TEXTURE4_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_5_ATI, GL_TEXTURE5_ARB, GL_SWIZZLE_STR_ATI);
   glColorFragmentOp2ATI(GL_MUL_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_PRIMARY_COLOR, GL_NONE, GL_NONE);
   glAlphaFragmentOp1ATI(GL_MOV_ATI,
			 GL_REG_0_ATI, GL_NONE,
			 GL_PRIMARY_COLOR, GL_NONE, GL_NONE);
   glColorFragmentOp3ATI(GL_MAD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_1_ATI, GL_NONE, GL_NONE,
			 GL_REG_2_ATI, GL_NONE, GL_NONE);
   glColorFragmentOp2ATI(GL_ADD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_3_ATI, GL_NONE, GL_NONE);
   glColorFragmentOp2ATI(GL_ADD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_4_ATI, GL_NONE, GL_NONE);
   glColorFragmentOp2ATI(GL_ADD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_5_ATI, GL_NONE, GL_NONE);
   glEndFragmentShaderATI();

/* mathematically equivalent to first shader but using 2 passes together with
   some tex coord rerouting */
   glBindFragmentShaderATI(boring2passID);
   glBeginFragmentShaderATI();
   glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_2_ATI, GL_TEXTURE2_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_3_ATI, GL_TEXTURE3_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_4_ATI, GL_TEXTURE4_ARB, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_5_ATI, GL_TEXTURE5_ARB, GL_SWIZZLE_STR_ATI);
   glColorFragmentOp2ATI(GL_ADD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_2_ATI, GL_NONE, GL_NONE,
			 GL_REG_3_ATI, GL_NONE, GL_NONE);
   glColorFragmentOp2ATI(GL_ADD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_4_ATI, GL_NONE, GL_NONE);
   glColorFragmentOp2ATI(GL_ADD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_5_ATI, GL_NONE, GL_NONE);
   /* not really a dependant read */
   glSampleMapATI(GL_REG_0_ATI, GL_REG_1_ATI, GL_SWIZZLE_STR_ATI);
   glSampleMapATI(GL_REG_1_ATI, GL_TEXTURE1_ARB, GL_SWIZZLE_STR_ATI);
   glPassTexCoordATI(GL_REG_5_ATI, GL_REG_0_ATI, GL_SWIZZLE_STR_ATI);
   glColorFragmentOp2ATI(GL_MUL_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_PRIMARY_COLOR, GL_NONE, GL_NONE);
   glAlphaFragmentOp1ATI(GL_MOV_ATI,
			 GL_REG_0_ATI, GL_NONE,
			 GL_PRIMARY_COLOR, GL_NONE, GL_NONE);
   glColorFragmentOp3ATI(GL_MAD_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_1_ATI, GL_NONE, GL_NONE,
			 GL_REG_5_ATI, GL_NONE, GL_NONE);
   /* in principle we're finished here, but to test a bit more
      we do some fun with dot ops, replication et al. */
   glSetFragmentShaderConstantATI(GL_CON_3_ATI, shaderconstant);
   glColorFragmentOp2ATI(GL_DOT4_ATI,
			 GL_REG_3_ATI, GL_GREEN_BIT_ATI, GL_EIGHTH_BIT_ATI,
			 GL_ZERO, GL_NONE, GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI,
			 GL_CON_3_ATI, GL_RED, GL_2X_BIT_ATI);
   /* those args must get ignored, except dstReg */
   glAlphaFragmentOp2ATI(GL_DOT4_ATI,
			 GL_REG_4_ATI, GL_NONE,
			 GL_ZERO, GL_NONE, GL_NONE,
			 GL_ZERO, GL_NONE, GL_NONE);
   /* -> reg3 g = reg4 alpha = -0.5 */
   glAlphaFragmentOp2ATI(GL_ADD_ATI,
			 GL_REG_5_ATI, GL_NONE,
			 GL_REG_3_ATI, GL_GREEN, GL_NONE,
			 GL_REG_4_ATI, GL_NONE, GL_NONE);
   /* -> reg5 a = -1 */
   glColorFragmentOp3ATI(GL_DOT2_ADD_ATI,
			 GL_REG_4_ATI, GL_BLUE_BIT_ATI, GL_HALF_BIT_ATI,
			 GL_REG_5_ATI, GL_ALPHA, GL_NEGATE_BIT_ATI,
			 GL_ONE, GL_NONE, GL_BIAS_BIT_ATI,
			 GL_ONE, GL_ALPHA, GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI);
   /* -> reg 4 b = -0.5 */
   glColorFragmentOp2ATI(GL_MUL_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE,
			 GL_REG_4_ATI, GL_BLUE, GL_NEGATE_BIT_ATI | GL_2X_BIT_ATI,
			 GL_REG_0_ATI, GL_NONE, GL_NONE);
   glEndFragmentShaderATI();

   glBindFragmentShaderATI(boringshaderID);
   glEnable(GL_FRAGMENT_SHADER_ATI);

   glShadeModel(GL_FLAT);
   glClearColor(0.3, 0.3, 0.4, 1.0);

   if (argc > 1 && strcmp(argv[1], "-info")==0) {
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
      printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
      printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
   }
   printf("output should be identical with both shaders to multiarb demo when 6 textures are enabled\n");
}