• Welcome to Theos PowerBasic Museum 2017.

BassBox

Started by Patrice Terrier, October 08, 2007, 10:57:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

--Charles (and others)

I am doing another change into BassBox to make sure that the %BBP_INIT will be sent only once to the plugin (to avoid extra check in each of the plugin)
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Charles Pegge

#406
I have not seen an upper limit for the number of textures Patrice, I would assume that it is limited only by the storage capacity of the graphics card,before they spill into main memory and cause performance problems. Ideally the Plugins should be responsible for taking down their own textures but I think that deleting the first 32 by default for most plugins is a safe and efficient method. If the textures do not exist, Opengl will not complain when asked to delete them.

PS:
Thanks for the new constants - they will help to keep the compiled DLL sizes down.

Patrice Terrier

Ok, then i will use the brute force to delete the texture using arbitrary value of 32.

I shall post the new build # 1.25 in a couple of hours, with the changes we spoke in previous posts, altogether with the new textures, new chm, and new include file. 

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#408
BassBox has been updated to version 1.25.

See the first post of this thread to download the whole updated project.

What is new:

  • plugin "Flying the pole".
  • 2 new textures (moon.jpg and bg9.gif).
  • BassBox.bas and BBPlugin.inc updated for further code optimization.
  • New constants to reduce code size: BBP_NO_REGISTRY, BBP_NO_IOFILE, BBP_NO_GLFONT.
  • BassBox clears all the textures, while the DLL plugin is detached.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Petr Schreiber

Thanks for the update,

works great here!


Bye,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge

Petr, have you looked at Opengl GLSL Shader Language yet? I am starting to explore it. GLSL is supported in Opengl 2.0 and compiles snippets of  C-like code directly into the video hardware to control shading lighting and texture blending directly, bypassing the static functions of standard Opengl. I think all the recent video cards will support it.

Petr Schreiber

#411
Hi Charles,

I like how GLSL is designed. I have experimented with it, but only in thinBASIC:
http://community.thinbasic.com/index.php?topic=1043.msg6926#msg6926

What I like about GLSL is surprisingly understandable syntax, what I dislike seriously is how it is implemented on Radeon HD series. ATI reworked whole OpenGL driver ... and something is terribly wrong. But I am sure it will get better. But X series should be ok. It runs even on Radeon 9600 :)

So range of cards we can play with GLSL on is quite wide ( OpenGL 1.5 as extension, OpenGL 2.0 as part of standard ), but not sure if enough wide to build complete general purpose engine on it. But if you target newer cards then it is really interesting option!

For example per pixel lighting and fog is so much better looking than fixed pipeline per vertex operations I almost had to run in the house crying loud YESSS! FINALLY! ;D when I saw it for first time.


Bye,
Petr

P.S. Good to "validate" the shaders using GLSL Validator from 3D labs

P.P.S. Interesting you can write geometry shaders using GLSL too, on WindowsXP. I think it is nice advantage over geometry shaders in DirectX10 which is binded to Vistas only. Please see here
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge

Thanks  for the info Petr, I see that none of the shader setup functions, now standard in Opengl 2.0, are exposed in the XP Open32.dll (2004). You have to obtain the proc addresses using wglGetProcAddress and it's usually the ARB version of the function.

So the functions have to be called indirectly as CALL DWORD ..

But one advantage over static DLL binding is that the Shaders can be excluded from the scene rendering if the drivers or hardware do not support the Shader language. So plugins can do the basic scene for older systems or an enhanced scene.

Am I right in thinking that DX9 does not provide access to shaders?

Petr Schreiber

#413
Hi Charles,

OpenGL32.DLL contains OpenGL 1.1 only! So of course extra functionality ( even multitexturing ) is dynamic - this is reason why I did tests in thinBASIC - there was no need for CALL DWORD, just once DECLARE SET ADDRESS and forget :) I love this feature.
All OpenGL functionality is provided by driver, because MS implementation is sadly ( intentionally? ) very poor - even depth test is done in very lazy way.

DirectX9 works with shaders for sure, with ShaderModel 3.0 I think. But not in GLSL - it is called HLSL language. But I still think developing in OpenGL is easier - no need to install SDK to get new functionality, just retrieve pointer and go :) But it is up to you.
Also you won't get geometry shaders on XPs with DX. But if you do not plan to use them then probably not such a issue.


Bye,
Petr

P.S. Charles do you know what happened to project Fahrenheit? It was agreement between MS and SGI to create new 3D API, as a crosbreed between DirectX and OpenGL. I think it was announced in 1997, but since then ... just silence :)
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge

Hi Petr, I found an article on the history and demise of the Fahrenheit project. MS scuppered the project by not providing low level support for it, and promoting DX7 instead, which was very bad news for SGI who wanted to migrate all their high-level graphics applications to PCs.

http://en.wikipedia.org/wiki/Fahrenheit_graphics_API

I have got the code for compiling and linking shaders, based on the ClockworkCoders tutorial implemented in PB.
Rather than use the CALL DWORD syntax, I used assembler to see what it was like. (no need to declare prototypes).

