JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_EXTGPUShader4_nglGetFragDataLocationEXT(JNIEnv *__env, jclass clazz, jint program, jlong nameAddress) {
    glGetFragDataLocationEXTPROC glGetFragDataLocationEXT = (glGetFragDataLocationEXTPROC)tlsGetFunction(1745);
    intptr_t name = (intptr_t)nameAddress;
    UNUSED_PARAM(clazz)
    return (jint)glGetFragDataLocationEXT(program, name);
}
Exemple #2
0
/** \return GL_TRUE for pass, GL_FALSE for fail */
static GLboolean
test_fbo(const struct format_info *info)
{
   const int max = get_max_val(info);
   const int comps = num_components(info->BaseFormat);
   const GLenum type = get_datatype(info);
   GLint f;
   GLuint fbo, texObj;
   GLenum status;
   GLboolean intMode;
   GLint buf;

   if (0)
      fprintf(stderr, "============ Testing format = %s ========\n", info->Name);

   /* Create texture */
   glGenTextures(1, &texObj);
   glBindTexture(GL_TEXTURE_2D, texObj);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

   glTexImage2D(GL_TEXTURE_2D, 0, info->IntFormat, TexWidth, TexHeight, 0,
                info->BaseFormat, type, NULL);

   if (check_error(__FILE__, __LINE__))
      return GL_FALSE;

   glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &f);
   assert(f == info->IntFormat);


   /* Create FBO to render to texture */
   glGenFramebuffers(1, &fbo);
   glBindFramebuffer(GL_FRAMEBUFFER, fbo);
   glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                          GL_TEXTURE_2D, texObj, 0);

   if (check_error(__FILE__, __LINE__))
      return GL_FALSE;

   status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
   if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
      fprintf(stderr, "%s: failure: framebuffer incomplete.\n", TestName);
      return GL_FALSE;
   }


   glGetBooleanv(GL_RGBA_INTEGER_MODE_EXT, &intMode);
   if (check_error(__FILE__, __LINE__))
      return GL_FALSE;
   if (!intMode) {
      fprintf(stderr, "%s: GL_RGBA_INTEGER_MODE_EXT return GL_FALSE\n",
              TestName);
      return GL_FALSE;
   }

   glGetIntegerv(GL_READ_BUFFER, &buf);
   assert(buf == GL_COLOR_ATTACHMENT0_EXT);
   glGetIntegerv(GL_DRAW_BUFFER, &buf);
   assert(buf == GL_COLOR_ATTACHMENT0_EXT);


   /* test clearing */
   if (1) {
      static const GLint clr[4] = { 8, 7, 6, 5 };
      GLint pix[4], i;

      glClearColorIiEXT(clr[0], clr[1], clr[2], clr[3]);
      glClear(GL_COLOR_BUFFER_BIT);

      glReadPixels(5, 5, 1, 1, GL_RGBA_INTEGER_EXT, GL_INT, pix);

      for (i = 0; i < comps; i++) {
         if (pix[i] != clr[i]) {
            fprintf(stderr, "%s: glClear failed\n", TestName);
            fprintf(stderr, "  Texture format = %s\n", info->Name);
            fprintf(stderr, "  Expected %d, %d, %d, %d\n",
                    clr[0], clr[1], clr[2], clr[3]);
            fprintf(stderr, "  Found %d, %d, %d, %d\n",
                    pix[0], pix[1], pix[2], pix[3]);
            return GL_FALSE;
         }
      }
   }


   /* Do glDraw/ReadPixels test */
   if (1) {
#define W 15
#define H 10
      GLint image[H * W * 4], readback[H * W * 4];
      GLint i;

      if (info->Signed) {
         for (i = 0; i < W * H * 4; i++) {
            image[i] = (i - 10) % max;
            assert(image[i] < max);
         }
      }
      else {
         for (i = 0; i < W * H * 4; i++) {
            image[i] = (i + 3) % max;
            assert(image[i] < max);
         }
      }

      glUseProgram(PassthroughProgram);
      if(0)glUseProgram(SimpleProgram);

      glWindowPos2i(1, 1);
      glDrawPixels(W, H, GL_RGBA_INTEGER_EXT, GL_INT, image);

      if (check_error(__FILE__, __LINE__))
         return GL_FALSE;

      glReadPixels(1, 1, W, H, GL_RGBA_INTEGER_EXT, GL_INT, readback);

      if (check_error(__FILE__, __LINE__))
         return GL_FALSE;

      for (i = 0; i < W * H * 4; i++) {
         if (readback[i] != image[i]) {
            if (comps == 3 && i % 4 == 3 && readback[i] == 1)
               continue; /* alpha = 1 if base format == RGB */

            fprintf(stderr,
                 "%s: glDraw/ReadPixels failed at %d.  Expected %d, found %d\n",
                    TestName, i, image[i], readback[i]);
            fprintf(stderr, "Texture format = %s\n", info->Name);
            assert(0);
            return GL_FALSE;
         }
      }
#undef W
#undef H
   }

   /* Do rendering test */
   if (1) {
      GLint value[4], result[4], loc, w = piglit_width, h = piglit_height;
      GLint error = 1; /* XXX fix */

      /* choose random value/color for polygon */
      value[0] = rand() % 100;
      value[1] = rand() % 100;
      value[2] = rand() % 100;
      value[3] = rand() % 100;

      glUseProgram(SimpleProgram);
      check_error(__FILE__, __LINE__);

      loc = glGetUniformLocation(SimpleProgram, "value");
      assert(loc >= 0);
      glUniform4iv(loc, 1, value);
      check_error(__FILE__, __LINE__);

#if 0 /* allow testing on mesa until this is implemented */
      loc = glGetFragDataLocationEXT(SimpleProgram, "out_color");
      assert(loc >= 0);
#endif

      glBegin(GL_POLYGON);
      glVertex2f(0, 0);
      glVertex2f(w, 0);
      glVertex2f(w, h);
      glVertex2f(0, h);
      glEnd();
      check_error(__FILE__, __LINE__);

      glReadPixels(w/2, h/2, 1, 1, GL_RGBA_INTEGER, GL_INT, result);
      check_error(__FILE__, __LINE__);

      if (info->BaseFormat == GL_RGB_INTEGER_EXT) {
         value[3] = 1;
      }

      if (abs(result[0] - value[0]) > error ||
          abs(result[1] - value[1]) > error ||
          abs(result[2] - value[2]) > error ||
          abs(result[3] - value[3]) > error) {
         fprintf(stderr, "%s: failure with format %s:\n", TestName, info->Name);
         fprintf(stderr, "  input value = %d, %d, %d, %d\n",
                 value[0], value[1], value[2], value[3]);
         fprintf(stderr, "  result color = %d, %d, %d, %d\n",
                 result[0], result[1], result[2], result[3]);
         return GL_FALSE;
      }
   }

   piglit_present_results();

   glDeleteTextures(1, &texObj);
   glDeleteFramebuffers(1, &fbo);

   return GL_TRUE;
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_EXTGpuShader4_nglGetFragDataLocationEXT(JNIEnv *env, jclass clazz, jint program, jobject name, jint name_position, jlong function_pointer) {
	const GLchar *name_address = ((const GLchar *)(*env)->GetDirectBufferAddress(env, name)) + name_position;
	glGetFragDataLocationEXTPROC glGetFragDataLocationEXT = (glGetFragDataLocationEXTPROC)((intptr_t)function_pointer);
	GLint __result = glGetFragDataLocationEXT(program, name_address);
	return __result;
}