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();
	}
	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();
	}
Пример #4
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();
}
static void glAlphaFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod) {
	glColorFragmentOp2ATI ( op, dst, GL_ALPHA, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod);
}
static void glColorFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod) {
	char str[128] = "\0";

	sOpUsed = 1;

	switch(op) {
		// Unary operators - fall back to Op1 routine.
		case GL_MOV_ATI:
			glColorFragmentOp1ATI(op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod);
			return;

		// Binary operators - fall back to Op2 routine.
		case GL_ADD_ATI:
		case GL_MUL_ATI:
		case GL_SUB_ATI:
		case GL_DOT3_ATI:
		case GL_DOT4_ATI:
			glColorFragmentOp2ATI(op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod);
			break;

		// Ternary operators
		case GL_MAD_ATI:
			sprintf(str, "    MAD r%d", dst - GL_REG_0_ATI);
			break;
		case GL_LERP_ATI:
			sprintf(str, "    LERP r%d", dst - GL_REG_0_ATI);
			break;
		case GL_CND_ATI:
			sprintf(str, "    CND r%d", dst - GL_REG_0_ATI);
			break;
		case GL_CND0_ATI:
			sprintf(str, "    CND0 r%d", dst - GL_REG_0_ATI);
			break;
		case GL_DOT2_ADD_ATI:
			sprintf(str, "    DOT2ADD r%d", dst - GL_REG_0_ATI);
			break;
		default:
			common->Warning("glColorFragmentOp3ATI invalid op;");
			break;
	}

	if(dstMask != GL_NONE)  {
		strcat(str, makeMaskStr(dstMask));
	}
	else {
		strcat(str, ".rgb" );
	}
	if(dstMod != GL_NONE) {
		strcat(str, makeDstModStr(dstMod));
	}
	strcat(str, ", ");

	strcat(str, makeArgStr(arg1));
	if(arg1Rep != GL_NONE)  {
		strcat(str, makeMaskStr(arg1Rep));
	}
	if(arg1Mod != GL_NONE) {
		strcat(str, makeArgModStr(arg1Mod));
	}
	strcat(str, ", ");

	strcat(str, makeArgStr(arg2));
	if(arg2Rep != GL_NONE)  {
		strcat(str, makeMaskStr(arg2Rep));
	}
	if(arg2Mod != GL_NONE) {
		strcat(str, makeArgModStr(arg2Mod));
	}
	strcat(str, ", ");

	strcat(str, makeArgStr(arg3));
	if(arg3Rep != GL_NONE)  {
		strcat(str, makeMaskStr(arg3Rep));
	}
	if(arg3Mod != GL_NONE) {
		strcat(str, makeArgModStr(arg3Mod));
	}
	strcat(str, ";\n");

	strcat(sPassString[sCurrentPass], str);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ATIFragmentShader_nglColorFragmentOp2ATI(JNIEnv *env, jclass clazz, jint op, jint dst, jint dstMask, jint dstMod, jint arg1, jint arg1Rep, jint arg1Mod, jint arg2, jint arg2Rep, jint arg2Mod, jlong function_pointer) {
	glColorFragmentOp2ATIPROC glColorFragmentOp2ATI = (glColorFragmentOp2ATIPROC)((intptr_t)function_pointer);
	glColorFragmentOp2ATI(op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod);
}
Пример #8
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");
}