Wednesday, March 27, 2013

The best design is the one that you don’t need to explain to the others

 

Yeah, like we need another pretentious debate about some pretentious concept de grandeur.

This one though, someone’s going prove it for good.

The ego of a computer scientist

 

is larger than the ones of all EE, Material, Telecom, Chemical, Structural and Mechanical Engineers combined.

For no bloody reason…

Tuesday, March 12, 2013

[c/c++] use reference variable to set values


    ExpandedVertex& beforeVec = (*m_hVecGlobalVecRef)[i];

    beforeVec.pos.x = temp_hPos[i*4] ;
    beforeVec.pos.y = temp_hPos[i*4+1];
    beforeVec.pos.z = temp_hPos[i*4+2];
    beforeVec.mass = temp_hPos[i*4+3];

    beforeVec.vel.x = temp_hVel[i*4];
    beforeVec.vel.y = temp_hVel[i*4+1];
    beforeVec.vel.z = temp_hVel[i*4+2];
    beforeVec.mass = temp_hVel[i*4+3];

Saturday, March 9, 2013

[opengl] http://www.opengl.org/wiki/Vertex_Buffer_Object#Vertex_Array_Object ?



http://rauwendaal.net/2011/02/10/how-to-use-cuda-3-0s-new-graphics-interoperability-api-with-opengl/



[opengl] glGenBuffers, glBindBuffer, glBufferData

--- Nvidia ParticleSystem particleSystem.cpp ---


uint
ParticleSystem::createVBO(uint size)
{
    GLuint vbo;
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    return vbo;
}

--- glGenBuffers()

http://stackoverflow.com/questions/12102864/assist-me-to-understand-opengl-glgenbuffers

glGenBuffers doesn't work quite like what you expect. When you call glGenBuffers, it doesn't actuallycreate anything. It just returns a list of integers that are not currently used as buffer names.
The actual 'object' is not created until you call glBindBuffer. So you can just make up any integer you like and pass it to glBindBuffer and a valid buffer will be created at that index. glGenBuffers is actually not required at all, it's just there as a convenience function to give you an unused integer.
So if you just create an array of random integers, as long as none of them overlap, you can use that as your list of buffers without calling glGenBuffers. That's why your code works whether you tell glGenBuffers to create 1 or 2 buffers. As long as you have two buffers with two different names, it doesn't matter where the integer came from.
A little demonstration:
int buf;
glGenBuffers(1, &buf);
glIsBuffer(buf); //FALSE - buffer has not been created yet
glBindBuffer(GL_ARRAY_BUFFER, buf);
glIsBuffer(buf); //TRUE - buffer created on bind

http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml

--- glBufferData()

http://stackoverflow.com/a/5402762


What does glBufferData do?
glBufferData does at least two things, and optionally a third. It allocates buffer storage and lays down the usage of the buffer. Optionally, if the pointer argument is non-null, it will fill the buffer with the pointed-to data. The similar glBufferSubData differs insofar as it only updates (possibly a subrange of) data, it does not allocate storage or anything else.

http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml


void glBufferData(GLenum  target,
 GLsizeiptr  size,
 const GLvoid *  data,
 GLenum  usage);

Parameters

target
Specifies the target buffer object. The symbolic constant must be GL_ARRAY_BUFFERGL_ATOMIC_COUNTER_BUFFERGL_COPY_READ_BUFFERGL_COPY_WRITE_BUFFERGL_DRAW_INDIRECT_BUFFER,GL_DISPATCH_INDIRECT_BUFFERGL_ELEMENT_ARRAY_BUFFERGL_PIXEL_PACK_BUFFERGL_PIXEL_UNPACK_BUFFERGL_SHADER_STORAGE_BUFFERGL_TEXTURE_BUFFERGL_TRANSFORM_FEEDBACK_BUFFER, or GL_UNIFORM_BUFFER.
size
Specifies the size in bytes of the buffer object's new data store.
data
Specifies a pointer to data that will be copied into the data store for initialization, or NULL if no data is to be copied.
usage
Specifies the expected usage pattern of the data store. The symbolic constant must be GL_STREAM_DRAWGL_STREAM_READGL_STREAM_COPYGL_STATIC_DRAWGL_STATIC_READGL_STATIC_COPY,GL_DYNAMIC_DRAWGL_DYNAMIC_READ, or GL_DYNAMIC_COPY.

Description

glBufferData creates a new data store for the buffer object currently bound to target. Any pre-existing data store is deleted. The new data store is created with the specified size in bytes and usage. If data is not NULL, the data store is initialized with data from this pointer. In its initial state, the new data store is not mapped, it has a NULL mapped pointer, and its mapped access is GL_READ_WRITE.
usage is a hint to the GL implementation as to how a buffer object's data store will be accessed. This enables the GL implementation to make more intelligent decisions that may significantly impact buffer object performance. It does not, however, constrain the actual usage of the data store. 



--- glBindBuffer()

http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml


void glBindBuffer(GLenum  target,
 GLuint  buffer);


.... Buffer object names are unsigned integers. The value zero is reserved, ..., buffer set to zero effectively unbinds any buffer object previously bound, and restores client memory usage for that buffer object target (if supported for that target)...

Thursday, March 7, 2013

What’s db normalization?

 

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

Database normalization is the process of organizing the fields and tables of a relational database to minimize redundancy and dependency. Normalization usually involves dividing large tables into smaller (and less redundant) tables and defining relationships between them. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships.

1NF
First normal form
Two versions: E.F. Codd (1970), C.J. Date (2003)
1970 [1] and 2003 [9]
Table faithfully represents a relation, primarily meaning it has at least one candidate key

2NF
Second normal form
E.F. Codd
1971 [2]
No non-prime attribute in the table is functionally dependent on a proper subset of any candidate key

3NF
Third normal form
Two versions: E.F. Codd (1971), C. Zaniolo (1982)
1971 [2] and 1982 [10]
Every non-prime attribute is non-transitively dependent on every candidate key in the table. The attributes that do not contribute to the description of the primary key are removed from the table. In other words, no transitive dependency is allowed.

Wednesday, March 6, 2013

Ways to create threads?

 

Defining Thread.run()

public class MyThread extends Thread {
  public void run(){
     System.out.println("MyThread running");
  }
}

MyThread myThread = new MyThread();
myTread.start();

 

Defining Runnable

Runnable myRunnable = new Runnable(){

  public void run(){
     System.out.println("Runnable running");
  }
}

Thread thread = new Thread(myRunnable);
thread.start();

http://tutorials.jenkov.com/java-concurrency/creating-and-starting-threads.html