This is the tutorial

http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/loading.php

and here is a snippet of assrmber code showing a complicated call and a simple call.


    ' glShaderSourceARB(fragmentShaderObject, 1, &FragmentShaderSource, &flength);
    j=LEN(FragmentShaderSource):i=VARPTR(j)
    ! push eax
    i=VARPTR(FragmentShaderSource)
    ! push eax
    ! push 1
    ! push FragmentShaderObject
    ! call glShaderSource

    ' glCompileShaderARB(VertexShaderObject);
    ! push VertexShaderObject
    ! call glCompileShader



Petr Schreiber

Hi Charles,

could you post complete PB code, this looks very interesting!


Thanks,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge

This is the code Petr. I have added some armour plating to ensure it wont crash the system when any of the required GLSL calls are unsupported. There are some ARB calls and one of the diagnostic calls in the tutorial is not supported in my system  and does not appear in the opengl 2.0 reference in any form.

If there is a GLSL Compiler error, it gets reported in a Message box. Linking is allowed to procede but the shader, as far as I can tell will be safely unimplemented.

I am using landscapeA as a test bed and will post as soon as I can get the shaders to do something useful.

This is how the code is used:


init:
        Static shaderA as long

         BindGLSL
         shaderA=CreateShaders

.....

render_scene:

         IF GLSL THEN
             glcolor4f 1,1,1,1
             glDisable GL_TEXTURE_2D
             ! push shaderA
             ! call glUseProgram
             glbegin GL_QUADS
             glVertex3f -1, 1,-2
             glVertex3f -1,-1,-2
             glVertex3f  1,-1,-2
             glVertex3f  1, 1,-2
             glEnd
             ! push 0
             ! call glUseProgram
         END IF


and this is the GLSL test interface without any additional dependencies


'/* Shaders */
'the leading zeros prevent sign extension. eg: ffff8b30
MACRO GL_FRAGMENT_SHADER                  = &h00008B30
MACRO GL_VERTEX_SHADER                    = &h00008B31
MACRO GL_MAX_VERTEX_ATTRIBS               = &h00008869
MACRO GL_MAX_VERTEX_UNIFORM_VECTORS       = &h00008DFB
MACRO GL_MAX_VARYING_VECTORS              = &h00008DFC
MACRO GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = &h00008B4D
MACRO GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS   = &h00008B4C
MACRO GL_MAX_TEXTURE_IMAGE_UNITS          = &h00008872
MACRO GL_MAX_FRAGMENT_UNIFORM_VECTORS     = &h00008DFD
MACRO GL_SHADER_TYPE                      = &h00008B4F
MACRO GL_DELETE_STATUS                    = &h00008B80
MACRO GL_LINK_STATUS                      = &h00008B82
MACRO GL_VALIDATE_STATUS                  = &h00008B83
MACRO GL_ATTACHED_SHADERS                 = &h00008B85
MACRO GL_ACTIVE_UNIFORMS                  = &h00008B86
MACRO GL_ACTIVE_UNIFORM_MAX_LENGTH        = &h00008B87
MACRO GL_ACTIVE_ATTRIBUTES                = &h00008B89
MACRO GL_ACTIVE_ATTRIBUTE_MAX_LENGTH      = &h00008B8A
MACRO GL_SHADING_LANGUAGE_VERSION         = &h00008B8C
MACRO GL_CURRENT_PROGRAM                  = &h00008B8D
'/* Shader Source */
MACRO GL_COMPILE_STATUS                   = &h00008B81
MACRO GL_INFO_LOG_LENGTH                  = &h00008B84
MACRO GL_SHADER_SOURCE_LENGTH             = &h00008B88
MACRO GL_SHADER_COMPILER                  = &h00008DFA

MACRO check_GLSL ' must keep all line breaks intact
    MACROTEMP nex
    '
    ! cmp eax,0
    ! jnz nex
    ! jmp fail
    nex:
END MACRO

SUB BindGLSL()
    #REGISTER NONE
    GLOBAL GLSL AS LONG
    GLOBAL glCreateShader,glShaderSource,glCompileShader AS LONG 'glGetObjectParameteriv
    GLOBAL glGetShaderiv,glGetInfoLog,glAttachShader,glLinkProgram AS LONG
    GLOBAL glCreateProgram,glGetProgramiv,glUseProgram  AS LONG
    glCreateShader=wglGetProcAddress("glCreateShader"):check_GLSL
    glShaderSource=wglGetProcAddress("glShaderSourceARB"):check_GLSL   ' ARB
    glCompileShader=wglGetProcAddress("glCompileShaderARB"):check_GLSL ' ARB
    glGetInfoLog=wglGetProcAddress("glGetInfoLogARB"):check_GLSL       ' ARB only
    'glGetObjectParameteriv ??
    glGetShaderiv=wglGetProcAddress("glGetShaderiv"):check_GLSL
    glAttachShader=wglGetProcAddress("glAttachShader"):check_GLSL
    glLinkProgram=wglGetProcAddress("glLinkProgram"):check_GLSL
    glCreateProgram=wglGetProcAddress("glCreateProgram"):check_GLSL
    glGetProgramiv=wglGetProcAddress("glGetProgramiv"):check_GLSL
    glUseProgram=wglGetProcAddress("glUseProgram")::check_GLSL
    GLSL=-1
    EXIT SUB
    fail:
    GLSL=0
