EXTERN_C_ENTER

JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL42_nglGetActiveAtomicCounterBufferiv__IIIJ(JNIEnv *__env, jclass clazz, jint program, jint bufferIndex, jint pname, jlong paramsAddress) {
    glGetActiveAtomicCounterBufferivPROC glGetActiveAtomicCounterBufferiv = (glGetActiveAtomicCounterBufferivPROC)tlsGetFunction(858);
    intptr_t params = (intptr_t)paramsAddress;
    UNUSED_PARAM(clazz)
    glGetActiveAtomicCounterBufferiv(program, bufferIndex, pname, params);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL42_nglGetActiveAtomicCounterBufferiv(JNIEnv *env, jclass clazz, jint program, jint bufferIndex, jint pname, jlong params, jlong function_pointer) {
	GLint *params_address = (GLint *)(intptr_t)params;
	glGetActiveAtomicCounterBufferivPROC glGetActiveAtomicCounterBufferiv = (glGetActiveAtomicCounterBufferivPROC)((intptr_t)function_pointer);
	glGetActiveAtomicCounterBufferiv(program, bufferIndex, pname, params_address);
}
Example #3
0
void
piglit_init(int argc, char **argv)
{
        struct atomic_counters_limits ls = atomic_counters_get_limits();
        bool visited_buffers[8] = { false };
        bool visited_counters[8] = { false };
        GLuint prog = glCreateProgram();
        int i, j, n, ret;

        piglit_require_gl_version(31);
        piglit_require_extension("GL_ARB_shader_atomic_counters");

        if (ls.fragment_counters < 9) {
                fprintf(stderr, "Insufficient number of supported atomic "
                        "counters.\n");
                piglit_report_result(PIGLIT_SKIP);
        }

        if (ls.fragment_buffers < 4) {
                fprintf(stderr, "Insufficient number of supported atomic "
                        "counter buffers.\n");
                piglit_report_result(PIGLIT_SKIP);
        }

        if (!atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source)) {
                fprintf(stderr, "Program failed to compile.\n");
                piglit_report_result(PIGLIT_FAIL);
        }

        if (!atomic_counters_link(prog)) {
                fprintf(stderr, "Program failed to link.\n");
                piglit_report_result(PIGLIT_FAIL);
        }

        glGetProgramiv(prog, GL_ACTIVE_ATOMIC_COUNTER_BUFFERS, &n);
        if (n != 4) {
                fprintf(stderr, "Unexpected number of active counter "
                        "buffers.\n");
                piglit_report_result(PIGLIT_FAIL);
        }

        ret = 0xdeadbeef;
        glGetActiveAtomicCounterBufferiv(
                prog, n, GL_ATOMIC_COUNTER_BUFFER_BINDING, &ret);

        if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
                fprintf(stderr, "glGetActiveAtomicCounterBufferiv should have "
                        "failed when trying to query a non-existent buffer.\n");
                piglit_report_result(PIGLIT_FAIL);
        }

        if (ret != 0xdeadbeef) {
                fprintf(stderr, "Failed call to glGetActiveAtomicCounterBufferiv"
                        "didn't preserve the output parameter contents.\n");
                piglit_report_result(PIGLIT_FAIL);
        }

        for (i = 0; i < n; ++i) {
                const struct buffer_info *binfo;
                int binding, data_size, num_counters, ref;
                GLuint counters[4];

                glGetActiveAtomicCounterBufferiv(
                        prog, i, GL_ATOMIC_COUNTER_BUFFER_BINDING, &binding);
                if (!piglit_check_gl_error(GL_NO_ERROR)) {
                        fprintf(stderr, "Couldn't obtain counter buffer binding"
                                " point.\n");
                        piglit_report_result(PIGLIT_FAIL);
                }

                binfo = expected_buffer_info(binding);
                if (!binfo) {
                        fprintf(stderr, "Got unexpected buffer binding "
                                "point.\n");
                        piglit_report_result(PIGLIT_FAIL);
                }

                glGetActiveAtomicCounterBufferiv(
                        prog, i, GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE,
                        &data_size);
                if (!piglit_check_gl_error(GL_NO_ERROR) ||
                    data_size < binfo->min_reasonable_size) {
                        fprintf(stderr, "Invalid buffer data size: %d,"
                               " expected at least: %d.\n", data_size,
                               binfo->min_reasonable_size);
                        piglit_report_result(PIGLIT_FAIL);
                }

                glGetActiveAtomicCounterBufferiv(
                        prog, i, GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS,
                        &num_counters);
                if (!piglit_check_gl_error(GL_NO_ERROR) ||
                    num_counters != binfo->num_counters) {
                        fprintf(stderr, "Invalid number of atomic counters: %d,"
                               " expected: %d.\n", num_counters,
                               binfo->num_counters);
                        piglit_report_result(PIGLIT_FAIL);
                }

                if (visited_buffers[i]) {
                        fprintf(stderr, "Buffer at binding point %d seen twice."
                                "\n", binding);
                        piglit_report_result(PIGLIT_FAIL);
                }
                visited_buffers[i] = true;

                glGetActiveAtomicCounterBufferiv(prog, i,
                        GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER,
                        &ref);
                if (!piglit_check_gl_error(GL_NO_ERROR) || ref) {
                        fprintf(stderr, "Buffer incorrectly reported to be "
                                "referenced by vertex shader.\n");
                        piglit_report_result(PIGLIT_FAIL);
                }

                glGetActiveAtomicCounterBufferiv(prog, i,
                        GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER,
                        &ref);
                if (!piglit_check_gl_error(GL_NO_ERROR) || ref) {
                        fprintf(stderr, "Buffer incorrectly reported to be "
                                "referenced by tessellation control shader.\n");
                        piglit_report_result(PIGLIT_FAIL);
                }

                glGetActiveAtomicCounterBufferiv(prog, i,
                        GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER,
                        &ref);
                if (!piglit_check_gl_error(GL_NO_ERROR) || ref) {
                        fprintf(stderr, "Buffer incorrectly reported to be "
                                "referenced by tessellation evaluation shader."
                                "\n");
                        piglit_report_result(PIGLIT_FAIL);
                }

                glGetActiveAtomicCounterBufferiv(prog, i,
                        GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER,
                        &ref);
                if (!piglit_check_gl_error(GL_NO_ERROR) || ref) {
                        fprintf(stderr, "Buffer incorrectly reported to be "
                                "referenced by geometry shader.\n");
                        piglit_report_result(PIGLIT_FAIL);
                }

                glGetActiveAtomicCounterBufferiv(prog, i,
                        GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER,
                        &ref);
                if (!piglit_check_gl_error(GL_NO_ERROR) || !ref) {
                        fprintf(stderr, "Buffer incorrectly reported as "
                                "unreferenced from the fragment shader.\n");
                        piglit_report_result(PIGLIT_FAIL);
                }

                glGetActiveAtomicCounterBufferiv(prog, i,
                        GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES,
                        (GLint *)counters);
                if (!piglit_check_gl_error(GL_NO_ERROR)) {
                        fprintf(stderr, "Couldn't obtain list of active atomic "
                                "counters for buffer at binding point %d.\n",
                                binding);
                        piglit_report_result(PIGLIT_FAIL);
                }

                for (j = 0; j < num_counters; ++j) {
                        const struct counter_info *cinfo;
                        int unif_type, unif_size, unif_name_len,
                                unif_block_idx, unif_offset, unif_stride,
                                unif_buffer_idx;
                        char unif_name[8];

                        glGetActiveUniformName(prog, counters[j],
                                               sizeof(unif_name), NULL,
                                               unif_name);

                        cinfo = expected_counter_info(unif_name);
                        if (!piglit_check_gl_error(GL_NO_ERROR) || !cinfo) {
                                fprintf(stderr, "Unknown atomic counter \"%s\"."
                                        "\n", unif_name);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        glGetActiveUniformsiv(prog, 1, &counters[j],
                                              GL_UNIFORM_TYPE, &unif_type);
                        if (!piglit_check_gl_error(GL_NO_ERROR) ||
                            unif_type != GL_UNSIGNED_INT_ATOMIC_COUNTER) {
                                fprintf(stderr, "Atomic counter \"%s\" has "
                                        "invalid type 0x%x, expected 0x%x.\n",
                                        unif_name, unif_type,
                                        GL_UNSIGNED_INT_ATOMIC_COUNTER);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        glGetActiveUniformsiv(prog, 1, &counters[j],
                                              GL_UNIFORM_SIZE, &unif_size);
                        if (!piglit_check_gl_error(GL_NO_ERROR) ||
                            unif_size != cinfo->size) {
                                fprintf(stderr, "Atomic counter \"%s\" has "
                                        "invalid size %d, expected: %d.\n",
                                        unif_name, unif_size, cinfo->size);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        glGetActiveUniformsiv(prog, 1, &counters[j],
                                              GL_UNIFORM_NAME_LENGTH, &unif_name_len);
                        if (!piglit_check_gl_error(GL_NO_ERROR) ||
                            unif_name_len != strlen(unif_name) + 1) {
                                fprintf(stderr, "Atomic counter \"%s\" has "
                                        "invalid name length %d, expected: %d."
                                        "\n", unif_name, unif_name_len,
                                        (int)strlen(unif_name) + 1);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        glGetActiveUniformsiv(prog, 1, &counters[j],
                                              GL_UNIFORM_BLOCK_INDEX, &unif_block_idx);
                        if (!piglit_check_gl_error(GL_NO_ERROR) ||
                            unif_block_idx != -1) {
                                fprintf(stderr, "Atomic counter \"%s\" has "
                                        "invalid block index %d, expected: -1."
                                        "\n", unif_name, unif_block_idx);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        glGetActiveUniformsiv(prog, 1, &counters[j],
                                              GL_UNIFORM_OFFSET, &unif_offset);
                        if (!piglit_check_gl_error(GL_NO_ERROR) ||
                            unif_offset != cinfo->offset) {
                                fprintf(stderr, "Atomic counter \"%s\" has "
                                        "invalid offset %d, expected: %d.\n",
                                        unif_name, unif_offset, cinfo->offset);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        glGetActiveUniformsiv(prog, 1, &counters[j],
                                              GL_UNIFORM_ARRAY_STRIDE, &unif_stride);
                        if (!piglit_check_gl_error(GL_NO_ERROR) ||
                            (cinfo->size > 1 && unif_stride < 4) ||
                            (cinfo->size == 1 && unif_stride != 0)) {
                                fprintf(stderr, "Atomic counter \"%s\" has "
                                        "invalid array stride %d.\n",
                                        unif_name, unif_stride);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        glGetActiveUniformsiv(prog, 1, &counters[j],
                                              GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX,
                                              &unif_buffer_idx);
                        if (!piglit_check_gl_error(GL_NO_ERROR) ||
                            unif_buffer_idx != i) {
                                fprintf(stderr, "Atomic counter \"%s\" has "
                                        "invalid buffer index %d, expected %d."
                                        "\n", unif_name, unif_buffer_idx, i);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        if (cinfo->binding != binding) {
                                fprintf(stderr, "Atomic counter \"%s\" belongs "
                                        "to the wrong binding point %d.\n",
                                        unif_name, binding);
                                piglit_report_result(PIGLIT_FAIL);
                        }

                        if (visited_counters[counters[j]]) {
                                fprintf(stderr, "Atomic counter \"%s\" seen "
                                        "twice.\n", unif_name);
                                piglit_report_result(PIGLIT_FAIL);
                        }
                        visited_counters[counters[j]] = true;
                }
        }

        glDeleteProgram(prog);

        piglit_report_result(PIGLIT_PASS);
}
Example #4
0
void kore::ShaderProgram::constructShaderInputInfo(const GLenum activeType,
                                std::vector<kore::ShaderInput>& rInputVector) {
  GLint iNumActiveElements = 0;

  /*
  /* OpenGL 4.3 or arb_program_interface_query needed 
  /*
  glGetProgramInterfaceiv(_programHandle, activeType, GL_ACTIVE_RESOURCES, 
      &iNumActiveElements);

  const GLenum properties[3] = {GL_TYPE, GL_NAME_LENGTH, GL_LOCATION};
  */

  glGetProgramiv(_programHandle,
      activeType,
      &iNumActiveElements);

  for (int i = 0; i < iNumActiveElements; ++i) {
    GLchar szNameBuf[BUFSIZE];
    GLsizei iActualNameLength = 0;
    GLint iElementSize = 1;
    GLenum eElementType;
    GLint iElementLoc = -1;

    /*
    /* OpenGL 4.3 or arb_program_interface_query needed 
    /*
    GLint values[3];       
    glGetProgramResourceiv(_programHandle, activeType, i, 3, properties, 
        BUFSIZE, NULL, values);

    eElementType = values[0];
    iActualNameLength = values[1];
    iElementLoc = values[2];

    glGetProgramResourceName(_programHandle, activeType, i, BUFSIZE, 
        &iActualNameLength, szNameBuf);
    */

    if (activeType == GL_ACTIVE_ATTRIBUTES) {
        glGetActiveAttrib(_programHandle, i, BUFSIZE, &iActualNameLength,
            &iElementSize, &eElementType, szNameBuf);
        iElementLoc = glGetAttribLocation(_programHandle, szNameBuf);
    }
    if (activeType == GL_ACTIVE_UNIFORMS){
        glGetActiveUniform(_programHandle, i, BUFSIZE, &iActualNameLength,
            &iElementSize, &eElementType, szNameBuf);
        iElementLoc = glGetUniformLocation(_programHandle, szNameBuf);
    }

    std::string szName = std::string(szNameBuf);
    ShaderInput element;
    element.name = szName;
    element.type = eElementType;
    element.input_type = activeType;
    element.size = iElementSize;
    element.location = iElementLoc;
    element.programHandle = _programHandle;
    element.shader = this;

    rInputVector.push_back(element);
  }

  /*
  /* OpenGL 4.3 or arb_program_interface_query needed 
  /*
  // For Uniform texture-types: add the textureUnit-field
  if (activeType == GL_UNIFORM) {
    GLuint texUnit = 0;
    for (uint i = 0; i < rInputVector.size(); ++i) {
      if (isSamplerType(rInputVector[i].type)) {
        rInputVector[i].texUnit = texUnit;
        ++texUnit;
      }
    }
  }
  */

  // For Uniform texture-types: add the textureUnit-field
  if (activeType == GL_ACTIVE_UNIFORMS) {
    ResourceManager* resourceManager = ResourceManager::getInstance();
    GLuint texUnit = 0;
    GLuint imgUnit = 0;
    GLuint atomicCounterIndex = 0;  // e.g. for atomic counters.

    for (uint i = 0; i < rInputVector.size(); ++i) {
      if (rInputVector[i].isSamplerType()) {
        rInputVector[i].texUnit = texUnit;
        
        TexSamplerProperties samplerProperties;
        samplerProperties.type = rInputVector[i].type;
                     
        
        const TextureSampler* sampler =
          resourceManager->requestTextureSampler(samplerProperties);
        
        _vSamplers.push_back(sampler);
        
        ++texUnit;
      }

      // For Image-types: add the imgUnit-field,
      // but don't create a sampler.
      else if (rInputVector[i].isImageType()) {
        rInputVector[i].imgUnit = imgUnit;
        ++imgUnit;
      
        _imgAccessParams.push_back(GL_READ_WRITE);
      }
      
      else if(rInputVector[i].isAtomicCounterType()) {
        // Get the bindingPoint (set with layout(binding = x) 
        GLint bindingPoint;
        glGetActiveAtomicCounterBufferiv(_programHandle,
                                         atomicCounterIndex,
                                         GL_ATOMIC_COUNTER_BUFFER_BINDING,
                                         &bindingPoint);
        ++atomicCounterIndex;
        rInputVector[i].atomicCounterBindingPoint = bindingPoint;
      }
    }
  }
}