END SUB

FUNCTION CreateShaders() AS LONG
    ' http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/loading.php
    #REGISTER NONE
    IF GLSL=0 THEN EXIT FUNCTION
    LOCAL e,i,j,k AS LONG
    LOCAL InfoLog AS STRING
    LOCAL VertexShaderSource AS STRING: VertexShaderSource=_
    "void main(void) "+_
    "{ "+_
    "   vec4 a = gl_Vertex; "+_
    "   a.x = a.x * 0.5; "+_
    "   a.y = a.y * 0.5; "+_
    "   gl_Position = gl_ModelViewProjectionMatrix * a; "+_
    "} "
    LOCAL FragmentShaderSource AS STRING: FragmentShaderSource=_
    "void main (void) "+_
    "{ "+_
    "  gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); "+_
    "} "
    LOCAL VertexShaderObject, FragmentShaderObject AS DWORD
    '
    ' vertexShaderObject = glCreateShader(GL_VERTEX_SHADER);
    ! push dword GL_VERTEX_SHADER
    ! call glCreateShader
    ! mov VertexShaderObject,eax
    'fragmentShaderObject = glCreateShader(GL_FRAGMENT_SHADER);
    ! push dword GL_FRAGMENT_SHADER
    ! call glCreateShader
    ! mov FragmentShaderObject,eax
    'glShaderSourceARB(vertexShaderObject, 1, &VertexShaderSource, &vlength);
    j=LEN(VertexShaderSource):i=VARPTR(j)
    ! push eax
    i=VARPTR(VertexShaderSource)
    ! push eax
    ! push 1
    ! push vertexShaderObject
    ! call glShaderSource

    ' glShaderSourceARB(fragmentShaderObject, 1, &FragmentShaderSource, &flength);
    j=LEN(FragmentShaderSource):i=VARPTR(j)
    ! push eax
    i=VARPTR(FragmentShaderSource)
    ! push eax
    ! push 1
    ! push FragmentShaderObject
    ! call glShaderSource

    ' glCompileShaderARB(VertexShaderObject);
    ! push VertexShaderObject
    ! call glCompileShader

    ' glCompileShaderARB(fragmentShaderObject);
    ! push FragmentShaderObject
    ! call glCompileShader

    ' glGetObjectParameteriv(ShaderObject, GL_COMPILE_STATUS, &compiled); OBSOLETE?
    'i=varptr(j)
    '! push eax
    '! push GL_COMPILE_STATUS
    '! push VertexShaderObject
    '! call glGetObjectParameteriv
    ' if (compiled) { /* yes it compiled! */ }

    'glGetShaderiv(ShaderObject, GL_INFO_LOG_LENGTH , &blen);
    i=VARPTR(j)
    ! push eax
    ! push GL_INFO_LOG_LENGTH
    ! push VertexShaderObject
    ! call glGetShaderiv
     IF j>1 THEN
         'glGetInfoLogARB(ShaderObject, blen, &slen, compiler_log);
         InfoLog=NUL$(1024)
         i=STRPTR(InfoLog)
         ! push eax
         i=VARPTR(j)
         ! push eax
         ! push 1024
         ! push VertexShaderObject
         ! call glGetInfoLog
         MSGBOX InfoLog ' compiler errors
         EXIT FUNCTION
     END IF
     
     'Linking:

    'ProgramObject = glCreateProgram();
    ! call glCreateProgram
    ! mov j,eax

    'glAttachShader(ProgramObject, vertexShaderObject);
    ! push VertexShaderObject
    ! push j
    ! call glAttachShader

    ' glAttachShader(ProgramObject, fragmentShaderObject);
    ! push FragmentShaderObject
    ! push j
    ! call glAttachShader

    ' glLinkProgram(ProgramObject);
    ! push j
    ! call glLinkProgram

    ' glGetProgramiv(ProgramObject, GL_LINK_STATUS, &linked);
    i=VARPTR(k)
    ! push eax
    ! push GL_LINK_STATUS
    ! push j
    ! call glGetProgramiv
    'msgbox hex$(k)

    FUNCTION=j
END FUNCTION


Petr Schreiber

Thanks Charles,

highly appreciated!


Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge


An advanced but exciting tutorial showing some of the possibilities unleashed by using shaders:

The art of texturing Using the OpenGL Shading Language
By Jerome Guinot


http://www.ozone3d.net/tutorials/glsl_texturing.php


Petr Schreiber

Hi Charles,

this is very good site, although some shaders from there did not passed GLSL validation ( I think it was per-pixel fog sample ), but generally it is a great resource! The article you posted link to is really fantastic!

Thanks,
Petr

P.S. Maybe better to move GLSL talk to new thread?
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com